diff options
| author | jwansek <eddie.atten.ea29@gmail.com> | 2026-01-03 17:43:06 +0000 |
|---|---|---|
| committer | jwansek <eddie.atten.ea29@gmail.com> | 2026-01-03 17:43:06 +0000 |
| commit | c459f51bb75e92a45adf828eb95a181a04fd35cb (patch) | |
| tree | fead24a0973966b4bf2256a7aec83cf050d7e2cf | |
| parent | 0018b77b200d55b57c045a036c45b65355597b4b (diff) | |
| download | UPSMartMonitor-c459f51bb75e92a45adf828eb95a181a04fd35cb.tar.gz UPSMartMonitor-c459f51bb75e92a45adf828eb95a181a04fd35cb.zip | |
Initial commit
| -rw-r--r-- | requirements.txt | 2 | ||||
| -rw-r--r-- | upsmartmonitor.py | 48 |
2 files changed, 50 insertions, 0 deletions
diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..7efe2a9 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +pyautogui +pygetwindow
\ No newline at end of file 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 |
