-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgui.py
216 lines (147 loc) · 7.67 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
from PyQt5.QtWidgets import QMainWindow, QHBoxLayout, QVBoxLayout, QWidget
from PyQt5.QtCore import QTimer
from ui.grid import CameraGrid
from ui.control import ControlBar
from ui.status import StatusBar
from ui.stopwatch import Stopwatch, StopwatchControlBar
from ui.capture import CaptureControlBar
from ui.console import ConsoleModule
from ui.info import ThrusterDisplayModule, AxisDisplayModule
from ui.automation_control import AutomationControlBar
from ui.select import SelectionWidget
import logging
class MainWindow(QMainWindow):
def __init__(self, front_port, down_port):
super().__init__()
self.setWindowTitle('Crimson UI')
self.setStyleSheet("""
QMainWindow {
background: rgb(21, 21, 21)
}
""")
self.control = ControlBar(self)
self.status = StatusBar()
self.stopwatch = Stopwatch()
self.stopwatch_control = StopwatchControlBar(self)
self.capture_control = CaptureControlBar(self)
self.grid = CameraGrid(self, front_port, down_port)
self.console = ConsoleModule(self)
self.console.hide()
self.thruster_display = ThrusterDisplayModule()
self.thruster_display.hide()
self.axis_display = AxisDisplayModule()
self.axis_display.hide()
self.automation_window = AutomationWindow(self)
self.control_frame = QWidget()
self.control_frame.layout = QVBoxLayout()
self.control_frame.layout.addStretch(1)
self.control_frame.layout.addWidget(self.control)
self.control_frame.layout.setContentsMargins(0,0,0,0)
self.control_frame.setLayout(self.control_frame.layout)
self.thruster_display_frame = QWidget()
self.thruster_display_frame.layout = QVBoxLayout()
self.thruster_display_frame.layout.addStretch(1)
self.thruster_display_frame.layout.addWidget(self.thruster_display)
self.thruster_display_frame.layout.setContentsMargins(0,0,0,0)
self.thruster_display_frame.setLayout(self.thruster_display_frame.layout)
self.axis_display_frame = QWidget()
self.axis_display_frame.layout = QVBoxLayout()
self.axis_display_frame.layout.addStretch(1)
self.axis_display_frame.layout.addWidget(self.axis_display)
self.axis_display_frame.layout.setContentsMargins(0,0,0,0)
self.axis_display_frame.setLayout(self.axis_display_frame.layout)
self.status_frame = QWidget()
self.status_frame.layout = QVBoxLayout()
self.status_frame.layout.addStretch(1)
self.status_frame.layout.addWidget(self.status)
self.status_frame.layout.setContentsMargins(0,0,0,0)
self.status_frame.setLayout(self.status_frame.layout)
self.stopwatch_frame = QWidget()
self.stopwatch_frame.layout = QHBoxLayout()
self.stopwatch_frame.layout.setSpacing(20)
self.stopwatch_frame.layout.addWidget(self.stopwatch)
self.stopwatch_frame.layout.addStretch(1)
self.stopwatch_frame.layout.addWidget(self.capture_control)
self.stopwatch_frame.layout.addWidget(self.stopwatch_control)
self.stopwatch_frame.layout.setContentsMargins(0,0,0,0)
self.stopwatch_frame.setLayout(self.stopwatch_frame.layout)
self.lower_frame = QWidget()
self.lower_frame.setFixedHeight(208)
self.lower_frame.layout = QHBoxLayout()
self.lower_frame.layout.setSpacing(20)
self.lower_frame.layout.addWidget(self.control_frame)
self.lower_frame.layout.addWidget(self.console)
self.lower_frame.layout.addWidget(self.thruster_display_frame)
self.lower_frame.layout.addStretch(1)
self.lower_frame.layout.addWidget(self.axis_display_frame)
self.lower_frame.layout.addWidget(self.status_frame)
self.lower_frame.layout.setContentsMargins(0,0,0,0)
self.lower_frame.setLayout(self.lower_frame.layout)
self.frame = QWidget()
self.frame.layout = QVBoxLayout()
self.frame.layout.addWidget(self.stopwatch_frame)
self.frame.layout.addWidget(self.grid, 100)
self.frame.layout.addWidget(self.lower_frame)
self.frame.layout.setContentsMargins(0,0,0,0)
self.frame.setLayout(self.frame.layout)
self.setCentralWidget(self.frame)
self.status_thread = QTimer()
self.status_thread.timeout.connect(self.status_listener)
self.status_thread.start(10)
def status_listener(self):
if self.grid.front_cam.connected:
self.status.front_cam_status.set_connected()
else:
self.status.front_cam_status.set_disconnected()
if self.grid.down_cam.connected:
self.status.down_cam_status.set_connected()
else:
self.status.down_cam_status.set_disconnected()
def update_thruster_values(self, values_dict):
self.thruster_display.front_left_thruster_label.update_value(round(values_dict[0]*100, 1))
self.thruster_display.front_right_thruster_label.update_value(round(values_dict[1]*100, 1))
self.thruster_display.back_left_thruster_label.update_value(round(values_dict[2]*100, 1))
self.thruster_display.back_right_thruster_label.update_value(round(values_dict[3]*100, 1))
self.thruster_display.left_thruster_label.update_value(round(values_dict[4]*100, 1))
self.thruster_display.right_thruster_label.update_value(round(values_dict[5]*100, 1))
def update_axis_values(self, values_dict):
self.axis_display.roll_label.update_value(round(values_dict[0]*100, 1))
self.axis_display.pitch_label.update_value(round(values_dict[1]*100, 1))
self.axis_display.yaw_label.update_value(round(values_dict[2]*100, 1))
def keyPressEvent(self, event):
if self.console.command_line.key_press_logging and event.text().isprintable() and len(event.text()) == 1:
logging.debug(f'Press: {event.text()} ({ord(event.text())})')
def keyReleaseEvent(self, event):
if self.console.command_line.key_release_logging and event.text().isprintable() and len(event.text()) == 1:
logging.debug(f'Release: {event.text()} ({ord(event.text())})')
class AutomationWindow(QWidget):
def __init__(self, parent):
super().__init__()
self.setWindowTitle('Crimson UI (Automation)')
self.setStyleSheet("""
QWidget {
background: rgb(21, 21, 21)
}
""")
self.parent = parent
self.automation_control = AutomationControlBar(self)
self.selection = SelectionWidget()
self.automation_control_frame = QWidget()
self.automation_control_frame.layout = QVBoxLayout()
self.automation_control_frame.layout.addStretch(1)
self.automation_control_frame.layout.addWidget(self.automation_control)
self.automation_control_frame.layout.setContentsMargins(0,0,0,0)
self.automation_control_frame.setLayout(self.automation_control_frame.layout)
self.layout = QHBoxLayout()
self.layout.addWidget(self.automation_control_frame)
self.layout.addWidget(self.selection, 100)
# self.automation_control_frame.setLayout(self.automation_control_frame.layout)
# self.preview_frame = QWidget()
# self.preview_frame.layout = QVBoxLayout()
# self.preview_frame.layout.addWidget(self.preview_widget)
self.layout.setContentsMargins(0,0,0,0)
self.setLayout(self.layout)
# self.setCentralWidget(self.automation_control_frame)
def closeEvent(self, event):
self.parent.control.automation_button.setDisabled(False)
event.accept()