Browse Source

show individual display values and reduce update issues

Thomas B 1 week ago
parent
commit
81134a88ba
2 changed files with 69 additions and 12 deletions
  1. 5
    2
      client/brightness.py
  2. 64
    10
      client/tray.py

+ 5
- 2
client/brightness.py View File

24
 
24
 
25
 running = True
25
 running = True
26
 is_active = True
26
 is_active = True
27
+is_unpaused = True
27
 last_brightness = 0
28
 last_brightness = 0
29
+disps = None
28
 
30
 
29
 def cal(v, c):
31
 def cal(v, c):
30
     # out = out_b + out_a * in_a * max(0, in_b + in)
32
     # out = out_b + out_a * in_a * max(0, in_b + in)
42
     return min(max(val, 0), 100)
44
     return min(max(val, 0), 100)
43
 
45
 
44
 def main():
46
 def main():
45
-    global running, is_active, last_brightness
47
+    global running, is_active, is_unpaused, last_brightness, disps
46
 
48
 
47
     print("usb init")
49
     print("usb init")
48
     usb = lux.usb_init()
50
     usb = lux.usb_init()
79
     time_window = time.time()
81
     time_window = time.time()
80
 
82
 
81
     is_active = True
83
     is_active = True
84
+    is_unpaused = True
82
 
85
 
83
     while running:
86
     while running:
84
         # read brightness at approx. 1Hz with low-pass filtering
87
         # read brightness at approx. 1Hz with low-pass filtering
129
             is_active = not info["fullscreen"]
132
             is_active = not info["fullscreen"]
130
 
133
 
131
         # set displays at most every 10s
134
         # set displays at most every 10s
132
-        if is_active and ((time.time() - time_displays) > 10.0):
135
+        if is_active and is_unpaused and ((time.time() - time_displays) > 10.0):
133
             time_displays = time.time()
136
             time_displays = time.time()
134
 
137
 
135
             for d in disps:
138
             for d in disps:

+ 64
- 10
client/tray.py View File

14
 #icon_path = "/usr/share/icons/breeze-dark/status/32/input-keyboard-brightness.svg"
14
 #icon_path = "/usr/share/icons/breeze-dark/status/32/input-keyboard-brightness.svg"
15
 icon_path = "/usr/share/icons/breeze-dark/actions/24/brightness-high.svg"
15
 icon_path = "/usr/share/icons/breeze-dark/actions/24/brightness-high.svg"
16
 
16
 
17
-def is_running():
18
-    #print("check1")
19
-    return "Active" if brightness.is_active else "Inactive"
17
+prev_pause = None
18
+prev_active = None
19
+prev_last = None
20
+prev_disp = None
21
+
22
+def is_running_name():
23
+    #print("check 1")
24
+    return "Running" if (brightness.is_active and brightness.is_unpaused) else "Stopped"
25
+
26
+def is_running_checked():
27
+    #print("check 2")
28
+    return True if (brightness.is_active and brightness.is_unpaused) else False
20
 
29
 
21
 def get_value():
30
 def get_value():
22
-    #print("check2")
31
+    #print("check 3")
23
     return f"Brightness: {brightness.last_brightness}"
32
     return f"Brightness: {brightness.last_brightness}"
24
 
33
 
34
+def is_paused_checked():
35
+    #print("check 4")
36
+    return False if brightness.is_unpaused else True
37
+
38
+def is_paused_name():
39
+    #print("check 5")
40
+    return "Unpaused" if brightness.is_unpaused else "Paused"
41
+
42
+def toggle_pause():
43
+    brightness.is_unpaused = False if brightness.is_unpaused else True
44
+
25
 def quit(icon):
45
 def quit(icon):
26
     print("stop brightness")
46
     print("stop brightness")
27
     brightness.running = False
47
     brightness.running = False
30
     icon.stop()
50
     icon.stop()
31
 
51
 
32
 def poll(icon):
52
 def poll(icon):
53
+    global prev_pause, prev_active, prev_last, prev_disp
54
+
33
     while brightness.running:
55
     while brightness.running:
56
+        time.sleep(1.0)
57
+
58
+        if (prev_pause == brightness.is_unpaused) and (prev_active == brightness.is_active) and (prev_last == brightness.last_brightness) and (prev_disp == brightness.disps):
59
+            #print("skip")
60
+            continue
61
+
62
+        prev_pause = brightness.is_unpaused
63
+        prev_active = brightness.is_active
64
+        prev_last = brightness.last_brightness
65
+        prev_disp = brightness.disps
66
+
34
         #print("update")
67
         #print("update")
35
         icon.update_menu()
68
         icon.update_menu()
36
-        time.sleep(5.0)
69
+
70
+def display_menu():
71
+    #print("menu")
72
+    if (brightness.disps == None) or (len(brightness.disps) <= 0):
73
+        return (pystray.MenuItem("No displays", None, enabled=False), )
74
+
75
+    display_entries = []
76
+    for d in brightness.disps:
77
+        #s = "{} ({}) @ {}".format(d["name"], d["_id"], d["prev"])
78
+        s = f"{d['prev']} @ {d['name']}"
79
+        display_entries.append(pystray.MenuItem(s, None, enabled=False))
80
+
81
+    return display_entries
37
 
82
 
38
 def main():
83
 def main():
39
     out = BytesIO()
84
     out = BytesIO()
48
     icon = pystray.Icon("AutoBrightness", image, "AutoBrightness",
93
     icon = pystray.Icon("AutoBrightness", image, "AutoBrightness",
49
         menu=pystray.Menu(
94
         menu=pystray.Menu(
50
             pystray.MenuItem(
95
             pystray.MenuItem(
51
-                'Activated',
96
+                lambda icon=pystray.Icon: get_value(),
52
                 None,
97
                 None,
53
                 enabled=False,
98
                 enabled=False,
54
-                checked=lambda icon=pystray.Icon: is_running(),
55
             ),
99
             ),
56
-
57
             pystray.MenuItem(
100
             pystray.MenuItem(
58
-                lambda icon=pystray.Icon: get_value(),
101
+                "Displays",
102
+                pystray.Menu(
103
+                    lambda icon=pystray.Icon: display_menu(),
104
+                )
105
+            ),
106
+            pystray.MenuItem(
107
+                lambda icon=pystray.Icon: is_running_name(),
59
                 None,
108
                 None,
60
                 enabled=False,
109
                 enabled=False,
110
+                checked=lambda icon=pystray.Icon: is_running_checked(),
111
+            ),
112
+            pystray.MenuItem(
113
+                lambda icon=pystray.Icon: is_paused_name(),
114
+                lambda icon=pystray.Icon: toggle_pause(),
115
+                checked=lambda icon=pystray.Icon: is_paused_checked(),
61
             ),
116
             ),
62
-
63
             pystray.MenuItem(
117
             pystray.MenuItem(
64
                 "Quit",
118
                 "Quit",
65
                 lambda icon=pystray.Icon: quit(icon),
119
                 lambda icon=pystray.Icon: quit(icon),

Loading…
Cancel
Save