-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserialHandler.py
More file actions
994 lines (879 loc) · 58.2 KB
/
serialHandler.py
File metadata and controls
994 lines (879 loc) · 58.2 KB
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
# Authors: Aaron Rito, Corwin Perren
# Date: 10/2/17
# Project: SARL Shuttlebox Behavior System
# Client: Oregon State University, SARL lab
########################################################################################################################
# This thread is instantiated in the BoxHandlerCore file on line 52. Each instance of this thread will communicate #
# with it's own Shuttlebox, on it's own COM port. To access different threads, call functions in the BoxHandler class#
# and send signals out to the other thread, including other instances of this one. It is safe to instantiate the #
# settings class and Qsettings handle, however, one should not instantiate the results class in this thread or risk #
# data corruption. #
########################################################################################################################
from PyQt5 import QtCore, QtWidgets, QtGui
import serial
from Framework.BoxHandlerCore import BoxHandler
from mainFile import NewWindow
from settings_core import ShuttleSettings
class SerialThread(QtCore.QThread):
updating_settings_signal = QtCore.pyqtSignal()
updating_settings_signal_close = QtCore.pyqtSignal()
def __init__(self, main_window, box_handler, comport_string):
super(SerialThread, self).__init__()
# inheritances
self.main_window = main_window
self.box_handler = box_handler
self.comport_string = comport_string
self.main_ref = NewWindow
# Gui Object References
self.id_list_widget = self.main_window.id_list_widget # type: QtWidgets.QListWidget
# Serial buffer and connection set up
self.in_buffer = ""
self.arduino = serial.Serial(comport_string, 57600, bytesize=8, stopbits=1, timeout=None)
# Class variables
self.should_run = True
self.current_state = 0
self.results_flag = 0
self.current_state_label = "Wait for Start"
self.current_state_strings = ["Wait for Start", "Test Start", "Settle Period", "Inter Trial", "Trial Start",
"Trial Running", "Trial Shock", "Trial End", "Abort", "Test End"]
self.pattern_list = ["Heart", "Big X", "Big O", "Horizontal Lines", "Vertical Lines", "Diagonal Lines",
"Big Line", "Small Box", "Corners"]
self.results = None
self.update_flag = None
self.settings_flag = False
self.box_id_found_flag = False
self.box_id = None
self.fish_gender = None
self.fault_flag = 0
# More static GUI elements
self.box_tab_widget = None # type: QtWidgets.QTabWidget
self.tab_widget_w = self.main_window.tab_widget_widget
self.__connect_signals_to_slots()
# launching class instances last (for box_id)
self.settings = QtCore.QSettings()
self.settings_core = ShuttleSettings(main_window)
self.start()
def __connect_signals_to_slots(self):
# GUI's get built here
self.main_window.id_list_widget.currentRowChanged.connect(self.on_current_box_id_changed_slot)
self.main_window.stop_all_threads.connect(self.on_stop_all_threads_slot)
self.box_handler.start_all_boxes_signal.connect(self.on_start_all_boxes)
self.box_handler.abort_all_boxes_signal.connect(self.on_abort_all_boxes)
self.updating_settings_signal.connect(self.show_update_wait)
def run(self):
while self.should_run:
try:
if self.arduino.inWaiting():
in_byte = self.arduino.read().decode("utf-8")
self.in_buffer += in_byte
if in_byte == "\n":
if "show: " in self.in_buffer:
# report box ready to BoxHandler
self.box_handler.box_counter()
if "u: " in self.in_buffer:
# The updates to a Shuttlebox are complete
self.update_flag = True
self.box_handler.send_data_init(self.box_id)
self.updating_settings_signal_close.emit()
if "Box ID: " in self.in_buffer:
# The system found an active Shuttlebox
self.box_id_found_flag = True
self.box_id = int(self.in_buffer.split(": ")[1])
print("Box ID: " + str(self.box_id) + " found")
if "s: " in self.in_buffer:
# The current state of the Shuttlebox has changed
self.current_state = int(self.in_buffer.split(": ")[1])
print("STATE = " + str(self.current_state) + " from box: " + str(self.box_id))
if self.box_tab_widget:
self.update_status_label(int(self.current_state))
if "z, " in self.in_buffer:
# The assay has ended or the trial has been aborted, results received from Arduino.
self.results = self.in_buffer.split(", ")
self.results.pop(0)
self.results.pop(0)
self.box_handler.send_data(self.results, self.box_id)
self.results_flag = 1
self.fault_flag = 0
if "x: " in self.in_buffer:
# The Shuttlebox is requesting it's settings
self.send_to_box(self.settings_core.send_box_configs(self.box_id))
self.send_to_box(self.settings_core.send_settle_lights(self.box_id))
self.send_to_box(self.settings_core.send_trial_lights(self.box_id))
self.send_to_box(self.settings_core.send_start_lights(self.box_id))
################ If there is a problem updating boxes, use these to verify the arduino######
# temp = " "
# self.send_to_box(" 50,1,600,24,12,12,16,8,95,20,500,50,5")
# self.send_to_box("50,1,600,24,12,12,16,8,95,20,500,50,5")
# self.send_to_box("4,8,100,150,255,0,255,0,50,75,255,0,255,0,200,225,255,0,255,200,0,1")
# self.send_to_box("7,3,200,15,12,255,10,255,50,75,0,255,0,255,200,225,0,255,255,200,1,0")
# self.send_to_box("7,3,200,15,12,255,10,255,50,75,0,255,0,255,200,225,0,255,255,200,1,0")
print("Box", str(self.box_id), " sent: ", self.in_buffer)
self.in_buffer = ""
self.msleep(50)
self.arduino.flush()
except IOError as e:
self.should_run = False
########################################################################################################################
# These functions support the settings updates, and handle updating the GUI when the list item is changed. #
########################################################################################################################
def send_to_box(self, message):
self.arduino.write(bytes(str(message), "utf-8"))
# !!!!VERY IMPORTANT!!!! This function updates the settings in the registry, the widgets, and the arduinos.
# It is called whenever there is a default reset or a box update. Called from multiple button....
def update_settings_slot(self):
# Make sure the box isn't running before updating
if self.current_state != 0:
m = QtWidgets.QMessageBox()
m.setInformativeText("Error: Cannot update Shuttlebox while trial is running.")
m.exec()
else:
self.box_tab_widget.hide()
m = QtWidgets.QMessageBox()
m.setInformativeText("Are you sure you want to update Shuttlebox " + str(self.box_id))
m.setStandardButtons(QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel)
m.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
m.setModal(True)
x = m.exec()
if x == QtWidgets.QMessageBox.Ok:
#self.counter = 0 ##############remove this before launch#################################
# Setup the waiting progress window
self.welcome = QtWidgets.QProgressDialog()
self.welcome.setCancelButton(None)
self.welcome.setRange(0, 0)
self.my_font = QtGui.QFont()
self.my_font.setPointSizeF(12)
self.my_font.setBold(True)
self.welcome.setFont(self.my_font)
self.welcome.setWindowTitle("SARL Shuttlebox Behavior System")
self.welcome_label = QtWidgets.QLabel(
" Please wait while Shuttlebox " + str(self.box_id) +
" is updated.\n This may take a moment....")
self.welcome_button = QtWidgets.QPushButton(None)
self.welcome_window = QtWidgets.QGraphicsScene()
self.welcome_image = QtGui.QImage("logo.png")
self.lab = QtWidgets.QLabel()
self.imageLabel = QtWidgets.QLabel()
self.imageLabel.setPixmap(QtGui.QPixmap.fromImage(self.welcome_image))
layout = QtWidgets.QVBoxLayout()
layout.addWidget(self.imageLabel)
layout.addWidget(self.welcome_label)
layout.addSpacing(50)
self.welcome.setLayout(layout)
self.welcome.resize(250, 200)
self.welcome.setModal(True)
self.welcome.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
self.updating_settings_signal_close.connect(self.close_update)
# Send the signals to update the box
self.update_flag = False
self.settings_core.update_settings(self.box_id, 0)
self.box_handler.send_data_init(self.box_id)
self.send_to_box(self.box_id)
self.send_to_box(",")
self.send_to_box("249")
print("settings signal sent")
# Show the progress bar, it's closed by a signal from the serial input on line ..
self.updating_settings_signal.emit()
msg_box = QtWidgets.QMessageBox()
msg_box.setStandardButtons(QtWidgets.QMessageBox.Ok)
msg_box.setText("Settings Updated")
msg_box.exec()
self.box_tab_widget.show()
self.update_flag = False
self.settings_flag = False
self.box_tab_widget.show()
# These two functions handle the progress window
def show_update_wait(self):
self.welcome.exec_()
def close_update(self):
self.welcome.done(0)
# VERY IMPORTANT this function builds the new tabs when a box id is changed from the list. It also destroys the
# GUI elements from the tab being clicked away from. The thread for the Shuttlebox will still be active and
# rec/send data over serial. It's important to rememeber the GUI elements do not exist outside of the clicked tab.
# when the settings change they will be updated in registry and retrieved when the new id is clicked on.
def on_current_box_id_changed_slot(self, row_id):
list_box_id = int(self.id_list_widget.currentItem().text())
# list_box_id = row_id + 1
if list_box_id == self.box_id:
layout = self.tab_widget_w.layout() # type: QtWidgets.QLayout
for i in reversed(range(layout.count())):
widgetToRemove = layout.itemAt(i).widget()
# remove it from the layout list
layout.removeWidget(widgetToRemove)
# remove it from the gui
widgetToRemove.setParent(None)
# Make a new tab widget(yes all of it) and set it to the main layout, update settings
layout.addWidget(self.make_box_tab_widget(self.tab_widget_w))
self.id_list_widget.sortItems()
self.update_status_label(int(self.current_state))
self.box_handler.send_data_init(int(row_id + 1))
########################################################################################################################
########################################################################################################################
# #
# Make the GUI tabs and retrieve the settings for the selected box (runs 600+ lines) #
# #
########################################################################################################################
########################################################################################################################
########################################################################################################################
# Build the box tab. This function runs most of the code on this thread to build a new box tab with populated windows#
########################################################################################################################
def make_box_tab_widget(self, parent):
self.box_tab_widget = QtWidgets.QTabWidget(parent)
self.make_control_tab(parent)
self.make_settings_tab(parent)
self.make_lights_tab(parent)
self.make_admin_tab(parent)
return self.box_tab_widget
########################################################################################################################
# Build the Admin Tab #
########################################################################################################################
def make_admin_tab(self, parent):
admin_tab_widget = QtWidgets.QWidget(parent)
self.box_tab_widget.addTab(admin_tab_widget, "Admin")
admin_layout = QtWidgets.QFormLayout()
self.restore_all_def_button = QtWidgets.QPushButton("THINK FIRST")
self.restore_all_def_button.clicked.connect(self.restore_all_def_slot)
self.restore_def_button = QtWidgets.QPushButton("MOSTLY SAFE")
self.restore_def_button.clicked.connect(self.restore_def_slot)
self.apply_all_button = QtWidgets.QPushButton("APPLY TO ALL")
self.apply_all_button.clicked.connect(self.apply_all_slot)
# add buttons to the layout
admin_layout.addRow("Restore defaults for Shuttlebox " + str(self.box_id), self.restore_def_button)
admin_layout.addRow("Restore all defaults", self.restore_all_def_button)
admin_layout.addRow("Apply settings to all boxes", self.apply_all_button)
admin_layout.setHorizontalSpacing(10)
holder_layout = QtWidgets.QHBoxLayout()
holder_layout.addSpacing(220)
holder_layout.addLayout(admin_layout)
admin_tab_widget.setLayout(holder_layout)
# Admin slots
def apply_all_slot(self):
msg = QtWidgets.QMessageBox()
msg.setStandardButtons(QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel)
msg.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
msg.setInformativeText("Are you sure you want to apply the settings from Shuttlebox " + str(self.box_id) +
" to all Shuttlebox settings?")
x = msg.exec()
if x == QtWidgets.QMessageBox.Ok:
self.settings_core.apply_all_settings(self.box_id)
msg = QtWidgets.QMessageBox()
msg.setStandardButtons(QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel)
msg.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
msg.setInformativeText("Settings from Shuttlebox " + str(self.box_id) +
" applied to all Shuttlebox settings. " +
"Please restart the program to update the boxes")
msg.exec()
def restore_all_def_slot(self):
if self.current_state != 0:
m = QtWidgets.QMessageBox()
m.setInformativeText("Error: Cannot update Shuttlebox while trial is running.")
m.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
m.exec()
else:
msgBox = QtWidgets.QMessageBox()
msgBox.setText("Are you absolutely sure you want to restore the defaults for ALL Shuttleboxes?")
msgBox.setStandardButtons(QtWidgets.QMessageBox.RestoreDefaults | QtWidgets.QMessageBox.Cancel)
msgBox.setDefaultButton(QtWidgets.QMessageBox.Cancel)
msgBox.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
ret = msgBox.exec_()
if ret == QtWidgets.QMessageBox.RestoreDefaults:
self.settings_core.restore_all_defaults()
self.get_conf_settings()
self.control_id_box.setText(self.settings.value(("control_number/box_id_" + str(self.box_id))))
self.concentrate_box.setText(self.settings.value("concentrate/box_id_", str(self.box_id)))
self.get_settle_lights_settings()
self.get_trial_lights_settings()
self.get_start_lights_settings()
msgBox = QtWidgets.QMessageBox()
msgBox.setText("Defaults restored. Please restart the program to update the Shuttleboxes.")
msgBox.setStandardButtons(QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel)
msgBox.setDefaultButton(QtWidgets.QMessageBox.Ok)
msgBox.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
msgBox.exec_()
def restore_def_slot(self):
if self.current_state != 0:
m = QtWidgets.QMessageBox()
m.setInformativeText("Error: Cannot update Shuttlebox while trial is running.")
m.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
m.exec()
else:
msgbox = QtWidgets.QMessageBox()
msgbox.setText("Are you absolutely sure you want to restore the defaults for Shuttlebox " + str(self.box_id) +
"?")
msgbox.setStandardButtons(QtWidgets.QMessageBox.RestoreDefaults | QtWidgets.QMessageBox.Cancel)
msgbox.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
msgbox.setDefaultButton(QtWidgets.QMessageBox.Cancel)
ret = msgbox.exec_()
if ret == QtWidgets.QMessageBox.RestoreDefaults:
self.settings_core.restore_box_defaults(self.box_id)
self.update_settings_slot()
self.get_conf_settings()
self.control_id_box.setText(self.settings.value(("control_number/box_id_" + str(self.box_id))))
self.concentrate_box.setText(self.settings.value("concentrate/box_id_" + str(self.box_id)))
self.get_settle_lights_settings()
self.get_trial_lights_settings()
self.get_start_lights_settings()
########################################################################################################################
# Build the settings tab #
########################################################################################################################
def make_settings_tab(self, parent):
self.settings_tab_widget = QtWidgets.QWidget(parent)
self.box_tab_widget.addTab(self.settings_tab_widget, "Settings")
settings_layout = QtWidgets.QFormLayout()
settings_layout2 = QtWidgets.QFormLayout()
# make the boxes
self.n_of_trials_box = QtWidgets.QSpinBox()
self.selection_box = QtWidgets.QSpinBox()
self.settle_time_box = QtWidgets.QSpinBox()
self.trial_duration_box = QtWidgets.QSpinBox()
self.seek_time_box = QtWidgets.QSpinBox()
self.trial_settle_box = QtWidgets.QSpinBox()
self.fault_side_box = QtWidgets.QSpinBox()
self.fault_out_box = QtWidgets.QSpinBox()
self.shock_voltage_box = QtWidgets.QSpinBox()
self.shock_interval_box = QtWidgets.QSpinBox()
self.shock_duration_box = QtWidgets.QSpinBox()
self.success_trials_box = QtWidgets.QSpinBox()
self.update_button = QtWidgets.QPushButton("UPDATE BOX " + str(self.box_id))
# add the elements to the layout
settings_layout.addRow("Number of Trials", self.n_of_trials_box)
settings_layout.addRow("Selection Mode (default = 1)", self.selection_box)
settings_layout.addRow("Settle Time (s)", self.settle_time_box)
settings_layout.addRow("Trial Duration (s)", self.trial_duration_box)
settings_layout.addRow("Seek Time (s)", self.seek_time_box)
settings_layout.addRow("Inter-Trial time (s)", self.trial_settle_box)
settings_layout.addRow("Trials to fault out", self.fault_side_box)
settings_layout.addRow("Fault Out Percent (%)", self.fault_out_box)
settings_layout.addRow("Shock Voltage (V)", self.shock_voltage_box)
settings_layout.addRow("Shock Interval (ms)", self.shock_interval_box)
settings_layout.addRow("Shock Duration (ms)", self.shock_duration_box)
settings_layout.addRow("Trials to success out", self.success_trials_box)
settings_layout2.addRow("Save Settings", self.update_button)
# set the ranges
self.n_of_trials_box.setRange(0, 255)
self.selection_box.setRange(0, 1)
self.settle_time_box.setRange(0, 1000)
self.trial_duration_box.setRange(0, 255)
self.seek_time_box.setRange(0, 255)
self.trial_settle_box.setRange(0, 255)
self.fault_side_box.setRange(0, 255)
self.fault_out_box.setRange(0, 100)
self.shock_voltage_box.setRange(0, 24)
self.shock_interval_box.setRange(0, 1000)
self.shock_duration_box.setRange(0, 1000)
self.success_trials_box.setRange(0, 255)
# Get the settings
self.get_conf_settings()
# connect the slots
self.n_of_trials_box.valueChanged.connect(self.n_of_trials_slot)
self.selection_box.valueChanged.connect(self.selection_slot)
self.settle_time_box.valueChanged.connect(self.settle_time_slot)
self.trial_duration_box.valueChanged.connect(self.trial_duration_slot)
self.seek_time_box.valueChanged.connect(self.seek_time_slot)
self.trial_settle_box.valueChanged.connect(self.trial_settle_slot)
self.fault_side_box.valueChanged.connect(self.fault_side_slot)
self.fault_out_box.valueChanged.connect(self.fault_out_slot)
self.shock_voltage_box.valueChanged.connect(self.shock_voltage_slot)
self.shock_voltage_box.valueChanged.connect(self.shock_voltage_slot)
self.shock_interval_box.valueChanged.connect(self.shock_interval_slot)
self.shock_duration_box.valueChanged.connect(self.shock_duration_slot)
self.success_trials_box.valueChanged.connect(self.success_trials_slot)
self.update_button.clicked.connect(self.update_settings_slot)
# Apply the layouts
holder_layout = QtWidgets.QVBoxLayout()
top_layout = QtWidgets.QHBoxLayout()
bottom_layout = QtWidgets.QHBoxLayout()
top_layout.addSpacing(10)
top_layout.addLayout(settings_layout)
bottom_layout.addSpacing(260)
bottom_layout.addLayout(settings_layout2)
settings_layout.setHorizontalSpacing(100)
settings_layout.setVerticalSpacing(10)
settings_layout2.setHorizontalSpacing(100)
holder_layout.addLayout(top_layout)
holder_layout.addSpacing(200)
holder_layout.addLayout(bottom_layout)
self.settings_tab_widget.setLayout(holder_layout)
# Settings Slots
def get_conf_settings(self):
# retrieve the settings
self.n_of_trials_box.setValue(
self.settings.value(("boxes/box_id_" + str(self.box_id) + "/n_of_trials"), int))
self.selection_box.setValue(
self.settings.value(("boxes/box_id_" + str(self.box_id) + "selection_mode"), int))
self.settle_time_box.setValue(
self.settings.value(("boxes/box_id_" + str(self.box_id) + "/settle_time"), int))
self.trial_duration_box.setValue(
self.settings.value(("boxes/box_id_" + str(self.box_id) + "/trial_duration"),
int))
self.seek_time_box.setValue(self.settings.value(("boxes/box_id_" + str(self.box_id) + "/seek_time"), int))
self.trial_settle_box.setValue(
self.settings.value(("boxes/box_id_" + str(self.box_id) + "/trial_settle_time"),
int))
self.fault_side_box.setValue(self.settings.value(("boxes/box_id_" + str(self.box_id) + "/fault_out_side"),
int))
self.fault_out_box.setValue(self.settings.value(("boxes/box_id_" + str(self.box_id) + "/fault_out_percent"),
int))
self.shock_voltage_box.setValue(self.settings.value(("boxes/box_id_" + str(self.box_id) + "/shock_voltage"),
int))
self.shock_interval_box.setValue(
self.settings.value(("boxes/box_id_" + str(self.box_id) + "/shock_interval"),
int))
self.shock_duration_box.setValue(
self.settings.value(("boxes/box_id_" + str(self.box_id) + "/shock_duration"),
int))
self.success_trials_box.setValue(
self.settings.value(("boxes/box_id_" + str(self.box_id) + "/success_trials"),
int))
#################### WRITE A FUNCTION HERE TO DEAL WITH THESE#####################################################
def n_of_trials_slot(self):
self.settings_flag = True
self.settings.setValue(("boxes/box_id_" + str(self.box_id) + "/n_of_trials"), self.n_of_trials_box.value())
def selection_slot(self):
self.settings_flag = True
self.settings.setValue(("boxes/box_id_" + str(self.box_id) + "selection_mode"), self.selection_box.value())
def settle_time_slot(self):
self.settings_flag = True
self.settings.setValue(("boxes/box_id_" + str(self.box_id) + "/settle_time"), self.settle_time_box.value())
def trial_duration_slot(self):
self.settings_flag = True
self.settings.setValue(("boxes/box_id_" + str(self.box_id) + "/trial_duration"),
self.trial_duration_box.value())
def seek_time_slot(self):
self.settings_flag = True
self.settings.setValue(("boxes/box_id_" + str(self.box_id) + "/seek_time"), self.seek_time_box.value())
def trial_settle_slot(self):
self.settings_flag = True
self.settings.setValue(("boxes/box_id_" + str(self.box_id) + "/trial_settle_time"),
self.trial_settle_box.value())
def fault_side_slot(self):
self.settings_flag = True
self.settings.setValue(("boxes/box_id_" + str(self.box_id) + "/fault_out_side"),
self.fault_side_box.value())
def fault_out_slot(self):
self.settings_flag = True
self.settings.setValue(("boxes/box_id_" + str(self.box_id) + "/fault_out_percent"),
self.fault_out_box.value())
def shock_voltage_slot(self):
self.settings_flag = True
self.settings.setValue(("boxes/box_id_" + str(self.box_id) + "/shock_voltage"),
self.shock_voltage_box.value())
def shock_interval_slot(self):
self.settings_flag = True
self.settings.setValue(("boxes/box_id_" + str(self.box_id) + "/shock_interval"),
self.shock_interval_box.value())
def shock_duration_slot(self):
self.settings_flag = True
self.settings.setValue(("boxes/box_id_" + str(self.box_id) + "/shock_duration"),
self.shock_duration_box.value())
def success_trials_slot(self):
self.settings_flag = True
self.settings.setValue(("boxes/box_id_" + str(self.box_id) + "/success_trials"),
self.success_trials_box.value())
########################################################################################################################
# Build the lighting tab #
########################################################################################################################
def make_lights_tab(self, parent):
lights_tab_widget = QtWidgets.QWidget(parent)
self.box_tab_widget.addTab(lights_tab_widget, "Lights")
lights_tab_layout = QtWidgets.QFormLayout()
# #################SETTLE LIGHTS################################################################################
# make the buttons
self.settle_lights_r_pattern_button = QtWidgets.QComboBox()
self.settle_lights_r_pattern_button.insertItems(0, self.pattern_list)
self.settle_lights_l_pattern_button = QtWidgets.QComboBox()
self.settle_lights_l_pattern_button.insertItems(0, self.pattern_list)
self.settle_lights_r_button = QtWidgets.QPushButton()
self.settle_lights_l_button = QtWidgets.QPushButton()
self.settle_lights_rb_button = QtWidgets.QPushButton()
self.settle_lights_lb_button = QtWidgets.QPushButton()
self.get_settle_lights_settings()
# add the buttons to the layout
lights_tab_layout.addRow("Right Side Settle Pattern", self.settle_lights_r_pattern_button)
lights_tab_layout.addRow("Right Side Settle Lights Color", self.settle_lights_r_button)
lights_tab_layout.addRow("Right Side Settle Lights Background Color", self.settle_lights_rb_button)
lights_tab_layout.addRow("Left Side Settle Pattern", self.settle_lights_l_pattern_button)
lights_tab_layout.addRow("Left Side Settle Lights Color", self.settle_lights_l_button)
lights_tab_layout.addRow("Left Side Settle Lights Background Color", self.settle_lights_lb_button)
# connect the slots
self.settle_lights_r_button.clicked.connect(lambda: self.color_select_slot("settle_lights", "right_side_color",
"right_side_sat", "right_side_bright"
, self.settle_lights_r_button))
self.settle_lights_rb_button.clicked.connect(lambda: self.color_select_slot("settle_lights", "right_back_color",
"right_back_sat",
"right_back_bright",
self.settle_lights_rb_button))
self.settle_lights_l_button.clicked.connect(lambda: self.color_select_slot("settle_lights", "left_side_color",
"left_side_sat", "left_side_bright"
, self.settle_lights_l_button))
self.settle_lights_lb_button.clicked.connect(lambda: self.color_select_slot("settle_lights", "left_back_color",
"left_back_sat", "left_back_bright"
, self.settle_lights_lb_button))
self.settle_lights_r_pattern_button.currentIndexChanged.connect(lambda: self.pattern_select_slot(
"settle_lights", "right_pattern", self.settle_lights_r_pattern_button.currentIndex()))
self.settle_lights_l_pattern_button.currentIndexChanged.connect(lambda: self.pattern_select_slot(
"settle_lights", "left_pattern", self.settle_lights_l_pattern_button.currentIndex()))
# #######################TRIAL LIGHTS###########################################################################
# make the buttons
self.trial_lights_r_pattern_button = QtWidgets.QComboBox()
self.trial_lights_r_pattern_button.insertItems(0, self.pattern_list)
self.trial_lights_l_pattern_button = QtWidgets.QComboBox()
self.trial_lights_l_pattern_button.insertItems(0, self.pattern_list)
self.trial_lights_r_button = QtWidgets.QPushButton()
self.trial_lights_l_button = QtWidgets.QPushButton()
self.trial_lights_rb_button = QtWidgets.QPushButton()
self.trial_lights_lb_button = QtWidgets.QPushButton()
# get the settings
self.get_trial_lights_settings()
# add the buttons to the layout
lights_tab_layout.addRow("Accept Side trial Pattern", self.trial_lights_r_pattern_button)
lights_tab_layout.addRow("Accept Side trial Lights Color", self.trial_lights_r_button)
lights_tab_layout.addRow("Accept Side trial Lights Background Color", self.trial_lights_rb_button)
lights_tab_layout.addRow("Reject Side trial Pattern", self.trial_lights_l_pattern_button)
lights_tab_layout.addRow("Reject Side trial Lights Color", self.trial_lights_l_button)
lights_tab_layout.addRow("Reject Side trial Lights Background Color", self.trial_lights_lb_button)
# connect the slots
self.trial_lights_r_button.clicked.connect(lambda: self.color_select_slot("trial_lights", "right_side_color",
"right_side_sat", "right_side_bright"
, self.trial_lights_r_button))
self.trial_lights_rb_button.clicked.connect(lambda: self.color_select_slot("trial_lights", "right_back_color",
"right_back_sat", "right_back_bright"
, self.trial_lights_rb_button))
self.trial_lights_l_button.clicked.connect(lambda: self.color_select_slot("trial_lights", "left_side_color",
"left_side_sat", "left_side_bright",
self.trial_lights_l_button))
self.trial_lights_lb_button.clicked.connect(lambda: self.color_select_slot("trial_lights", "left_back_color",
"left_back_sat", "left_back_bright",
self.trial_lights_lb_button))
self.trial_lights_r_pattern_button.currentIndexChanged.connect(lambda: self.pattern_select_slot(
"trial_lights", "right_pattern", self.trial_lights_r_pattern_button.currentIndex()))
self.trial_lights_l_pattern_button.currentIndexChanged.connect(lambda: self.pattern_select_slot(
"trial_lights", "left_pattern", self.trial_lights_l_pattern_button.currentIndex()))
# #################START LIGHTS ################################################################################
#make the buttons
self.start_lights_r_pattern_button = QtWidgets.QComboBox()
self.start_lights_r_pattern_button.insertItems(0, self.pattern_list)
self.start_lights_l_pattern_button = QtWidgets.QComboBox()
self.start_lights_l_pattern_button.insertItems(0, self.pattern_list)
self.start_lights_r_button = QtWidgets.QPushButton()
self.start_lights_l_button = QtWidgets.QPushButton()
self.start_lights_rb_button = QtWidgets.QPushButton()
self.start_lights_lb_button = QtWidgets.QPushButton()
self.get_start_lights_settings()
# add the buttons to the layout
lights_tab_layout.addRow("Right Side start Pattern", self.start_lights_r_pattern_button)
lights_tab_layout.addRow("Right Side start Lights Color", self.start_lights_r_button)
lights_tab_layout.addRow("Right Side start Lights Background Color", self.start_lights_rb_button)
lights_tab_layout.addRow("Left Side start Pattern", self.start_lights_l_pattern_button)
lights_tab_layout.addRow("Left Side start Lights Color", self.start_lights_l_button)
lights_tab_layout.addRow("Left Side start Lights Background Color", self.start_lights_lb_button)
# connect the slots
self.start_lights_r_button.clicked.connect(lambda: self.color_select_slot("start_lights", "right_side_color",
"right_side_sat", "right_side_bright"
, self.start_lights_r_button))
self.start_lights_rb_button.clicked.connect(lambda: self.color_select_slot("start_lights", "right_back_color",
"right_back_sat",
"right_back_bright",
self.start_lights_rb_button))
self.start_lights_l_button.clicked.connect(lambda: self.color_select_slot("start_lights", "left_side_color",
"left_side_sat", "left_side_bright"
, self.start_lights_l_button))
self.start_lights_lb_button.clicked.connect(lambda: self.color_select_slot("start_lights", "left_back_color",
"left_back_sat", "left_back_bright"
, self.start_lights_lb_button))
self.start_lights_r_pattern_button.currentIndexChanged.connect(lambda: self.pattern_select_slot(
"start_lights", "right_pattern", self.start_lights_r_pattern_button.currentIndex()))
self.start_lights_l_pattern_button.currentIndexChanged.connect(lambda: self.pattern_select_slot(
"start_lights", "left_pattern", self.start_lights_l_pattern_button.currentIndex()))
# Update button
lights_tab_layout2 = QtWidgets.QFormLayout()
self.light_update_button = QtWidgets.QPushButton("UPDATE BOX" + str(self.box_id))
lights_tab_layout2.addRow("Save Settings", self.light_update_button)
self.light_update_button.clicked.connect(self.update_settings_slot)
# layouts
holder_layout = QtWidgets.QVBoxLayout()
holder_layout.addLayout(lights_tab_layout)
holder_layout.addSpacing(10)
bottom_layout = QtWidgets.QHBoxLayout()
bottom_layout.addSpacing(260)
bottom_layout.addLayout(lights_tab_layout2)
holder_layout.addLayout(bottom_layout)
holder_layout.addSpacing(10)
lights_tab_layout.setHorizontalSpacing(50)
lights_tab_layout.setVerticalSpacing(10)
lights_tab_layout2.setHorizontalSpacing(100)
lights_tab_layout2.setVerticalSpacing(10)
lights_tab_widget.setLayout(holder_layout)
# Lighting slots
def get_settle_lights_settings(self):
# patterns
self.settle_lights_r_pattern_button.setCurrentIndex(self.settings.value("lights/settle_lights/box_id_" +
str(self.box_id) + "right_pattern", int)
)
self.settle_lights_l_pattern_button.setCurrentIndex(self.settings.value("lights/settle_lights/box_id_" +
str(self.box_id) + "left_pattern", int))
# make the custom colors from the saved settings
self.settle_lights_r_color = QtGui.QColor()
self.settle_lights_l_color = QtGui.QColor()
self.settle_lights_rb_color = QtGui.QColor()
self.settle_lights_lb_color = QtGui.QColor()
# set the colors to the buttons
self.settle_lights_r_color.setHsv(self.settings.value("lights/settle_lights/box_id_" + str(self.box_id) +
"right_side_color", int),
self.settings.value(("lights/settle_lights/box_id_" + str(self.box_id) +
"right_side_sat"), int), self.settings.value((
"lights/settle_lights/box_id_" + str(self.box_id) +
"right_side_bright"), int))
self.settle_lights_rb_color.setHsv(self.settings.value("lights/settle_lights/box_id_" + str(self.box_id) +
"right_back_color", int), self.settings.value(
("lights/settle_lights/box_id_" + str(self.box_id) + "right_back_sat"), int), self.settings.value(
("lights/settle_lights/box_id_" + str(self.box_id) + "right_back_bright"), int))
self.settle_lights_l_color.setHsv(self.settings.value("lights/settle_lights/box_id_" + str(self.box_id) +
"left_side_color", int),
self.settings.value(("lights/settle_lights/box_id_" + str(self.box_id) +
"left_side_sat"), int), self.settings.value(
("lights/settle_lights/box_id_" + str(self.box_id) + "left_side_bright"), int))
self.settle_lights_lb_color.setHsv(self.settings.value("lights/settle_lights/box_id_" + str(self.box_id) +
"left_back_color", int), self.settings.value(
("lights/settle_lights/box_id_" + str(self.box_id) + "left_back_sat"), int), self.settings.value(
("lights/settle_lights/box_id_" + str(self.box_id) + "left_back_bright"), int))
# style
self.settle_lights_r_button.setStyleSheet("QWidget { background-color: %s}" % self.settle_lights_r_color.name())
self.settle_lights_rb_button.setStyleSheet(
"QWidget { background-color: %s}" % self.settle_lights_rb_color.name())
self.settle_lights_l_button.setStyleSheet("QWidget { background-color: %s}" % self.settle_lights_l_color.name())
self.settle_lights_lb_button.setStyleSheet(
"QWidget { background-color: %s}" % self.settle_lights_lb_color.name())
def get_trial_lights_settings(self):
# make the custom colors from the saved settings
self.trial_lights_r_color = QtGui.QColor()
self.trial_lights_l_color = QtGui.QColor()
self.trial_lights_rb_color = QtGui.QColor()
self.trial_lights_lb_color = QtGui.QColor()
#Patterns
self.trial_lights_r_pattern_button.setCurrentIndex(self.settings.value("lights/trial_lights/box_id_" +
str(self.box_id) + "right_pattern", int)
)
self.trial_lights_l_pattern_button.setCurrentIndex(self.settings.value("lights/trial_lights/box_id_" +
str(self.box_id) + "left_pattern", int))
self.trial_lights_r_color.setHsv(self.settings.value("lights/trial_lights/box_id_" + str(self.box_id) +
"right_side_color", int),
self.settings.value(("lights/trial_lights/box_id_" + str(self.box_id) +
"right_side_sat"), int), self.settings.value((
"lights/trial_lights/box_id_" + str(self.box_id) +
"right_side_bright"), int))
self.trial_lights_rb_color.setHsv(self.settings.value("lights/trial_lights/box_id_" + str(self.box_id) +
"right_back_color", int), self.settings.value(
("lights/trial_lights/box_id_" + str(self.box_id) + "right_back_sat"), int), self.settings.value(
("lights/trial_lights/box_id_" + str(self.box_id) + "right_back_bright"), int))
self.trial_lights_l_color.setHsv(self.settings.value("lights/trial_lights/box_id_" + str(self.box_id) +
"left_side_color", int),
self.settings.value(("lights/trial_lights/box_id_" + str(self.box_id) +
"left_side_sat"), int), self.settings.value(
("lights/trial_lights/box_id_" + str(self.box_id) + "left_side_bright"), int))
self.trial_lights_lb_color.setHsv(self.settings.value("lights/trial_lights/box_id_" + str(self.box_id) +
"left_back_color", int), self.settings.value(
("lights/trial_lights/box_id_" + str(self.box_id) + "left_back_sat"), int), self.settings.value(
("lights/trial_lights/box_id_" + str(self.box_id) + "left_back_bright"), int))
# style
self.trial_lights_r_button.setStyleSheet("QWidget { background-color: %s}" % self.trial_lights_r_color.name())
self.trial_lights_rb_button.setStyleSheet("QWidget { background-color: %s}" % self.trial_lights_rb_color.name())
self.trial_lights_l_button.setStyleSheet("QWidget { background-color: %s}" % self.trial_lights_l_color.name())
self.trial_lights_lb_button.setStyleSheet("QWidget { background-color: %s}" % self.trial_lights_lb_color.name())
def get_start_lights_settings(self):
# make the custom colors from the saved settings
self.start_lights_r_color = QtGui.QColor()
self.start_lights_l_color = QtGui.QColor()
self.start_lights_rb_color = QtGui.QColor()
self.start_lights_lb_color = QtGui.QColor()
self.start_lights_r_pattern_button.setCurrentIndex(self.settings.value("lights/start_lights/box_id_" +
str(self.box_id) + "right_pattern", int))
self.start_lights_l_pattern_button.setCurrentIndex(self.settings.value("lights/start_lights/box_id_" +
str(self.box_id) + "left_pattern", int))
self.start_lights_r_color.setHsv(self.settings.value("lights/start_lights/box_id_" + str(self.box_id) +
"right_side_color", int),
self.settings.value(("lights/start_lights/box_id_" + str(self.box_id) +
"right_side_sat"), int), self.settings.value((
"lights/start_lights/box_id_" + str(self.box_id) +
"right_side_bright"), int))
self.start_lights_rb_color.setHsv(self.settings.value("lights/start_lights/box_id_" + str(self.box_id) +
"right_back_color", int), self.settings.value(
("lights/start_lights/box_id_" + str(self.box_id) + "right_back_sat"), int), self.settings.value(
("lights/start_lights/box_id_" + str(self.box_id) + "right_back_bright"), int))
self.start_lights_l_color.setHsv(self.settings.value("lights/start_lights/box_id_" + str(self.box_id) +
"left_side_color", int),
self.settings.value(("lights/start_lights/box_id_" + str(self.box_id) +
"left_side_sat"), int), self.settings.value(
("lights/start_lights/box_id_" + str(self.box_id) + "left_side_bright"), int))
self.start_lights_lb_color.setHsv(self.settings.value("lights/start_lights/box_id_" + str(self.box_id) +
"left_back_color", int), self.settings.value(
("lights/start_lights/box_id_" + str(self.box_id) + "left_back_sat"), int), self.settings.value(
("lights/start_lights/box_id_" + str(self.box_id) + "left_back_bright"), int))
# style
self.start_lights_r_button.setStyleSheet("QWidget { background-color: %s}" % self.start_lights_r_color.name())
self.start_lights_rb_button.setStyleSheet("QWidget { background-color: %s}" % self.start_lights_rb_color.name())
self.start_lights_l_button.setStyleSheet("QWidget { background-color: %s}" % self.start_lights_l_color.name())
self.start_lights_lb_button.setStyleSheet("QWidget { background-color: %s}" % self.start_lights_lb_color.name())
# This function selects the color and updates the GUI
def color_select_slot(self, lights, hue, sat, val, button):
self.settings_flag = True
temp_colorbox = QtWidgets.QColorDialog()
temp_color = temp_colorbox.getColor()
button.setStyleSheet("QWidget { background-color: %s}" % temp_color.name())
temp = temp_color.getHsv()
self.settings.setValue(("lights/" + lights + "/box_id_" + str(self.box_id) + hue + ""), int(temp[0]))
self.settings.setValue(("lights/" + lights + "/box_id_" + str(self.box_id) + sat + ""), int(temp[1]))
self.settings.setValue(("lights/" + lights + "/box_id_" + str(self.box_id) + val + ""), int(temp[2]))
# Select a pattern
def pattern_select_slot(self, lights, pat, button):
self.settings_flag = True
self.settings.setValue(("lights/" + lights + "/box_id_" + str(self.box_id) + pat + ""),
button)
########################################################################################################################
# Build the Control Tab #
########################################################################################################################
def make_control_tab(self, parent):
# Setting the layout
control_tab_widget = QtWidgets.QWidget(parent)
self.box_tab_widget.addTab(control_tab_widget, "Control " + str(self.box_id))
control_form_layout = QtWidgets.QFormLayout()
control_form_layout2 = QtWidgets.QFormLayout()
control_box_layout = QtWidgets.QVBoxLayout()
# Creating the button instances
self.current_state_show = QtWidgets.QLabel()
self.current_state_show.setText(str(self.current_state_label))
self.control_id_box = QtWidgets.QTextEdit()
self.concentrate_box = QtWidgets.QTextEdit()
self.control_id_box.setText(self.settings.value(("control_number/box_id_" + str(self.box_id))))
self.concentrate_box = QtWidgets.QTextEdit()
self.concentrate_box.setText(self.settings.value("concentrate/box_id_" + str(self.box_id)))
self.gender_box = QtWidgets.QComboBox()
self.gender_box.addItem("Female")
self.gender_box.addItem("Male")
self.gender_box.addItem("N/A")
self.fish_gender = self.settings.value("boxes/box_id_" + str(self.box_id) + "/gender")
if self.fish_gender == "Female":
self.gender_box.setCurrentIndex(0)
elif self.fish_gender == "Male":
self.gender_box.setCurrentIndex(1)
if self.fish_gender == "N/A":
self.gender_box.setCurrentIndex(2)
control_start_button = QtWidgets.QPushButton("Start Box " + str(self.box_id))
control_start_all_button = QtWidgets.QPushButton("Start All")
control_start_group_button = QtWidgets.QPushButton("Update Box" + str(self.box_id))
control_abort_button = QtWidgets.QPushButton("Abort Box " + str(self.box_id))
control_abort_all_button = QtWidgets.QPushButton("Abort All")
# Adding the buttons to the layout
control_form_layout.addRow("Current Status: ", self.current_state_show)
control_form_layout.addRow("Treatment", self.control_id_box)
control_form_layout.addRow("Concentration", self.concentrate_box)
control_form_layout.addRow("Gender", self.gender_box)
control_form_layout2.addRow("Start Box " + str(self.box_id), control_start_button)
control_form_layout2.addRow("Start All", control_start_all_button)
control_form_layout2.addRow("Abort", control_abort_button)
control_form_layout2.addRow("Abort All", control_abort_all_button)
control_form_layout2.addRow("Update Box " + str(self.box_id), control_start_group_button)
# slots
self.control_id_box.textChanged.connect(self.control_id_slot)
self.concentrate_box.textChanged.connect(self.concentrate_slot)
self.gender_box.activated[str].connect(self.gender_box_slot)
control_start_button.clicked.connect(self.button_one_slot)
control_start_all_button.clicked.connect(self.button_two_slot)
control_start_group_button.clicked.connect(self.update_settings_slot)
control_abort_button.clicked.connect(self.button_four_slot)
control_abort_all_button.clicked.connect(self.abort_all_slot)
control_form_layout.setHorizontalSpacing(100)
control_form_layout.setVerticalSpacing(50)
control_form_layout2.setHorizontalSpacing(110)
control_form_layout2.setVerticalSpacing(30)
dumb_button = QtWidgets.QPushButton()
holder_layout = QtWidgets.QVBoxLayout()
smaller_holder = QtWidgets.QVBoxLayout()
horz_holder = QtWidgets.QHBoxLayout()
smaller_holder.addLayout(control_form_layout)
smaller_holder.addSpacing(50)
horz_holder.addSpacing(260)
horz_holder.addLayout(control_form_layout2)
control_box_layout.addWidget(dumb_button)
holder_layout.addLayout(smaller_holder)
holder_layout.addLayout(horz_holder)
control_tab_widget.setLayout(holder_layout)
dumb_button.hide()
# control slots
def control_id_slot(self):
self.settings_flag = True
self.settings.setValue(("control_number/box_id_" + str(self.box_id)), self.control_id_box.toPlainText())
def concentrate_slot(self):
self.settings_flag = True
self.settings.setValue(("concentrate/box_id_" + str(self.box_id)), self.concentrate_box.toPlainText())
def gender_box_slot(self):
self.settings_flag = True
self.settings.setValue("boxes/box_id_" + str(self.box_id) + "/gender", self.gender_box.currentText())
def update_status_label(self, status):
self.current_state_label = self.current_state_strings[status]
self.current_state_show.setText(self.current_state_label)
def button_one_slot(self):
# Start this box, if settings are ready
if self.settings_flag:
msg = QtWidgets.QMessageBox()
msg.setInformativeText("Please update Shuttlebox " + str(self.box_id) + " before starting.")
msg.setStandardButtons(QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel)
msg.setModal(True)
msg.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
msg.exec()
else:
if self.current_state != 0:
m = QtWidgets.QMessageBox()
m.setInformativeText("Error: Cannot update Shuttlebox while trial is running.")
m.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
m.setModal(True)
m.exec()
elif str(self.settings.value("control_number/box_id_" + str(self.box_id))) == "ENTER TREATMENT":
msg = QtWidgets.QMessageBox()
msg.setInformativeText("Please enter a treatment ID.")
msg.setStandardButtons(QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel)
msg.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
msg.setModal(True)
msg.exec()
elif str(self.settings.value("concentrate/box_id_" + str(self.box_id))) == "ENTER CONCENTRATE":
msg = QtWidgets.QMessageBox()
msg.setInformativeText("Please enter a concentration.")
msg.setStandardButtons(QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel)
msg.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
msg.setModal(True)
msg.exec()
else:
self.box_handler.send_data_init(self.box_id)
self.send_to_box(self.box_id)
self.send_to_box(",")
self.send_to_box("250")
print("Start pushed")
BoxHandler.on_box_start(self.box_handler, self.box_id)
self.msleep(50)
def button_two_slot(self):
# Signal all the boxes to start via the BoxHandler
BoxHandler.start_all_boxes_manager = True
BoxHandler.start_all_boxes(self.box_handler)
print("Start all signal pushed from box: ", self.box_id)
def abort_all_slot(self):
# Signal all the boxes to abort via the BoxHandler
BoxHandler.abort_all_boxes_manager = True
BoxHandler.abort_all(self.box_handler)
def button_four_slot(self):
# abort this box
self.send_to_box(self.box_id)
self.send_to_box(",")
self.send_to_box("255")
print("Abort pushed")
BoxHandler.on_box_abort(self.box_handler, self.box_id, self.current_state_label)
self.msleep(50)
def on_start_all_boxes(self):
# This runs after getting the signal from BoxHandler to start all boxes (can be called from same thread)
print("on start all from box" + str(self.box_id))
# ##############################################RESTORE THIS SECTION BEFORE LAUNCH#######################
self.button_one_slot()
def on_abort_all_boxes(self):
# This runs after getting the signal from BoxHandler to abort all boxes (can be called from same thread)
print("abort all from " + str(self.box_id))
self.button_four_slot()
def on_stop_all_threads_slot(self):
self.should_run = False