-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
2355 lines (1685 loc) · 65.8 KB
/
main.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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#########################
######## IMPORTS ########
#########################
try:
# PYQT5 MODULES
from PyQt5 import uic
from PyQt5.QtCore import (pyqtSignal, QObject, pyqtSlot, QThread, QTimer, QSize, Qt,
QPropertyAnimation, QPoint, QEasingCurve, QTimeLine)
from PyQt5.QtWidgets import (QSplashScreen, QProgressBar, QScrollArea, QGroupBox,
QHBoxLayout, QFrame, QWidget, QStyleFactory, QMainWindow,
QApplication, QComboBox, QRadioButton, QVBoxLayout, QFormLayout,
QGridLayout, QVBoxLayout, QLabel, QSlider, QLineEdit,
QPushButton, QCheckBox, QSizePolicy, QDesktopWidget,
QFileDialog, QGraphicsDropShadowEffect, QShortcut)
from PyQt5.QtGui import (QPixmap, QImage, QResizeEvent, QKeyEvent, QKeySequence,
QIcon, QFont, QColor, QPalette, QPainter)
# ADDITIONAL MODULES
import sys, os
import threading
#from threading import Thread, Timer
from datetime import datetime
from cv2 import (VideoCapture, resize, cvtColor, COLOR_BGR2RGB, CAP_PROP_FRAME_WIDTH,
CAP_PROP_FRAME_HEIGHT, CAP_DSHOW, CAP_FFMPEG)
from xml.etree.ElementTree import parse, Element, SubElement, ElementTree
from subprocess import call, Popen
from webbrowser import open
from pygame import init
from pygame.joystick import quit, Joystick, get_count
from pygame.event import Event, get
import serial
from math import ceil
import time
import subprocess
except:
sys.exit("\n###################################################################################################"
"\nSome libraries are missing! Run the 'install_libraries.bat' file to install the required libraries."
"\n###################################################################################################")
from libraries.animation.slideAnimation import SLIDE_ANIMATION
from libraries.camera.cameraCapture import CAMERA_CAPTURE
from libraries.computer_vision.mosaicTask.mosaicPopupWindow import \
MOSAIC_POPUP_WINDOW
from libraries.computer_vision.transectLineTask.transectLineAlgorithm_v1 import \
TRANSECT_LINE_TASK
from libraries.computer_vision.transectLineTask.transectLinePopupWindow import \
TRANSECT_LINE_POPUP_WINDOW
# CUSTOM LIBRARIES
from libraries.configuration_file.configurationFile import (READ_CONFIG_FILE,
WRITE_CONFIG_FILE)
from libraries.controller.xboxController import CONTROLLER
from libraries.gui.actuators import ACTUATORS
from libraries.gui.analogCameras import ANALOG_CAMERAS
from libraries.gui.controllerDisplay import CONTROLLER_DISPLAY
from libraries.gui.digitalCameras import DIGITAL_CAMERAS
from libraries.gui.keybindings import KEYBINDINGS
from libraries.gui.profileSelector import PROFILE_SELECTOR
from libraries.gui.sensors import SENSORS
from libraries.gui.thrusters import THRUSTERS
from libraries.gui.timerWidget import TIMER
from libraries.serial.rovComms import ROV_SERIAL
from libraries.visual.visualEffects import STYLE
def getResourcePath(relativePath):
"""
Get absolute path to resource, works for dev and for PyInstaller
"""
try:
# PYINSTALLER CREATES A TEMP FOLDER AND STORES PATH IN _MEIPASS
basePath = sys._MEIPASS
except Exception:
basePath = os.path.abspath(".")
return os.path.join(basePath, relativePath)
class UI(QMainWindow):
"""
PURPOSE
Contains functions to initiate the GUI, link the widgets and connect
all the signals/slots from external libraries together.
"""
# DATABASE
fileName = ""
cameraFeeds = []
cameraThreadList = []
visionTaskStatus = [False] * 4
# INITIAL SETUP
def __init__(self, app):
"""
PURPOSE
Class constructor.
Loads GUI, call functions to initiate all the libraries and connects the signal/slots together.
INPUT
- app = QApplication object (required to allow theme changing).
RETURNS
NONE
"""
super(UI, self).__init__()
# LOAD UI FILE
uiFile = getResourcePath("gui.ui")
uic.loadUi(uiFile, self)
# APPLICATION OBJECT TO ALLOW THEME CHANGING
self.app = app
# INITIATE ALL OBJECTS AND LIBRARIES
self.initiateObjects()
# CONNECT LIBRARY SIGNALS TO SLOTS
self.connectSignals()
# LINK SIGNALS TO SLOTS
self.linkControlPanelWidgets()
self.linkConfigWidgets()
self.linkToolbarWidgets()
# LOAD DEFAULT PROGRAM CONFIGURATION
self.configSetup()
# SET DEFAULT SCALING
self.setupDefaultScaling()
# LINK KEYBOARD SHORTCUTS
self.setKeyShortcuts()
# INITIAL STARTUP MESSAGE
self.printTerminal("Welcome to the Avalon ROV control interface.")
self.printTerminal("Click 'Help' on the taskbar to access the user manual.")
self.printTerminal("Connect to the ROV and CONTROLLER to get started.")
# LAUNCH GUI
self.showFullScreen()
# LAUNCH PILOT PROFILE SELECTOR
self.profileSelector.showPopup()
def initiateObjects(self):
"""
PURPOSE
Instantiates all the external library modules.
INPUT
NONE
RETURNS
NONE
"""
# OPEN PILOT PROFILE SELECTOR WINDOW
self.profileSelector = PROFILE_SELECTOR()
# INITIATE SERIAL COMMUNICATION LIBRARY
self.comms = ROV_SERIAL()
# INITIATE XBOX CONTROLLER LIBRARY
self.controller = CONTROLLER()
self.control = CONTROL_PANEL(self, self.controller, self.comms)
self.config = CONFIG(self, self.control, self.controller, self.comms)
self.toolbar = TOOLBAR(self)
# INITIATE SLIDE ANIMATION FOR TAB CHANGE
self.animation = SLIDE_ANIMATION(self.gui_view_widget)
self.animation.setSpeed(500)
self.animation.setDirection(Qt.Vertical)
# INITIATE CAMERA FEED LIBRARY
self.initiateCameraFeed()
# STYLESHEET LIBRARY AND STYLING FUNCTIONS
self.style = STYLE()
# INITIATE VISION TASKS
self.control.initialiseVisionWidgets()
# INITIATE TIMER
self.timer = TIMER(controlLayout = self.timer_control)
# INITIATE THRUSTERS
self.thrusters = THRUSTERS(controlLayout = self.orientation_control, configLayout = self.thruster_config)
# INITIATE ACTUATORS
self.actuators = ACTUATORS(controlLayout = self.actuator_control, configLayout = self.actuator_config)
# INITIATE ANALOG CAMERAS
self.analogCameras = ANALOG_CAMERAS(controlLayout = self.analog_camera_control, configLayout = self.analog_camera_config)
# INITIATE DIGITAL CAMERAS
self.digitalCameras = DIGITAL_CAMERAS(controlLayout = self.digital_camera_control, configLayout = self.digital_camera_config)
# INITIATE KEYBINDINGS
self.keybindings = KEYBINDINGS(configLayout = self.keybinding_config)
# INITIATE CONTROLLER INPUT DISPLAY
self.controllerDisplay = CONTROLLER_DISPLAY(configLayout = self.controller_display_config, controlLayout = self.controller_control)
# INITIATE SENSORS
self.sensors = SENSORS(controlLayout = self.sensor_control, configLayout = self.sensor_config)
def connectSignals(self):
"""
PURPOSE
Connect all the signals from modules to slots in the main program.
INPUT
NONE
RETURNS
NONE
"""
# PILOT PROFILE SELECTED SIGNAL
self.profileSelector.loadProfileSignal.connect(self.pilotProfileSelected)
self.profileSelector.saveProfileSignal.connect(self.addNewProfile)
# PROGRAM CLOSE SIGNAL
self.app.aboutToQuit.connect(self.programExit)
# WINDOW RESIZE EVENT
self.resizeEvent(QResizeEvent(self.size(), QSize()))
# KEYBINDING GET BUTTON STATES SIGNAL
self.keybindings.getButtonStates.connect(self.config.returnButtonStates)
# DIGITAL CAMERA CHANGE ADDRESS/LABEL SIGNALS
self.digitalCameras.cameraEnableSignal.connect(self.toggleCameraFeed)
self.digitalCameras.cameraResolutionSignal.connect(self.changeCameraResolution)
self.digitalCameras.cameraEditSignal.connect(self.updateCameraMenus)
self.digitalCameras.cameraChangeAddress.connect(self.changeCameraAddress)
# THRUSTER TEST/SET SPEED SIGNALS
self.thrusters.thrusterTestSignal.connect(self.control.changeThrusters)
self.thrusters.thrusterSpeedsSignal.connect(self.control.changeThrusters)
# ADD/REMOVE/TOGGLE ACTUATOR SIGNALS
self.actuators.addKeybinding.connect(lambda label: self.keybindings.addBinding(label))
self.actuators.removeKeybinding.connect(self.keybindings.removeBinding)
self.actuators.toggleActuatorSignal.connect(self.control.changeActuators)
# CONTROLLER VALUES SIGNAL
self.controller.processInputSignal.connect(self.control.processControllerInput)
# COMMS FAIL SIGNAL
self.comms.uiSerialFunction.connect(self.control.serialFailEvent)
###############################
### CONFIGURATION FUNCTIONS ###
###############################
@pyqtSlot(str)
def pilotProfileSelected(self, directory):
"""
PURPOSE
Called when a pilot profile is selected from the popup window.
Sets the directory of the configuration file to load.
Loads to configuration file.
INPUT
- directory = directory of the XML configuration file.
RETURNS
NONE
"""
self.fileName = "./config/" + directory
# LOAD SETTINGS FROM CONFIG FILE
self.resetConfig()
self.configSetup()
@pyqtSlot(str)
def addNewProfile(self, directory):
"""
PURPOSE
Called by the pilot profile selector window when the user wants to add a new pilot profile.
The default program configuration is saved.
INPUT
- directory = the directory of the the new pilot profile.
RETURNS
NONE
"""
self.writeDefaultConfigFile(directory)
def configSetup(self):
"""
PURPOSE
Reads the configuration file and configures the programs thruster, actuator, sensor, camera and controller settings.
If no configuration file is found, the program will open with default settings.
INPUT
NONE
RETURNS
NONE
"""
# READ PROGRAM SETTINGS FROM CONFIGURATION FILE
self.readConfigFile()
# APPLY SETTINGS TO GUI
self.programSetup()
def readConfigFile(self):
"""
PURPOSE
Reads the XML configuration file and stores the data in their respective modules.
INPUT
NONE
RETURNS
NONE
"""
# PARSE CONFIGURATION FILE
configFile = READ_CONFIG_FILE(self.fileName)
configFileStatus = configFile.parseFile()
if configFileStatus:
self.printTerminal('Configuration file found.')
# READ THEME SETTINGS
self.style.theme = configFile.readTheme()
# READ THRUSTER SETTINGS
self.thrusters.rovPositions, self.thrusters.reverseStates = configFile.readThruster()
# READ ACTUATOR SETTINGS
self.actuators.quantity, self.actuators.labelList = configFile.readActuator()
# READ ANALOG CAMERA SETTINGS
self.analogCameras.quantity, self.analogCameras.labelList, self.analogCameras.defaultCameras = configFile.readAnalogCamera()
# READ DIGITAL CAMERA SETTINGS
self.digitalCameras.quantity, self.digitalCameras.labelList, self.digitalCameras.addressList, self.digitalCameras.defaultCameras, self.digitalCameras.selectedResolutions = configFile.readDigitalCamera()
# READ KEYBINDING SETTINGS
self.keybindings.bindings = configFile.readKeyBinding()
# READ SENSOR SETTINGS
self.sensors.quantity, self.sensors.viewType, self.sensors.selectedTypes = configFile.readSensor()
else:
self.printTerminal('Configuration file not found.')
def writeConfigFile(self):
"""
PURPOSE
Write the program settings to an XML file.
INPUT
NONE
RETURNS
NONE
"""
# CREATE ROOT
configFile = WRITE_CONFIG_FILE(self.fileName)
configFile.createFile()
# SAVE THEME SETTINGS
configFile.saveTheme(self.style.theme)
# SAVE THRUSTER SETTINGS
configFile.saveThruster(self.thrusters.rovPositions, self.thrusters.reverseStates)
# SAVE ACTUATOR SETTINGS
configFile.saveActuator(self.actuators.quantity, self.actuators.labelList)
# SAVE ANALOG CAMERA SETTINGS
configFile.saveAnalogCamera(self.analogCameras.quantity, self.analogCameras.labelList, self.analogCameras.defaultCameras)
# SAVE DIGITAL CAMERA SETTINGS
configFile.saveDigitalCamera(self.digitalCameras.quantity, self.digitalCameras.labelList, self.digitalCameras.addressList, self.digitalCameras.defaultCameras, self.digitalCameras.selectedResolutions)
# SAVE KEYBINDING SETTINGS
configFile.saveKeybinding(self.keybindings.bindings)
# SAVE SENSOR SETTINGS
configFile.saveSensor(self.sensors.quantity, self.sensors.viewType, self.sensors.selectedTypes)
# WRITE SETTINGS TO XML FILE
configFile.writeFile()
def writeDefaultConfigFile(self, directory):
"""
PURPOSE
Saves a default program configuration to an XML file.
INPUT
- directory = the directory of the the new pilot profile.
RETURNS
NONE
"""
# CREATE ROOT
configFile = WRITE_CONFIG_FILE(directory)
configFile.createFile()
# SAVE THEME SETTINGS
style = STYLE()
configFile.saveTheme(style.theme)
# SAVE THRUSTER SETTINGS
thrusters = THRUSTERS()
configFile.saveThruster(thrusters.rovPositions, thrusters.reverseStates)
# SAVE ACTUATOR SETTINGS
actuators = ACTUATORS()
configFile.saveActuator(actuators.quantity, actuators.labelList)
# SAVE ANALOG CAMERA SETTINGS
analogCameras = ANALOG_CAMERAS()
configFile.saveAnalogCamera(analogCameras.quantity, analogCameras.labelList, analogCameras.defaultCameras)
# SAVE DIGITAL CAMERA SETTINGS
digitalCameras = DIGITAL_CAMERAS()
configFile.saveDigitalCamera(digitalCameras.quantity, digitalCameras.labelList, digitalCameras.addressList, digitalCameras.defaultCameras, digitalCameras.selectedResolutions)
# SAVE KEYBINDING SETTINGS
keybindings = KEYBINDINGS()
configFile.saveKeybinding(keybindings.bindings)
# SAVE SENSOR SETTINGS
sensors = SENSORS()
configFile.saveSensor(sensors.quantity, sensors.viewType, sensors.selectedTypes)
# WRITE SETTINGS TO XML FILE
configFile.writeFile()
def programSetup(self):
"""
PURPOSE
Applies the configuration settings to the GUI by calling the setup() function of each module.
INPUT
NONE
RETURNS
NONE
"""
# SETUP THEME
self.changeTheme(self.style.theme)
# SETUP TIMER
self.timer.setup()
# SETUP THRUSTERS
self.thrusters.setup()
# SETUP KEYBINDINGS
self.keybindings.setup()
# SETUP ACTUATORS
self.actuators.setup()
# SETUP ANALOG CAMERAS
self.analogCameras.setup()
# SETUP DIGITAL CAMERAS
self.digitalCameras.setup()
# SETUP CONTROLLER DISPLAY
self.controllerDisplay.setup()
# UPDATE GUI WITH SENSOR DATA
self.sensors.setup()
def resetConfig(self):
"""
PURPOSE
Resets the program to default settings (nothing configured).
INPUT
NONE
RETURNS
NONE
"""
# CLEAR TIMER LAYOUT
self.timer.reset()
# RESET THRUSTER SETTINGS
self.thrusters.reset()
# RESET ACTUATOR SETTINGS
self.actuators.reset()
# RESET SENSOR SETTINGS
self.sensors.reset()
# RESET ANALOG CAMERA SETTINGS
self.analogCameras.reset()
# RESET DIGITAL CAMERA SETTINGS
self.digitalCameras.reset()
# RESET CONTROLLER DISPLAY
self.controllerDisplay.reset()
# RESET KEYBINDING SETTINGS
self.keybindings.reset()
################################
### WIDGET LINKING FUNCTIONS ###
################################
def linkControlPanelWidgets(self):
"""
PURPOSE
Links widgets in the control panel tab to their respective functions.
INPUT
NONE
RETURNS
NONE
"""
# GO TO CONTROL PANEL TAB BUTTON
self.change_gui_control.clicked.connect(lambda state, view = 0: self.changeView(view))
self.change_gui_control.setChecked(True)
self.style.applyGlow(self.change_gui_control, "#0D47A1", 10)
# GO TO CONFIGURATION TAB BUTTON
self.change_gui_config.clicked.connect(lambda state, view = 1: self.changeView(view))
self.style.applyGlow(self.change_gui_config, "#0D47A1", 10)
# VERTICAL SPITTER
self.control_panel_splitter.splitterMoved.connect(self.splitterEvent)
# ROV CONNECT BUTTON
self.control_rov_connect.clicked.connect(self.control.rovSerialConnection)
self.control_rov_connect.setObjectName("large-button")
self.style.applyGlow(self.control_rov_connect, "#0D47A1", 10)
#self.control_rov_connect.setFixedHeight(int(self.control_rov_connect.sizeHint().height() * 1.5))
# CONTROLLER CONNECT BUTTON
self.control_controller_connect.clicked.connect(self.control.controllerConnection)
self.control_controller_connect.setObjectName("large-button")
self.style.applyGlow(self.control_controller_connect, "#0D47A1", 10)
#self.control_controller_connect.setFixedHeight(int(self.control_controller_connect.sizeHint().height() * 1.5))
# MACHINE VISION TASK BUTTONS
self.control_vision_mosaic.clicked.connect(lambda status, task = 0: self.control.popupVisionTask(task))
self.control_vision_shape_detection.clicked.connect(lambda status, task = 1: self.control.popupVisionTask(task))
self.control_vision_transect_line.clicked.connect(lambda status, task = 2: self.control.popupVisionTask(task))
self.control_vision_coral_health.clicked.connect(lambda status, task = 3: self.control.popupVisionTask(task))
# LINK EACH DIGITAL CAMERA DROP DOWN MENU TO THE SAME SLOT, PASSING CAMERA ID AS 1,2,3,4 ETC.
self.camera_feed_1_menu.activated.connect(lambda index, camera = 0: self.changeCameraFeedMenu(index, camera))
self.camera_feed_2_menu.activated.connect(lambda index, camera = 1: self.changeCameraFeedMenu(index, camera))
self.camera_feed_3_menu.activated.connect(lambda index, camera = 2: self.changeCameraFeedMenu(index, camera))
self.camera_feed_4_menu.activated.connect(lambda index, camera = 3: self.changeCameraFeedMenu(index, camera))
# CAMERA FEED CLICK EVENT
self.camera_feed_1.mousePressEvent = lambda event, cameraFeed = 0: self.changeCameraFeed(event, cameraFeed)
self.camera_feed_2.mousePressEvent = lambda event, cameraFeed = 1: self.changeCameraFeed(event, cameraFeed)
self.camera_feed_3.mousePressEvent = lambda event, cameraFeed = 2: self.changeCameraFeed(event, cameraFeed)
self.camera_feed_4.mousePressEvent = lambda event, cameraFeed = 3: self.changeCameraFeed(event, cameraFeed)
# SWITCH USER BUTTON
self.switch_user.clicked.connect(lambda: self.profileSelector.showPopup())
self.switch_user.setIcon(QIcon("./graphics/login-icon.png"))
self.switch_user.setIconSize(QSize(15,15))
self.switch_user.setObjectName("green-button")
# PROGRAM EXIT BUTTON
self.program_exit.clicked.connect(lambda: self.app.quit())
self.program_exit.setIcon(QIcon("./graphics/exit-icon.png"))
self.program_exit.setIconSize(QSize(15,15))
self.program_exit.setObjectName("red-button")
self.mini_rov_activate.clicked.connect(lambda sensor = 0, reading = None: self.sensors.updateSensorGraph(sensor, reading))
def linkConfigWidgets(self):
"""
PURPOSE
Links widgets in the configuration tab to their respective functions.
INPUT
NONE
RETURNS
NONE
"""
# ROV CONNECT BUTTON
self.config_rov_connect.clicked.connect(self.control.rovSerialConnection)
self.config_rov_connect.setObjectName("large-button")
self.style.applyGlow(self.config_rov_connect, "#0D47A1", 10)
#self.config_rov_connect.setFixedHeight(int(self.config_rov_connect.sizeHint().height() * 1.5))
# CONTROLLER CONNECT BUTTON
self.config_controller_connect.clicked.connect(self.control.controllerConnection)
self.config_controller_connect.setObjectName("large-button")
self.style.applyGlow(self.config_controller_connect, "#0D47A1", 10)
#self.config_controller_connect.setFixedHeight(int(self.config_controller_connect.sizeHint().height() * 1.5))
# SERIAL COMMUNICATION BUTTONS
self.config_com_port_list.activated.connect(self.config.changeComPort)
self.config_find_com_ports.clicked.connect(self.config.refreshComPorts)
def linkToolbarWidgets(self):
"""
PURPOSE
Links widgets in the toolbar to their respective functions.
INPUT
NONE
RETURNS
NONE
"""
# FILE MENU
self.toolbar_save_settings.triggered.connect(self.toolbar.saveSettings)
self.toolbar_change_pilot.triggered.connect(self.toolbar.changePilotProfile)
self.toolbar_load_settings.triggered.connect(self.toolbar.loadSettings)
self.toolbar_reset_settings.triggered.connect(self.toolbar.resetSettings)
self.toolbar_toggle_theme.triggered.connect(self.toolbar.toggleTheme)
# HELP MENU
self.toolbar_open_documentation.triggered.connect(self.toolbar.openDocumentation)
self.toolbar_open_github.triggered.connect(self.toolbar.openGitHub)
self.toolbar_open_user_guide.triggered.connect(self.toolbar.openUserGuide)
################################
#### CAMERA FEEDS FUNCTIONS ####
################################
def initiateCameraFeed(self):
"""
PURPOSE
Instantiates a camera feed object for each camera and starts the threads.
INPUT
NONE
RETURNS
NONE
"""
self.cameraFeeds = [self.camera_feed_1, self.camera_feed_2, self.camera_feed_3, self.camera_feed_4]
# INITIATE CAMERA THREADS
feedQuantity = len(self.cameraFeeds)
for i in range(feedQuantity):
cameraThread = CAMERA_CAPTURE(identifier = i)
# CONNECT SIGNAL TO SLOT
cameraThread.cameraNewFrameSignal.connect(self.updateCameraFeed)
# STORE THREAD POINTER FOR LATER USE
self.cameraThreadList.append(cameraThread)
# START THREAD
cameraThread.start()
@pyqtSlot()
def updateCameraMenus(self):
"""
PURPOSE
Refreshes the digital camera feed menus on the control panel tab.
Called when a camera feed is changed or the name is modified.
INPUT
NONE
RETURNS
"""
menuList = [self.camera_feed_1_menu, self.camera_feed_2_menu, self.camera_feed_3_menu, self.camera_feed_4_menu]
for i, menu in enumerate(menuList):
menu.clear()
menu.addItem("None")
menu.addItems(self.digitalCameras.labelList)
menu.setCurrentIndex(self.digitalCameras.selectedCameras[i])
@pyqtSlot(bool, int)
def toggleCameraFeed(self, status, feed):
"""
PURPOSE
Turns specific camera feed off.
INPUT
- status = True to turn ON, False to turn OFF.
- feed = the camera to be toggled (1,2,3,4).
RETURNS
NONE
"""
if status:
self.cameraThreadList[feed].feedBegin()
self.cameraThreadList[feed].start()
else:
self.cameraThreadList[feed].feedStop()
@pyqtSlot(int, str)
def changeCameraAddress(self, camera, address):
"""
PURPOSE
Changes the source address of a specific camera.
Called by the DIGITAL_CAMERAS module which then calls the changeSource function in the camera module.
INPUT
NONE
- camera = the camera feed being changed.
- addess = the new source address.
RETURNS
NONE
"""
# FORMAT ADDRESS
formattedAddress = self.digitalCameras.addressConverter(address)
# CHECK IF THIS ADDRESS IS ALREADY IN USE
for i, cameraThread in enumerate(self.cameraThreadList):
address = cameraThread.address
if address == formattedAddress and i != camera:
# DISCONNECT FROM THAT FEED BEFORE ATTEMPTING TO CONNECT AGAIN
# PREVENTS THREADS FIGHTING OVER CAMERA ACCESS
cameraThread.changeSource("")
# REINITIALISE CAMERA WITH NEW ADDRESS
self.cameraThreadList[camera].changeSource(formattedAddress)
@pyqtSlot(int, int, int)
def changeCameraResolution(self, camera, width, height):
"""
PURPOSE
Calls function in camera capture library to change camera resolution.
INPUT
- camera = the camera feed being modified (0,1,2,3).
- width = width of the frame in px.
- height = height of the frame in px.
RETURNS
NONE
"""
try:
self.cameraThreadList[camera].changeResolution(width, height)
except:
pass
@pyqtSlot(QPixmap, int)
def updateCameraFeed(self, frame, identifier):
"""
PURPOSE
Refreshes a specific camera feed with a new frame.
INPUT
- frame = QImage containing the new frame captures from the camera.
- identifier = the identification number of the camera feed (0, 1, 2 etc.)
RETURNS
NONE
"""
# RESIZE PIXMAP
pixmap = frame.scaled(self.cameraFeeds[identifier].size().width(), self.cameraFeeds[identifier].size().height(), Qt.KeepAspectRatio, Qt.SmoothTransformation)
# PAINT PIXMAP ONTO LABEL
self.cameraFeeds[identifier].setPixmap(pixmap)
def changeCameraFeed(self, event, cameraFeed):
"""
PURPOSE
Changes which camera is shown in the main camera feed. When a secondary camera feed is clicked, it is swapped with the current primary camera feed.
INPUT
- event = Mouse click event.
- cameraFeed = Camera feed that has been clicked on (1,2,3,4).
RETURNS
NONE
"""
# SWAP MAIN FEED WITH SELECTED SECONDARY FEED
try:
self.digitalCameras.selectedCameras[0], self.digitalCameras.selectedCameras[cameraFeed] = self.digitalCameras.selectedCameras[cameraFeed], self.digitalCameras.selectedCameras[0]
self.digitalCameras.setCameraAddresses()
except:
pass
# UPDATE MENUS
self.updateCameraMenus()
def changeCameraFeedMenu(self, index, cameraFeed):
"""
PURPOSE
Changes the camera feed from the menu options.
INPUTS
- index = menu index of the camera selected.
- cameraFeed = the camera feed that is being modified.
"""
self.digitalCameras.selectedCameras[cameraFeed] = index
# CHECK FOR DUPLICATE CAMERA FEEDS
for i, camera in enumerate(self.digitalCameras.selectedCameras):
if camera == index and i != cameraFeed:
self.digitalCameras.selectedCameras[i] = 0
self.updateCameraMenus()
# UPDATE CAMERA FEEDS
self.digitalCameras.setCameraAddresses()
#############################
###### THEME FUNCTIONS ######
#############################
def changeTheme(self, theme = None):
"""
PURPOSE
Change the program theme between light and dark.
INPUT
- theme = True for dark theme, False for light theme.
RETURNS
NONE
"""
# TOGGLE CURRENT THEME
if theme == None:
self.style.theme = not self.style.theme
else:
self.style.theme = theme
# APPLY NEW APPLICATION DEFAULT COLOR PALETTE
self.style.setPalette(self.style.theme, self.app)
# GET CURRENT DEFAULT WIDGET HEIGHT (TO CORRECTLY SET BORDER RADIUS)
self.style.widgetHeight = self.getDefaultButtonSize()
# CHANGE PROGRAM STYLESHEETS
self.style.setStyleSheets(self.style.theme)
# SET STYLESHEETS
try:
globalStylesheets = (
self.style.normalButton +
self.style.largeButton +
self.style.actuatorButton +
self.style.orientationButton +
self.style.timerStartButton +
self.style.blueButton +
self.style.greenButton +
self.style.redButton +
self.style.timerLCD +
self.style.scrollArea +
self.style.comboBox +
self.style.groupBox +
self.style.settingsFrame +
self.style.thrusterFrame +
self.style.actuatorFrame +
self.style.digitalCameraFrame +
self.style.keybindingFrame +
self.style.labelOnOff +
self.style.infoLabel)
# APPLY TO MAIN PROGRAM
self.setStyleSheet(globalStylesheets)
# APPLY TO PROFILE SELECTOR POPUP
self.profileSelector.setStyleSheet(globalStylesheets)
except:
pass
# LOAD AVALON LOGO
#self.setLogo(self.style.theme)
def setLogo(self, theme):
"""
PURPOSE
Loads the Avalon logo for either the light or dark theme.
INPUT
- theme = True for dark theme, False for light theme.
RETURNS
NONE
"""
# DARK THEME
if theme:
self.avalon_logo.clear()
avalonPixmap = QPixmap('graphics/thumbnail.png')
avalonPixmap = avalonPixmap.scaledToWidth(200, Qt.SmoothTransformation)
self.avalon_logo.setPixmap(avalonPixmap)
# LIGHT THEME
else:
self.avalon_logo.clear()
avalonPixmap = QPixmap('graphics/thumbnail.png')
avalonPixmap = avalonPixmap.scaledToWidth(200, Qt.SmoothTransformation)
self.avalon_logo.setPixmap(avalonPixmap)
###########################
#### SCALING FUNCTIONS ####
###########################
def setupDefaultScaling(self):
"""
PURPOSE
Sets the default proportion of the side bar on the control panel at program launch.
INPUT
NONE
RETURNS
NONE
"""
# SET DEFAULT SIDE BAR WIDTH
width,_ = self.getScreenSize()
self.con_panel_functions_widget.resize(int(width/3),self.con_panel_functions_widget.height())
def getScreenSize(self):
"""
PURPOSE
Gets the width and height of the screen.
INPUT
NONE
RETURNS
- width = width of screen in pixels.
- height = height of screen in pixels.
"""