|
@@ -14,14 +14,34 @@ from PIL import Image
|
14
|
14
|
#icon_path = "/usr/share/icons/breeze-dark/status/32/input-keyboard-brightness.svg"
|
15
|
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
|
30
|
def get_value():
|
22
|
|
- #print("check2")
|
|
31
|
+ #print("check 3")
|
23
|
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
|
45
|
def quit(icon):
|
26
|
46
|
print("stop brightness")
|
27
|
47
|
brightness.running = False
|
|
@@ -30,10 +50,35 @@ def quit(icon):
|
30
|
50
|
icon.stop()
|
31
|
51
|
|
32
|
52
|
def poll(icon):
|
|
53
|
+ global prev_pause, prev_active, prev_last, prev_disp
|
|
54
|
+
|
33
|
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
|
67
|
#print("update")
|
35
|
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
|
83
|
def main():
|
39
|
84
|
out = BytesIO()
|
|
@@ -48,18 +93,27 @@ def main():
|
48
|
93
|
icon = pystray.Icon("AutoBrightness", image, "AutoBrightness",
|
49
|
94
|
menu=pystray.Menu(
|
50
|
95
|
pystray.MenuItem(
|
51
|
|
- 'Activated',
|
|
96
|
+ lambda icon=pystray.Icon: get_value(),
|
52
|
97
|
None,
|
53
|
98
|
enabled=False,
|
54
|
|
- checked=lambda icon=pystray.Icon: is_running(),
|
55
|
99
|
),
|
56
|
|
-
|
57
|
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
|
108
|
None,
|
60
|
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
|
117
|
pystray.MenuItem(
|
64
|
118
|
"Quit",
|
65
|
119
|
lambda icon=pystray.Icon: quit(icon),
|