-
Notifications
You must be signed in to change notification settings - Fork 0
/
panel.py
executable file
·72 lines (58 loc) · 1.9 KB
/
panel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python3
# A script that will start and manage the processes
# that feed the bar-aint-recursive panel maker (./panel_parser)
import subprocess
from queue import Queue
from threading import Thread
from time import sleep
from panel_workers import clock, parser, battery, fifo_listener
from panel_workers import inbox_watcher, one_shot_applets
apps = {'keyboard': 'kbdlayout get',
'bspwm_status': 'bspc control --subscribe',
'win_title': 'xtitle -sf T%s'
}
enabled_apps = ['bspwm_status',
'win_title'
]
enabled_modules = [battery.main,
clock.main,
parser.main,
inbox_watcher.main,
one_shot_applets.main,
fifo_listener.main
]
active_apps, active_modules = [], []
def enqueue_stdout(out, queue):
while True:
try:
data = out.readline()
if not data:
sleep(0.1)
else:
data = data.strip()
queue.put(data)
except UnicodeDecodeError:
print('Found error when decoding string:', repr(data))
def main():
fifo = Queue()
for module in enabled_modules:
thread = Thread(target=module, args=(fifo,), name=module)
thread.start()
active_modules.append(thread)
for app in enabled_apps:
app = subprocess.Popen(apps[app].split(),
shell=False,
stdin=None,
universal_newlines=True,
stdout=subprocess.PIPE)
thread = Thread(target=enqueue_stdout, args=(app.stdout, fifo))
thread.start()
active_apps.append(thread)
def die(*args):
for app in active_apps:
app.kill()
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
die()