-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparam_window.py
More file actions
executable file
·1194 lines (972 loc) · 55 KB
/
param_window.py
File metadata and controls
executable file
·1194 lines (972 loc) · 55 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
992
993
994
995
996
997
998
999
1000
import clr
clr.AddReference("System.Windows.Forms")
clr.AddReference("System.Drawing")
from System import Array
from System.Windows.Forms import Application, Form, Panel, TableLayoutPanel, FlowLayoutPanel, ControlStyles
from System.Windows.Forms import Button, Label, Control, ComboBox, TextBox, TrackBar, CheckBox, ToolTip
from System.Windows.Forms import AnchorStyles, DockStyle, FlowDirection, BorderStyle, ComboBoxStyle, Padding, FormBorderStyle, FormStartPosition, DialogResult
from System.Drawing import Color, Size, Font, FontStyle, Icon, SystemFonts, FontFamily, ContentAlignment
from name_dialog import ExperimentNameDialog, ConfigNameDialog
from stim_dialog import StimDialog
from ttl_dialog import TTLDialog
from confirmation_dialog import ConfirmationDialog
import time
import threading
# import shared constants & helper functions
from shared import *
class ParamWindow(Form):
'''
Parameter window class.
This is the main window that is opened.
'''
def __init__(self, controller):
# set controller
self.controller = controller
self.tooltip = ToolTip()
# initialize invalid params label
self.invalid_params_label = None
# initialize total time label
self.total_time_label = None
# set window details
self.Text = 'Parameters'
self.StartPosition = FormStartPosition.Manual
self.FormBorderStyle = FormBorderStyle.FixedSingle
self.Top = 30
self.Left = 30
self.AutoSize = True
self.closing = False
# create dialogs
self.experiment_name_dialog = ExperimentNameDialog()
self.config_name_dialog = ConfigNameDialog()
self.stim_dialog = StimDialog()
self.TTL_dialog = TTLDialog()
self.confirmation_dialog = ConfirmationDialog()
# add & populate stim list panel
self.add_stim_list_panel()
self.populate_stim_list_panel()
# add & populate config button panel
self.add_config_button_panel()
self.populate_config_button_panel()
# add & populate config choice panel
self.add_config_choice_panel()
self.populate_config_choice_panel()
# add & populate exp param panel
self.add_exp_param_panel()
self.populate_exp_param_panel()
# add exp choice panel
self.add_exp_choice_panel()
# add save button panel
self.add_save_button_panel()
Application.EnableVisualStyles()
def add_exp_choice_panel(self):
# add exp button panel
self.exp_button_panel = FlowLayoutPanel()
self.exp_button_panel.Parent = self
self.exp_button_panel.BackColor = BUTTON_PANEL_COLOR
self.exp_button_panel.Padding = Padding(10, 0, 10, 10)
self.exp_button_panel.Dock = DockStyle.Top
self.exp_button_panel.FlowDirection = FlowDirection.LeftToRight
self.exp_button_panel.WrapContents = False
self.exp_button_panel.AutoSize = True
self.exp_button_panel.Font = BODY_FONT
# add new exp button
new_exp_button = Button()
new_exp_button.Parent = self.exp_button_panel
new_exp_button.Text = "New"
new_exp_button.AutoSize = True
new_exp_button.Click += self.add_new_experiment
new_exp_button.BackColor = BUTTON_COLOR
# add remove exp button
self.remove_exp_button = Button()
self.remove_exp_button.Parent = self.exp_button_panel
self.remove_exp_button.Text = "Delete"
self.remove_exp_button.AutoSize = True
self.remove_exp_button.Click += self.remove_experiment
self.remove_exp_button.BackColor = BUTTON_COLOR
# disable remove exp button if there is only one experiment
if len(self.controller.experiments['experiments_list']) == 1:
self.remove_exp_button.Enabled = False
# add rename exp button
rename_exp_button = Button()
rename_exp_button.Parent = self.exp_button_panel
rename_exp_button.Text = "Rename"
rename_exp_button.AutoSize = True
rename_exp_button.Click += self.rename_experiment
rename_exp_button.BackColor = BUTTON_COLOR
# create exp choice panel
self.exp_choice_panel = FlowLayoutPanel()
self.exp_choice_panel.Parent = self
self.exp_choice_panel.BackColor = CHOICE_PANEL_COLOR
self.exp_choice_panel.Dock = DockStyle.Top
self.exp_choice_panel.Padding = Padding(10, 10, 0, 10)
self.exp_choice_panel.FlowDirection = FlowDirection.TopDown
self.exp_choice_panel.WrapContents = False
self.exp_choice_panel.AutoSize = True
self.exp_choice_panel.Font = BODY_FONT
# add exp choice label
exp_choice_label = Label()
exp_choice_label.Parent = self.exp_choice_panel
exp_choice_label.Text = "Experiment:"
exp_choice_label.AutoSize = True
# add exp chooser
self.exp_chooser = ComboBox()
self.exp_chooser.DropDownStyle = ComboBoxStyle.DropDownList
self.exp_chooser.Parent = self.exp_choice_panel
self.exp_chooser.Items.AddRange(Array[str](self.controller.experiments['experiments_list']))
self.exp_chooser.SelectionChangeCommitted += self.on_exp_choice
self.exp_chooser.Text = self.controller.experiments['current_experiment']
self.exp_chooser.Width = self.Width - 35
self.exp_chooser.AutoSize = True
self.exp_chooser.Font = BODY_FONT
def on_exp_choice(self, sender, event):
if self.controller.running_stim:
confirmation = self.confirmation_dialog.ShowDialog(self.controller, "Stop Current Stimulation?", "Creating a new configuration will stop the currently-running stimulation. Continue?")
else:
confirmation = True
if confirmation:
# stop any running stim
self.controller.stop_stim(ignore_troubleshooting=True)
# get new exp name
new_exp_name = self.exp_chooser.SelectedItem.ToString()
if new_exp_name != self.controller.experiments['current_experiment']:
# change experiment
self.controller.change_experiment(new_exp_name)
# refresh panels
self.exp_param_panel.Refresh()
self.config_choice_panel.Refresh()
self.config_button_panel.Refresh()
self.stim_list_panel.Refresh()
# re-populate exp param, config choice, config button & stim list panels
self.populate_exp_param_panel()
self.populate_config_choice_panel()
self.populate_config_button_panel()
self.populate_stim_list_panel()
# re-populate config chooser
self.config_chooser.Items.Clear()
self.config_chooser.Items.AddRange(Array[str](self.controller.configs['configs_list']))
self.config_chooser.Text = self.controller.configs['current_config']
# disable remove config button if there's only one config
if len(self.controller.configs['configs_list']) == 1:
self.remove_config_button.Enabled = False
def add_new_experiment(self, sender, event):
if self.controller.running_stim:
confirmation = self.confirmation_dialog.ShowDialog(self.controller, "Stop Current Stimulation?", "Creating a new experiment will stop the currently-running stimulation. Continue?")
else:
confirmation = True
if confirmation:
# stop any running stim
self.controller.stop_stim(ignore_troubleshooting=True)
# get new experiment name
new_exp_name = self.experiment_name_dialog.ShowDialog(self.controller, "Add New Experiment", "New experiment name:", "New Experiment", None)
if new_exp_name != None:
# add experiment to experiments list
self.controller.experiments['experiments_list'].append(new_exp_name)
# switch to the new experiment
self.controller.change_experiment(new_exp_name)
# add & switch to new experiment in the exp chooser
self.exp_chooser.Items.Add(new_exp_name)
self.exp_chooser.Text = self.controller.experiments['current_experiment']
# refresh panels
self.exp_param_panel.Refresh()
self.config_choice_panel.Refresh()
self.config_button_panel.Refresh()
self.stim_list_panel.Refresh()
# re-populate exp param, config choice, config button & stim list panels
self.populate_exp_param_panel()
self.populate_config_choice_panel()
self.populate_config_button_panel()
self.populate_stim_list_panel()
# enable the remove experiment button
self.remove_exp_button.Enabled = True
def remove_experiment(self, sender, event):
if self.controller.running_stim:
confirmation = self.confirmation_dialog.ShowDialog(self.controller, "Stop Current Stimulation?", "Removing this experiment will stop the currently-running stimulation. Continue?")
else:
confirmation = True
if confirmation:
# stop any running stim
self.controller.stop_stim(ignore_troubleshooting=True)
# remove experiment from experiments dict
success = self.controller.remove_experiment(self.exp_chooser.SelectedItem.ToString())
if success:
# remove experiment from exp chooser & switch to the new current experiment
self.exp_chooser.Items.Remove(self.exp_chooser.SelectedItem)
self.exp_chooser.Text = self.controller.experiments['current_experiment']
# refresh panels
self.exp_param_panel.Refresh()
self.config_choice_panel.Refresh()
self.config_button_panel.Refresh()
self.stim_list_panel.Refresh()
# re-populate exp param, config choice, config button & stim list panels
self.populate_exp_param_panel()
self.populate_config_choice_panel()
self.populate_config_button_panel()
self.populate_stim_list_panel()
# disable remove experiment button if there's only one experiment left
if len(self.controller.experiments['experiments_list']) == 1:
self.remove_exp_button.Enabled = False
def rename_experiment(self, sender, event):
# get old experiment name
old_exp_name = self.exp_chooser.SelectedItem.ToString()
# get new experiment name
new_exp_name = self.experiment_name_dialog.ShowDialog(self.controller, "Rename experiment","New experiment name:", old_exp_name, self.controller.experiments['experiments_list'].index(old_exp_name))
if new_exp_name != None:
# rename the experiment
success = self.controller.rename_experiment(old_exp_name, new_exp_name)
if success:
# rename the experiment in the exp chooser
exp_index = self.exp_chooser.Items.IndexOf(old_exp_name)
self.exp_chooser.Items.Item[exp_index] = new_exp_name
self.exp_chooser.Text = self.controller.experiments['current_experiment']
def add_exp_param_panel(self):
# create exp param panel
self.exp_param_panel = FlowLayoutPanel()
self.exp_param_panel.Parent = self
self.exp_param_panel.BackColor = PARAM_PANEL_COLOR
self.exp_param_panel.Dock = DockStyle.Top
self.exp_param_panel.Padding = Padding(5)
self.exp_param_panel.FlowDirection = FlowDirection.LeftToRight
self.exp_param_panel.WrapContents = True
# self.exp_param_panel.Height = 250
self.exp_param_panel.AutoSize = True
self.exp_param_panel.Font = BODY_FONT
def populate_exp_param_panel(self):
# initialize exp param textboxes, sliders & slider labels dicts
self.exp_param_textboxes = {}
self.exp_param_sliders = {}
self.exp_param_checkboxes = {}
self.exp_param_slider_labels = {}
# empty exp param panel
list_of_controls = self.exp_param_panel.Controls
for control in list_of_controls:
control.Dispose()
self.exp_param_panel.Controls.Clear()
# add exp param heading label
# add_heading_label("Experiment Parameters", self.exp_param_panel)
# add exp params
self.add_exp_param_to_window('screen_cm_width', 'Projection width (cm)')
self.add_exp_param_to_window('screen_px_width', 'Projection width (px)')
self.add_exp_param_checkbox_to_window('warp_perspective', 'Cylindrical projection')
self.add_exp_param_to_window('dish_radius', 'Dish radius (cm)')
self.add_exp_param_slider_to_window('width', 'Viewport width', 1, 100)
self.add_exp_param_slider_to_window('height', 'Viewport height', 1, 100)
# # add filler subpanel
# exp_param_subpanel = FlowLayoutPanel()
# exp_param_subpanel.Parent = self.exp_param_panel
# exp_param_subpanel.BackColor = PARAM_PANEL_COLOR
# exp_param_subpanel.Dock = DockStyle.Bottom
# exp_param_subpanel.Padding = Padding(0)
# exp_param_subpanel.FlowDirection = FlowDirection.TopDown
# exp_param_subpanel.WrapContents = False
# exp_param_subpanel.Width = int(self.Width/3) - 20
# exp_param_subpanel.Height = 50
# # exp_param_subpanel.AutoSize = True
# exp_param_subpanel.Font = BODY_FONT
self.add_exp_param_slider_to_window('x_offset', 'Viewport x offset', 0, 100)
self.add_exp_param_slider_to_window('y_offset', 'Viewport y offset', 0, 100)
def add_exp_param_to_window(self, name, label_text, tooltip=None):
# create exp param panel
exp_param_subpanel = FlowLayoutPanel()
exp_param_subpanel.Parent = self.exp_param_panel
exp_param_subpanel.BackColor = PARAM_PANEL_COLOR
exp_param_subpanel.Dock = DockStyle.Bottom
exp_param_subpanel.Padding = Padding(0)
exp_param_subpanel.FlowDirection = FlowDirection.TopDown
exp_param_subpanel.WrapContents = False
exp_param_subpanel.Width = int(self.Width/3) - 15
exp_param_subpanel.Height = 50
# exp_param_subpanel.AutoSize = True
exp_param_subpanel.Font = BODY_FONT
# add param label
label = Label()
label.Parent = exp_param_subpanel
label.Text = label_text + ":"
label.AutoSize = True
label.Font = BODY_FONT
label.Margin = Padding(0, 5, 0, 0)
label.Width = exp_param_subpanel.Width
# add param textbox
self.exp_param_textboxes[name] = TextBox()
self.exp_param_textboxes[name].Parent = exp_param_subpanel
self.exp_param_textboxes[name].Text = str(self.controller.experiment_params[name])
self.exp_param_textboxes[name].Width = int(self.Width/3) - 20
self.exp_param_textboxes[name].BackColor = BUTTON_PANEL_COLOR
self.exp_param_textboxes[name].Font = BODY_FONT
if tooltip is not None:
self.tooltip.SetToolTip(label, tooltip)
def add_exp_param_slider_to_window(self, name, label_text, min, max):
# create exp param panel
exp_param_subpanel = FlowLayoutPanel()
exp_param_subpanel.Parent = self.exp_param_panel
exp_param_subpanel.BackColor = PARAM_PANEL_COLOR
exp_param_subpanel.Dock = DockStyle.Bottom
exp_param_subpanel.Padding = Padding(0)
exp_param_subpanel.FlowDirection = FlowDirection.TopDown
exp_param_subpanel.WrapContents = False
exp_param_subpanel.Width = int(self.Width/3) - 15
exp_param_subpanel.Height = 50
# exp_param_subpanel.AutoSize = True
exp_param_subpanel.Font = BODY_FONT
# add param label
self.exp_param_slider_labels[name] = Label()
self.exp_param_slider_labels[name].Parent = exp_param_subpanel
self.exp_param_slider_labels[name].Text = label_text + ": " + str(self.controller.experiment_params[name])
self.exp_param_slider_labels[name].AutoSize = True
self.exp_param_slider_labels[name].Font = BODY_FONT
self.exp_param_slider_labels[name].Margin = Padding(0, 5, 0, 0)
self.exp_param_slider_labels[name].Name = label_text
# add param slider
self.exp_param_sliders[name] = TrackBar()
self.exp_param_sliders[name].Parent = exp_param_subpanel
self.exp_param_sliders[name].Minimum = min
self.exp_param_sliders[name].Maximum = max
self.exp_param_sliders[name].Value = float(self.controller.experiment_params[name])*100.0
self.exp_param_sliders[name].Width = int(self.Width/3) - 20
self.exp_param_sliders[name].Name = name
self.exp_param_sliders[name].TickFrequency = 100
self.exp_param_sliders[name].Scroll += self.on_slider_scroll
def add_exp_param_checkbox_to_window(self, name, label_text):
# create exp param panel
exp_param_subpanel = FlowLayoutPanel()
exp_param_subpanel.Parent = self.exp_param_panel
exp_param_subpanel.BackColor = PARAM_PANEL_COLOR
exp_param_subpanel.Dock = DockStyle.Bottom
exp_param_subpanel.Padding = Padding(0)
exp_param_subpanel.FlowDirection = FlowDirection.TopDown
exp_param_subpanel.WrapContents = False
exp_param_subpanel.Width = int(self.Width/3) - 15
exp_param_subpanel.Height = 50
# exp_param_subpanel.AutoSize = True
exp_param_subpanel.Font = BODY_FONT
self.exp_param_checkboxes[name] = CheckBox()
self.exp_param_checkboxes[name].Parent = exp_param_subpanel
self.exp_param_checkboxes[name].Checked = bool(self.controller.experiment_params[name])
self.exp_param_checkboxes[name].CheckedChanged += self.on_checkbox_click
self.exp_param_checkboxes[name].Text = label_text
self.exp_param_checkboxes[name].Width = int(self.Width/3) - 20
self.exp_param_checkboxes[name].Name = name
self.exp_param_checkboxes[name].AutoSize = True
def on_slider_scroll(self, sender, event):
self.exp_param_slider_labels[sender.Name].Text = self.exp_param_slider_labels[sender.Name].Name + ": " + str(sender.Value/100.0)
# update stim window's params
if self.controller.stim_window:
if self.controller.running_stim:
confirmation = self.confirmation_dialog.ShowDialog(self.controller, "Stop Current Stimulation?", "Changing experiment paremeters will stop the currently-running stimulation. Continue?")
else:
confirmation = True
if confirmation:
# stop any running stim
self.controller.stop_stim(ignore_troubleshooting=True)
self.controller.experiment_params[sender.Name] = sender.Value/100.0
self.controller.save_experiment_params()
self.controller.stim_window.update_params()
def on_checkbox_click(self, sender, event):
# update stim window's params
if self.controller.stim_window:
if self.controller.running_stim:
confirmation = self.confirmation_dialog.ShowDialog(self.controller, "Stop Current Stimulation?", "Changing experiment paremeters will stop the currently-running stimulation. Continue?")
else:
confirmation = True
if confirmation:
# stop any running stim
self.controller.stop_stim(ignore_troubleshooting=True)
self.controller.experiment_params[sender.Name] = int(sender.Checked)
self.controller.save_experiment_params()
self.controller.stim_window.update_params()
def add_config_choice_panel(self):
# create config choice panel
self.config_choice_panel = FlowLayoutPanel()
self.config_choice_panel.Parent = self
self.config_choice_panel.BackColor = CHOICE_PANEL_COLOR
self.config_choice_panel.Dock = DockStyle.Top
self.config_choice_panel.Padding = Padding(10, 10, 0, 10)
self.config_choice_panel.FlowDirection = FlowDirection.TopDown
self.config_choice_panel.WrapContents = False
self.config_choice_panel.AutoSize = True
self.config_choice_panel.Font = BODY_FONT
def populate_config_choice_panel(self):
# empty config choice panel
list_of_controls = self.config_choice_panel.Controls
for control in list_of_controls:
control.Dispose()
self.config_choice_panel.Controls.Clear()
# add config choice label
config_choice_label = Label()
config_choice_label.Parent = self.config_choice_panel
config_choice_label.Text = "Config:"
config_choice_label.AutoSize = True
# add config chooser
self.config_chooser = ComboBox()
self.config_chooser.DropDownStyle = ComboBoxStyle.DropDownList
self.config_chooser.Parent = self.config_choice_panel
self.config_chooser.Items.AddRange(Array[str](self.controller.configs['configs_list']))
self.config_chooser.SelectionChangeCommitted += self.on_config_choice
self.config_chooser.Text = self.controller.configs['current_config']
self.config_chooser.Width = self.Width - 35
self.config_chooser.AutoSize = True
self.config_chooser.Font = BODY_FONT
def on_config_choice(self, sender, event):
if self.controller.running_stim:
confirmation = self.confirmation_dialog.ShowDialog(self.controller, "Stop Current Stimulation?", "Creating a new configuration will stop the currently-running stimulation. Continue?")
else:
confirmation = True
if confirmation:
# stop any running stim
self.controller.stop_stim(ignore_troubleshooting=True)
# get new config name
new_config_name = self.config_chooser.SelectedItem.ToString()
if new_config_name != self.controller.configs['current_config']:
# refresh panel
self.stim_list_panel.Refresh()
# change config
self.controller.change_config(new_config_name)
# re-populate stim list panel
self.populate_stim_list_panel()
def add_config_button_panel(self):
# add config button panel
self.config_button_panel = FlowLayoutPanel()
self.config_button_panel.Parent = self
self.config_button_panel.BackColor = BUTTON_PANEL_COLOR
self.config_button_panel.Padding = Padding(10, 0, 10, 10)
self.config_button_panel.Dock = DockStyle.Top
self.config_button_panel.FlowDirection = FlowDirection.LeftToRight
self.config_button_panel.WrapContents = False
self.config_button_panel.AutoSize = True
self.config_button_panel.Font = BODY_FONT
def populate_config_button_panel(self):
# empty config button panel
list_of_controls = self.config_button_panel.Controls
for control in list_of_controls:
control.Dispose()
self.config_button_panel.Controls.Clear()
# add new config button
new_config_button = Button()
new_config_button.Parent = self.config_button_panel
new_config_button.Text = "New"
new_config_button.Click += self.add_new_config
new_config_button.BackColor = BUTTON_COLOR
new_config_button.AutoSize = True
# add remove config button
self.remove_config_button = Button()
self.remove_config_button.Parent = self.config_button_panel
self.remove_config_button.Text = "Delete"
self.remove_config_button.Click += self.remove_config
self.remove_config_button.BackColor = BUTTON_COLOR
self.remove_config_button.AutoSize = True
if len(self.controller.configs['configs_list']) == 1:
self.remove_config_button.Enabled = False
# add rename config button
rename_config_button = Button()
rename_config_button.Parent = self.config_button_panel
rename_config_button.Text = "Rename"
rename_config_button.Click += self.rename_config
rename_config_button.BackColor = BUTTON_COLOR
rename_config_button.AutoSize = True
def add_new_config(self, sender, event):
if self.controller.running_stim:
confirmation = self.confirmation_dialog.ShowDialog(self.controller, "Stop Current Stimulation?", "Creating a new configuration will stop the currently-running stimulation. Continue?")
else:
confirmation = True
if confirmation:
# stop any running stim
self.controller.stop_stim(ignore_troubleshooting=True)
# get new config name
new_config_name = self.config_name_dialog.ShowDialog(self.controller, "Add New Config", "New config name:", "New Config", None)
if new_config_name != None:
# add config to configs list
self.controller.configs['configs_list'].append(new_config_name)
# switch to the new config
self.controller.change_config(new_config_name)
# add & switch to new config in the exp chooser
self.config_chooser.Items.Add(new_config_name)
self.config_chooser.Text = self.controller.configs['current_config']
# refresh panel
self.stim_list_panel.Refresh()
# re-populate stim list panel
self.populate_stim_list_panel()
# enable the remove config button
self.remove_config_button.Enabled = True
list_of_controls = self.stim_list_panel.Controls
for control in list_of_controls:
index = self.stim_list_panel.Controls.IndexOf(control)
def remove_config(self, sender, event):
if self.controller.running_stim:
confirmation = self.confirmation_dialog.ShowDialog(self.controller, "Stop Current Stimulation?", "Removing this configuration will stop the currently-running stimulation. Continue?")
else:
confirmation = True
if confirmation:
# stop any running stim
self.controller.stop_stim(ignore_troubleshooting=True)
# remove config from configs dict
success = self.controller.remove_config(self.config_chooser.SelectedItem.ToString())
if success:
# remove config from exp chooser & switch to the new current config
self.config_chooser.Items.Remove(self.config_chooser.SelectedItem)
self.config_chooser.Text = self.controller.configs['current_config']
# refresh panel
self.stim_list_panel.Refresh()
# re-populate stim list panel
self.populate_stim_list_panel()
# disable remove config button if there's only one config left
if len(self.controller.configs['configs_list']) == 1:
self.remove_config_button.Enabled = False
list_of_controls = self.stim_list_panel.Controls
for control in list_of_controls:
index = self.stim_list_panel.Controls.IndexOf(control)
def rename_config(self, sender, event):
# get old config name
old_config_name = self.config_chooser.SelectedItem.ToString()
# get new config name
new_config_name = self.config_name_dialog.ShowDialog(self.controller, "Rename Config","New config name:", old_config_name, self.controller.configs['configs_list'].index(old_config_name))
if new_config_name != None:
# rename the config
success = self.controller.rename_config(old_config_name, new_config_name)
if success:
# rename the config in the exp chooser
config_index = self.config_chooser.Items.IndexOf(old_config_name)
self.config_chooser.Items.Item[config_index] = new_config_name
self.config_chooser.Text = self.controller.configs['current_config']
def add_stim_list_panel(self):
# create stim list panel
self.stim_list_panel = FlowLayoutPanel()
self.stim_list_panel.Parent = self
self.stim_list_panel.BackColor = PARAM_PANEL_COLOR
self.stim_list_panel.Dock = DockStyle.Fill
self.stim_list_panel.Padding = Padding(10)
self.stim_list_panel.FlowDirection = FlowDirection.TopDown
self.stim_list_panel.WrapContents = False
self.stim_list_panel.AutoScroll = True
# self.stim_list_panel.Width = self.Width
self.stim_list_panel.MaximumSize = Size(0, 300)
self.stim_list_panel.AutoSize = True
self.stim_list_panel.Font = BODY_FONT
def populate_stim_list_panel(self):
# stop the param window from refreshing
self.SuspendLayout()
self.stim_list_panel.Visible = False
# empty stim list panel
list_of_controls = self.stim_list_panel.Controls
for control in list_of_controls:
control.Dispose()
self.stim_list_panel.Controls.Clear()
# initialize lists of controls
self.stim_list_subpanels = []
self.stim_list_duration_labels = []
self.stim_list_name_labels = []
self.stim_list_type_labels = []
self.stim_list_edit_buttons = []
self.stim_list_delete_buttons = []
# add all stims
for i in range(len(self.controller.config_params['stim_list'])):
self.add_stim_to_stim_list_panel(i)
self.stim_list_panel.Visible = True
# allow the param window to refresh
self.ResumeLayout()
# update total time label
self.update_total_time_label()
def add_stim_to_stim_list_panel(self, i):
# create stim subpanel
subpanel = FlowLayoutPanel()
subpanel.Parent = self.stim_list_panel
subpanel.Dock = DockStyle.Left
subpanel.Padding = Padding(0)
subpanel.Margin = Padding(1, 0, 1, 1)
subpanel.FlowDirection = FlowDirection.LeftToRight
subpanel.WrapContents = False
subpanel.AutoSize = True
subpanel.Font = BODY_FONT
subpanel.Tag = i
# get stim type
stim_type = self.controller.config_params['types_list'][i]
# add edit button
edit_button = Button()
edit_button.Parent = subpanel
edit_button.Text = "Edit"
edit_button.AutoSize = True
edit_button.Click += self.edit_stim
edit_button.BackColor = BUTTON_COLOR
# add edit button to list of edit buttons
self.stim_list_edit_buttons.append(edit_button)
# add delete button
delete_button = Button()
delete_button.Parent = subpanel
delete_button.Text = "Delete"
delete_button.AutoSize = True
delete_button.Click += self.remove_stim
delete_button.BackColor = BUTTON_COLOR
# add delete button to list of delete buttons
self.stim_list_delete_buttons.append(delete_button)
# add stim name label
stim_name_label = Label()
stim_name_label.Parent = subpanel
stim_name_label.Text = self.controller.config_params['stim_list'][i]
stim_name_label.MinimumSize = Size(220, 40)
stim_name_label.MaximumSize = Size(220, 40)
stim_name_label.AutoSize = True
stim_name_label.Padding = Padding(0, 7, 0, 0)
stim_name_label.AutoEllipsis = True
# add stim name label to list of stim name labels
self.stim_list_name_labels.append(stim_name_label)
# add stim type label
stim_type_label = Label()
stim_type_label.Parent = subpanel
stim_type_label.Text = stim_type
stim_type_label.MinimumSize = Size(100, 40)
stim_type_label.MaximumSize = Size(100, 40)
stim_type_label.AutoEllipsis = True
stim_type_label.AutoSize = True
stim_type_label.Padding = Padding(0, 7, 0, 0)
# add stim type label to list of stim type labels
self.stim_list_type_labels.append(stim_type_label)
# add duration label
duration_label = Label()
duration_label.Parent = subpanel
duration_label.Text = str(self.controller.config_params['durations_list'][i]) + "s"
duration_label.MinimumSize = Size(100, 40)
duration_label.MaximumSize = Size(100, 40)
duration_label.AutoSize = True
duration_label.Padding = Padding(0, 7, 0, 0)
# add duration label to list of duration labels
self.stim_list_duration_labels.append(duration_label)
# add move up button
move_up_button = Button()
move_up_button.Parent = subpanel
move_up_button.Text = u"\u02C4"
move_up_button.MaximumSize = Size(40, 0)
move_up_button.AutoSize = True
move_up_button.Click += self.move_up_stim
move_up_button.BackColor = BUTTON_COLOR
# add move down button
move_down_button = Button()
move_down_button.Parent = subpanel
move_down_button.Text = u"\u02C5"
move_down_button.MaximumSize = Size(40, 0)
move_down_button.AutoSize = True
move_down_button.Click += self.move_down_stim
move_down_button.BackColor = BUTTON_COLOR
# add color accent
edit_button.BackColor = stim_color(stim_type)
# add subpanel to list of subpanels
self.stim_list_subpanels.append(subpanel)
def move_up_stim(self, sender, event):
if len(self.controller.config_params['stim_list']) > 0:
if self.controller.running_stim:
confirmation = self.confirmation_dialog.ShowDialog(self.controller, "Stop Current Stimulation?", "Rearranging stimulations will stop the currently-running stimulation. Continue?")
else:
confirmation = True
if confirmation:
# stop any running stim
self.controller.stop_stim(ignore_troubleshooting=True)
# get stim index
stim_index = sender.Parent.Tag
if stim_index != 0:
# rearrange subpanels
self.stim_list_panel.Controls.SetChildIndex(self.stim_list_panel.Controls[stim_index-1], stim_index)
# rearrange tags
self.stim_list_panel.Controls[stim_index-1].Tag -= 1
self.stim_list_panel.Controls[stim_index].Tag += 1
# update lists of controls
self.stim_list_subpanels[stim_index], self.stim_list_subpanels[stim_index-1] = self.stim_list_subpanels[stim_index-1], self.stim_list_subpanels[stim_index]
self.stim_list_duration_labels[stim_index], self.stim_list_duration_labels[stim_index-1] = self.stim_list_duration_labels[stim_index-1], self.stim_list_duration_labels[stim_index]
self.stim_list_name_labels[stim_index], self.stim_list_name_labels[stim_index-1] = self.stim_list_name_labels[stim_index-1], self.stim_list_name_labels[stim_index]
self.stim_list_type_labels[stim_index], self.stim_list_type_labels[stim_index-1] = self.stim_list_type_labels[stim_index-1], self.stim_list_type_labels[stim_index]
self.stim_list_edit_buttons[stim_index], self.stim_list_edit_buttons[stim_index-1] = self.stim_list_edit_buttons[stim_index-1], self.stim_list_edit_buttons[stim_index]
self.stim_list_delete_buttons[stim_index], self.stim_list_delete_buttons[stim_index-1] = self.stim_list_delete_buttons[stim_index-1], self.stim_list_delete_buttons[stim_index]
# update config params
self.controller.config_params['stim_list'][stim_index], self.controller.config_params['stim_list'][stim_index-1] = self.controller.config_params['stim_list'][stim_index-1], self.controller.config_params['stim_list'][stim_index]
self.controller.config_params['durations_list'][stim_index], self.controller.config_params['durations_list'][stim_index-1] = self.controller.config_params['durations_list'][stim_index-1], self.controller.config_params['durations_list'][stim_index]
self.controller.config_params['types_list'][stim_index], self.controller.config_params['types_list'][stim_index-1] = self.controller.config_params['types_list'][stim_index-1], self.controller.config_params['types_list'][stim_index]
self.controller.config_params['parameters_list'][stim_index], self.controller.config_params['parameters_list'][stim_index-1] = self.controller.config_params['parameters_list'][stim_index-1], self.controller.config_params['parameters_list'][stim_index]
# update stim window's params
if self.controller.stim_window:
self.controller.stim_window.update_params()
def move_down_stim(self, sender, event):
if len(self.controller.config_params['stim_list']) > 0:
if self.controller.running_stim:
confirmation = self.confirmation_dialog.ShowDialog(self.controller, "Stop Current Stimulation?", "Rearranging stimulations will stop the currently-running stimulation. Continue?")
else:
confirmation = True
if confirmation:
# stop any running stim
self.controller.stop_stim(ignore_troubleshooting=True)
# get stim index
stim_index = sender.Parent.Tag
if stim_index != self.stim_list_panel.Controls.Count - 1:
# rearrange subpanels
self.stim_list_panel.Controls.SetChildIndex(self.stim_list_panel.Controls[stim_index+1], stim_index)
# rearrange tags
self.stim_list_panel.Controls[stim_index+1].Tag += 1
self.stim_list_panel.Controls[stim_index].Tag -= 1
# update lists of controls
self.stim_list_subpanels[stim_index], self.stim_list_subpanels[stim_index+1] = self.stim_list_subpanels[stim_index+1], self.stim_list_subpanels[stim_index]
self.stim_list_duration_labels[stim_index], self.stim_list_duration_labels[stim_index+1] = self.stim_list_duration_labels[stim_index+1], self.stim_list_duration_labels[stim_index]
self.stim_list_name_labels[stim_index], self.stim_list_name_labels[stim_index+1] = self.stim_list_name_labels[stim_index+1], self.stim_list_name_labels[stim_index]
self.stim_list_type_labels[stim_index], self.stim_list_type_labels[stim_index+1] = self.stim_list_type_labels[stim_index+1], self.stim_list_type_labels[stim_index]
self.stim_list_edit_buttons[stim_index], self.stim_list_edit_buttons[stim_index+1] = self.stim_list_edit_buttons[stim_index+1], self.stim_list_edit_buttons[stim_index]
self.stim_list_delete_buttons[stim_index], self.stim_list_delete_buttons[stim_index+1] = self.stim_list_delete_buttons[stim_index+1], self.stim_list_delete_buttons[stim_index]
# update config params
self.controller.config_params['stim_list'][stim_index], self.controller.config_params['stim_list'][stim_index+1] = self.controller.config_params['stim_list'][stim_index+1], self.controller.config_params['stim_list'][stim_index]
self.controller.config_params['durations_list'][stim_index], self.controller.config_params['durations_list'][stim_index+1] = self.controller.config_params['durations_list'][stim_index+1], self.controller.config_params['durations_list'][stim_index]
self.controller.config_params['types_list'][stim_index], self.controller.config_params['types_list'][stim_index+1] = self.controller.config_params['types_list'][stim_index+1], self.controller.config_params['types_list'][stim_index]
self.controller.config_params['parameters_list'][stim_index], self.controller.config_params['parameters_list'][stim_index+1] = self.controller.config_params['parameters_list'][stim_index+1], self.controller.config_params['parameters_list'][stim_index]
# update stim window's params
if self.controller.stim_window:
self.controller.stim_window.update_params()
def remove_stim(self, sender, event):
if len(self.controller.config_params['stim_list']) > 0:
if self.controller.running_stim:
confirmation = self.confirmation_dialog.ShowDialog(self.controller, "Stop Current Stimulation?", "Removing this stimulation will stop the currently-running stimulation. Continue?")
else:
confirmation = True
if confirmation:
# stop any running stim
self.controller.stop_stim(ignore_troubleshooting=True)
# stop the param window from refreshing
self.SuspendLayout()
# get stim index
stim_index = sender.Parent.Tag
# remove stim
self.stim_list_panel.Controls.RemoveAt(stim_index)
del self.stim_list_subpanels[stim_index]
del self.stim_list_duration_labels[stim_index]
del self.stim_list_name_labels[stim_index]
del self.stim_list_type_labels[stim_index]
del self.stim_list_edit_buttons[stim_index]
del self.stim_list_delete_buttons[stim_index]
# adjust indices of remaining stims
for i in range(stim_index, len(self.stim_list_subpanels)):
self.stim_list_subpanels[i].Tag -= 1
# remove stim from experiment params
del self.controller.config_params['stim_list'][stim_index]
del self.controller.config_params['durations_list'][stim_index]
del self.controller.config_params['types_list'][stim_index]
del self.controller.config_params['parameters_list'][stim_index]
# update stim window's params
if self.controller.stim_window:
self.controller.stim_window.update_params()
# allow the param window to refresh
self.ResumeLayout()
# update total time label
self.update_total_time_label()
def edit_stim(self, sender, event):
# get stim index
stim_index = sender.Parent.Tag
# show stim dialog
success = self.stim_dialog.ShowDialog(self.controller, stim_index)
print(success)
if success:
self.controller.stop_stim(ignore_troubleshooting=True)
# stop the param window from refreshing
self.SuspendLayout()
# update stim subpanel controls
self.stim_list_name_labels[stim_index].Text = str(self.controller.config_params['stim_list'][stim_index])
self.stim_list_duration_labels[stim_index].Text = str(self.controller.config_params['durations_list'][stim_index]) + "s"
# get stim type
stim_type = self.controller.config_params['types_list'][stim_index]
# update stim type label
self.stim_list_type_labels[stim_index].Text = str(stim_type)
# add color accent
self.stim_list_edit_buttons[stim_index].BackColor = stim_color(stim_type)
# allow the param window to refresh
self.ResumeLayout()
# update total time label
self.update_total_time_label()
def add_save_button_panel(self):
# create save button panel
self.save_button_panel = FlowLayoutPanel()
self.save_button_panel.Parent = self
self.save_button_panel.BackColor = BUTTON_PANEL_COLOR
self.save_button_panel.Dock = DockStyle.Bottom
self.save_button_panel.Padding = Padding(10)
self.save_button_panel.WrapContents = False
self.save_button_panel.AutoSize = True
self.save_button_panel.Font = BODY_FONT
# add new stim button
self.add_stim_button = Button()
self.add_stim_button.Parent = self.save_button_panel
self.add_stim_button.Text = "Add Stim"
self.add_stim_button.Click += self.add_stim
self.add_stim_button.BackColor = BUTTON_COLOR
self.add_stim_button.AutoSize = True
# add save button
self.save_button = Button()
self.save_button.Parent = self.save_button_panel
self.save_button.Text = "Save"
self.save_button.Click += self.save_experiment_params
self.save_button.BackColor = BUTTON_COLOR
self.save_button.AutoSize = True
self.AcceptButton = self.save_button
# add start/stop button
self.start_stop_button = Button()
self.start_stop_button.Parent = self.save_button_panel
self.start_stop_button.Text = "Start"
self.start_stop_button.Click += self.start_stop_stim
self.start_stop_button.BackColor = BUTTON_COLOR
self.start_stop_button.AutoSize = True
# add edit TTL params button
self.ttl_button = Button()
self.ttl_button.Parent = self.save_button_panel
self.ttl_button.Text = "TTL"
self.ttl_button.Click += self.edit_TTL_params
self.ttl_button.BackColor = BUTTON_COLOR
self.ttl_button.AutoSize = True
# add troubleshooting checkbox
self.troubleshooting_checkbox = CheckBox()
self.troubleshooting_checkbox.Parent = self.save_button_panel
self.troubleshooting_checkbox.Checked = self.controller.troubleshooting