-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui.py
79 lines (62 loc) · 2.01 KB
/
gui.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
# vim: set tabstop=3 noexpandtab shiftwidth=3 softtabstop=3 autoindent:
from PyQt6.QtCore import Qt, QSize
from PyQt6.QtGui import QPainter, QPalette, QFont
from PyQt6.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QLabel, QSizePolicy, QTextEdit
class GUI():
def __init__(self):
self.w = QWidget()
self.w.resize(600, 600)
self.w.move(300, 300)
self.sim_connected = Light()
self.device_connected = Light()
sim_label = QLabel('Connected to sim')
device_label = QLabel('Connected to AP')
sim_status = QHBoxLayout()
sim_status.addWidget(self.sim_connected)
sim_status.addWidget(sim_label)
sim_status.addStretch()
device_status = QHBoxLayout()
device_status.addWidget(self.device_connected)
device_status.addWidget(device_label)
device_status.addStretch()
palette = QPalette()
palette.setColor(QPalette.ColorRole.Base, Qt.GlobalColor.black)
palette.setColor(QPalette.ColorRole.Text, Qt.GlobalColor.white)
self.console = QTextEdit()
self.console.setFontFamily('Courier')
self.console.setPalette(palette)
self.console.setReadOnly(True)
self.console.setAutoFillBackground(True)
vbox = QVBoxLayout()
vbox.addLayout(sim_status)
vbox.addLayout(device_status)
vbox.addWidget(self.console)
self.w.setLayout(vbox)
self.w.setWindowTitle('AutoPilot')
self.w.show()
def set_sim_connected(self, state):
self.sim_connected.set_state(state)
def set_device_connected(self, state):
self.device_connected.set_state(state)
def console_line(self, line):
self.console.append(line)
class Light(QWidget):
def __init__(self):
super().__init__()
self.setFixedSize(30, 30)
self.set_state(False)
def set_state(self, state):
if state:
self.colour = Qt.GlobalColor.green
else:
self.colour = Qt.GlobalColor.red
self.update()
def paintEvent(self, event):
width = 30
height = 30
painter = QPainter()
painter.begin(self)
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
painter.setBrush(self.colour)
painter.drawEllipse(0, 0, width, height)
painter.end()