Created
June 13, 2018 19:50
-
-
Save glegoux/191b9756bd85b99ec969560ecde1d0fd to your computer and use it in GitHub Desktop.
[Python] Get screen physical size
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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