aboutsummaryrefslogtreecommitdiffstats
path: root/upsmartmonitor.py
diff options
context:
space:
mode:
authorjwansek <eddie.atten.ea29@gmail.com>2026-01-03 17:43:06 +0000
committerjwansek <eddie.atten.ea29@gmail.com>2026-01-03 17:43:06 +0000
commitc459f51bb75e92a45adf828eb95a181a04fd35cb (patch)
treefead24a0973966b4bf2256a7aec83cf050d7e2cf /upsmartmonitor.py
parent0018b77b200d55b57c045a036c45b65355597b4b (diff)
downloadUPSMartMonitor-c459f51bb75e92a45adf828eb95a181a04fd35cb.tar.gz
UPSMartMonitor-c459f51bb75e92a45adf828eb95a181a04fd35cb.zip
Initial commit
Diffstat (limited to 'upsmartmonitor.py')
-rw-r--r--upsmartmonitor.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/upsmartmonitor.py b/upsmartmonitor.py
new file mode 100644
index 0000000..a23bacb
--- /dev/null
+++ b/upsmartmonitor.py
@@ -0,0 +1,48 @@
+import subprocess
+import tempfile
+import pyautogui
+import cv2
+import os
+
+def get_window_geometries():
+ return [
+ s.split()[:6] + [" ".join(s.split()[7:])]
+ for s in subprocess.run(["wmctrl", "-l", "-G"], stdout = subprocess.PIPE).stdout.decode().split("\n")[:-1]
+ ]
+
+def find_upsmart_geometry():
+ for g in get_window_geometries():
+ if g[-1] == "UPSmart":
+ return g
+ raise Exception("Couldn't find UPSMart application")
+
+def focus_upsmart():
+ # it would be much nicer to use an API such as wmctrl to focus the application...
+ # but it doesn't seem to work with UPSmart specifically, perhaps because you need
+ # to start it as root
+ geom = find_upsmart_geometry()
+
+ pyautogui.moveTo(int(geom[2]), int(geom[3]), duration = 0.5)
+ pyautogui.click()
+
+def main():
+ focus_upsmart()
+
+ with tempfile.TemporaryDirectory() as td:
+ fp = os.path.join(td, "upsmart.jpg")
+ subprocess.run(["gnome-screenshot", "--file=%s" % fp, "-w"])
+
+ im = cv2.imread(fp)
+ # im = cv2.cvtColor(im, cv2.COLOR_RGB2BGR)
+ print(fp)
+
+ cv2.imshow("im", im)
+ cv2.waitKey(0)
+
+ # plt.imshow(img, cmap = 'gray', interpolation = 'bicubic')
+ # plt.xticks([]), plt.yticks([]) # to hide tick values on X and Y axis
+ # plt.show()
+
+
+if __name__ == "__main__":
+ main() \ No newline at end of file