-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdzen_panel.py
executable file
·102 lines (89 loc) · 2.64 KB
/
dzen_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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#! /usr/bin/env python
import threading
import time
import sys
import string
import os
status_cmd = 'herbstclient tag_status'
idle_cmd = 'herbstclient --idle'
def parse_tags(output):
#Takes herbstclient tag_status and parses it
#returns a nested list of tags.
tags = output.split()
taglist = ''
for i in range(len(tags)):
if tags[i][0] == '#':
taglist += '^bg(' + colors[11] + ') ' + tags[i][1:] + ' '
elif tags[i][0] == ':':
taglist += '^bg(' + colors[17] + ') ' + tags[i][1:] + ' '
elif tags[i][0] == '.' or '!':
taglist += '^bg(' + colors[1] + ') ' + tags[i][1:] + ' '
return taglist
def parse_xres():
os.chdir('/home/damian/')
fin = open('.Xresources')
colors = []
for line in fin:
color = line.strip()
if 'color' in color:
rgb = color[color.find('#'):]
colors.append(rgb)
elif 'background' in color:
colors.append(color[color.find('#'):])
elif 'foreground' in color:
colors.append(color[color.find('#'):])
return(colors)
def print_colors(colors):
res = ''
for i in range(len(colors)):
res +='^bg(' + colors[i] + ')' + str(i)
return res
def get_date():
return time.strftime('%a %d %b %Y %R')
def get_battery():
try:
fin = open('/sys/class/power_supply/BAT1/uevent')
full = 0
now = 0
for line in fin.readlines():
if line[13:25] == 'CHARGE_FULL=':
full = int(line[25:])
elif line[13:23] == 'CHARGE_NOW':
now = int(line[24:])
res = str(now / full * 100) + '%'
return res
except:
return 'No'
def get_event():
#rename, clean up
proc = os.popen(status_cmd)
output = proc.readline()
taglist = parse_tags(output)
print taglist + '^bg(' + colors[1] + ') ' + get_date() + ' ' + '^bg(' + colors[1] + ')Bat: ' + get_battery() #, print_colors(colors)
sys.stdout.flush()
proc.close()
def event_thread():
get_event()
while True:
line = idlein.readline()
if 'tag' in line:
get_event()
elif 'reload' in line:
idlein.close()
os._exit(0) #Extremely hacky, the interpreter doesn't free up res's
def timer_thread():
while True:
get_event()
time.sleep(1)
return o
def main_thread():
"""docstring for main_thread"""
t1 = threading.Thread(target=event_thread)
t2 = threading.Thread(target=timer_thread)
t1.start()
t2.start()
colors = parse_xres()
single_line_out = ''
idlein = os.popen(idle_cmd)
if __name__ == '__main__':
main_thread()