Skip to content

Instantly share code, notes, and snippets.

@glegoux
Created June 13, 2018 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glegoux/191b9756bd85b99ec969560ecde1d0fd to your computer and use it in GitHub Desktop.
Save glegoux/191b9756bd85b99ec969560ecde1d0fd to your computer and use it in GitHub Desktop.
[Python] Get screen physical size
#!/usr/bin/env python3
import subprocess
r = 1
screens = [l.split() for l in
subprocess.check_output(["xrandr"]).decode("utf-8").strip().splitlines()
if " connected" in l]
scr_data = []
for s in screens:
try:
scr_data.append((
s[0],
float(s[-3].replace("mm", "")),
float(s[-1].replace("mm", ""))
))
except ValueError:
pass
print(("\t").join(["Screen", "width", "height", "diagonal\n"+32*"-"]))
for s in scr_data:
scr = s[0]; w = s[1]/25.4; h = s[2]/25.4; d = ((w**2)+(h**2))**(0.5)
print(("\t").join([scr]+[str(round(n, 1)) for n in [w, h, d]]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment