-
Notifications
You must be signed in to change notification settings - Fork 0
/
bar.py
100 lines (76 loc) · 2.71 KB
/
bar.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
import PyQt5.QtWidgets as qtw
import PyQt5.QtGui as qtg
import PyQt5.QtCore as qtc
import threading
import socket
import time
from awm import config
update_workspace_label = None
update_date_label = None
class MainWindow(qtw.QWidget):
def __init__(self):
super().__init__()
global update_workspace_label
global update_date_label
self.setWindowTitle("AWM - bar")
self.setStyleSheet("background-color: black;")
self.setLayout(qtw.QHBoxLayout())
self.workspace_label = self.create_label(qtc.Qt.AlignLeft)
self.date_label = self.create_label(qtc.Qt.AlignRight)
self.update_workspace_label(1)
update_workspace_label = self.update_workspace_label
update_date_label = self.update_date_label
screen_width = qtw.QDesktopWidget().screenGeometry(-1).width()
self.setFixedWidth(screen_width)
self.setFixedHeight(config.BAR_HEIGHT)
self.show()
def create_label(self, alignment):
label = qtw.QLabel("loading")
label.setAttribute(qtc.Qt.WA_TranslucentBackground, True)
label_gce = qtw.QGraphicsColorizeEffect()
label_gce.setColor(qtc.Qt.white)
label.setGraphicsEffect(label_gce)
label.setAlignment(alignment | qtc.Qt.AlignVCenter)
label.setFont(qtg.QFont('Ubuntu Mono', config.BAR_FONT_SIZE))
self.layout().addWidget(label)
return label
def update_workspace_label(self, workspace_id):
workspace_amt = len(config.workspace_keys)
text = " ".join(map(lambda x: f"{x}" if x != workspace_id else f"[{x}]", range(
1, workspace_amt + 1)))
self.workspace_label.setText(text)
def update_date_label(self):
text = time.strftime("%H:%M")
self.date_label.setText(text)
def wait_for_wm_data():
host = socket.gethostname()
port = 8080
s = socket.socket()
s.bind((host, port))
while True:
s.listen(1)
c, addr = s.accept()
print("Connection from: " + str(addr))
data = c.recv(1024).decode('utf-8')
if not data:
break
print('From wm: ' + data)
try:
new_workspace = int(data)
update_workspace_label(new_workspace)
except ValueError:
print('Workspace ID received from wm was invalid.')
c.close()
def date_updator():
time.sleep(1)
while True:
update_date_label()
time.sleep(60)
if __name__ == "__main__":
vm_listener_thread = threading.Thread(target=wait_for_wm_data)
vm_listener_thread.start()
date_updator_thread = threading.Thread(target=date_updator)
date_updator_thread.start()
app = qtw.QApplication([])
mw = MainWindow()
app.exec_()