-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcs_GUI.enaml
More file actions
5494 lines (5000 loc) · 198 KB
/
cs_GUI.enaml
File metadata and controls
5494 lines (5000 loc) · 198 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
"""
author = 'Martin Lichtman'
created = 2013-04-02
modified >= 2014-04-21
cs_GUI.enaml
A GUI for the Cs experiment controller, written using the enaml toolkit for python.
"""
from __future__ import division
__author__ = 'Martin Lichtman'
import logging
logger = logging.getLogger(__name__)
from cs_errors import PauseError
from enaml.layout.api import vbox, hbox, align, horizontal, vertical, spacer, grid
from enaml.widgets.api import (MainWindow, MenuBar, Menu, Action,
Notebook, Page, Container, GroupBox, DualSlider, Slider,
Form, Label, CheckBox, SpinBox, PushButton, MPLCanvas,
MultilineField, ProgressBar, ScrollArea, Separator,
FileDialog,Window, StatusBar, StatusItem,
Stack, StackItem, ComboBox, HGroup, VGroup
)
from enaml.icon import Icon, IconImage
from enaml.image import Image
from enaml.core.declarative import d_
from enaml.core.include import Include
from enaml.stdlib.dialog_buttons import DialogButton
from enaml.stdlib.message_box import question, information
from enaml.stdlib.fields import FloatField, IntField
from enaml.core.api import Looper, Conditional
from enaml.styling import StyleSheet, Style, Setter
from enaml.validator import Validator
from atom.api import Member, Bool, Typed, observe, Callable
import threading, datetime, time, os, itertools
import numpy, itertools
from experiments import IndependentVariable
from instrument_property import ListProp
# redefine Field so that all Fields will have status_tips
from enaml.widgets.api import Field as OldField
enamldef Field(OldField):
status_tip << text
enamldef MyStyleSheet(StyleSheet):
Style:
style_class = 'invalid'
Setter:
field = 'background-color'
value = 'pink'
Setter:
field = 'border-color'
value = 'red'
Setter:
field = 'border-style'
value = 'solid'
Setter:
field = 'border-width'
value = '2'
Style:
style_class = 'valid'
enamldef RefreshableLooper(Looper): self:
"""A Looper that sends a reference of itself to the backend controller, so it can be forcibly updated using the
refresh_items() method."""
initialized::
iterable.gui = self
class MyBoolValidator(Validator):
experiment=Member()
def __init__(self,experiment):
super(MyBoolValidator,self).__init__()
self.experiment=experiment
def validate(self,text):
try:
value = self.experiment.eval_bool(text)
except:
return False
return True
class MyEnumValidator(Validator):
experiment=Member()
allowedValues=Member()
def __init__(self,experiment,allowedValues):
super(MyEnumValidator,self).__init__()
self.experiment=experiment
self.allowedValues=allowedValues
def validate(self,text):
try:
value = self.experiment.eval_general(text)
#check for parsing errors
except:
return False
#check if the value is one of the ones allowed by this particular Enum
if value not in self.allowedValues:
return False
#if we've gotten this far, all tests have passed
return True
#TODO: make these Fields have validation and able to process statements
enamldef MyIntField(Field):
"""This class exists to make an IntField that is able to be synced with a numpy array element."""
attr value
text << str(value)
text :: self.value = int(text)
enamldef MyFloatField(Field):
"""This class exists to make a FloatField that is able to be synced with a numpy array element."""
attr value
text << str(value)
text :: self.value = float(text)
enamldef MyBoolField(Field):
"""This class exists to make a BoolField (which isn't something that is available anyway),
that is able to be synced with a numpy array element."""
attr value
text << str(value)
text :: self.value = bool(text)
enamldef IndexedStack(GroupBox): indexedStack:
attr iterable=Typed(ListProp)
attr viewType #=Class(StackItem) #do we really have to declare what type? I suppose this was so that we would be okay with creating an instance
hug_height = 'strong'
hug_width = 'strong'
Container: controls:
constraints=[hbox(addButton,removeButton,combo)]
PushButton: addButton:
text='+'
constraints=[width==50,height==20]
clicked::
iterable.add()
combo.maximum=len(iterable)-1
combo.value=combo.maximum
PushButton: removeButton:
text='-'
constraints=[width==50,height==20]
clicked::
i=combo.value
if i>=0:
iterable.pop(i)
combo.maximum=len(iterable)-1
if i>1:
combo.value=i-1
else:
combo.value=0
# RefreshableComboBox: combo:
# items<<[str(i)+' '+n.description for i,n in enumerate(iterable)]
SpinBox: combo:
constraints=[width==50,height==20]
maximum<<len(iterable)-1
minimum=0
Stack: stack:
index<<combo.value
RefreshableLooper:
iterable<<indexedStack.iterable
Include:
objects=[viewType(item=loop_item)]
enamldef IndexedContainer(GroupBox):
# This is like an IndexedStack, but instead of using a stack, we just have only one object to display and we
# change what that one object is using an Include
# The attribute 'iterable' must be a ListProp. This container then provides controls to add and remove elements.
# The GUI element viewType must define 'item' which is the element of the ListProp that will be passed to it
# The attribute dynamic enables the buttons to dynamically add or remove list items
attr iterable = Typed(ListProp)
# Below is commented out because we don't actually have to declare the type.
# This was so that we would be okay with creating an instance, but it's not necessary
attr viewType # = Class(StackItem)
# The attribute static disables the buttons to dynamically add or remove list items
attr dynamic = True
hug_height = 'strong'
hug_width = 'strong'
HGroup:
#constraints=[hbox(addButton,removeButton,combo)]
Conditional:
condition = dynamic
PushButton: addButton:
text='Add'
constraints=[width==50,height==20]
clicked::
iterable.add()
combo.maximum=len(iterable)-1
combo.value=combo.maximum
PushButton: removeButton:
text='Remove'
constraints=[width==50,height==20]
clicked::
i=combo.value
if i>=0:
iterable.pop(i)
combo.maximum=len(iterable)-1
if i>1:
combo.value=i-1
else:
combo.value=0
SpinBox: combo:
constraints=[width==50,height==20]
maximum<<len(iterable)-1
minimum=0
# the actual thing to display
Conditional:
condition << ((iterable.length>0) and (combo.value >=0))
Include:
objects << [viewType(item=iterable[combo.value])]
def get_load_file_callback(experiment):
def load_file_callback(dlg):
if dlg.result == 'accepted':
try:
experiment.load(dlg.path)
except PauseError:
pass
return load_file_callback
def get_save_file_callback(experiment):
def save_file_callback(dlg):
if dlg.result == 'accepted':
try:
experiment.save(dlg.path)
except PauseError:
pass
return save_file_callback
enamldef CsMenuBar(MenuBar): menuBar:
attr experiment
attr mainWindow
Menu:
title = '&File'
Action:
text = 'Load\tCtrl+L'
triggered::
confirm_load_file(menuBar, experiment)
Action:
text = 'Save\tCtrl+S'
triggered::
dlg = FileDialog(
parent=menuBar,
title='Save As?',
mode='save_file',
path=os.path.join(experiment.setting_path,
'settings-{}.hdf5'.format(
datetime.datetime.now().strftime(
'%Y-%m-%d-%H-%M-%S'))),
callback=get_save_file_callback(
experiment),
).open()
Action:
text = 'Quit\tCtrl+Q'
triggered::
mainWindow.close()
Menu:
title = '&Experiment'
Action:
text = 'Reset and Run\tCtrl+R'
triggered::experiment.resetAndGo()
Action:
text = 'Reset'
triggered::experiment.reset()
Action:
text = 'Run/Continue\tCtrl+G'
triggered::experiment.goThread()
Menu:
title = 'Pause...'
Action:
checkable = True
text = 'After Measurement\tCtrl+M'
checked := experiment.pauseAfterMeasurement
Action:
checkable = True
text = 'After Iteration'
checked := experiment.pauseAfterIteration
Action:
checkable = True
text = 'After Error'
checked := experiment.pauseAfterError
Action:
text = 'End and Upload'
triggered::experiment.end_now()
Action:
text = 'Upload'
triggered::experiment.upload_now()
Action:
text = 'Stop\tCtrl+H'
triggered::experiment.stop()
Menu:
title = 'Evaluation'
Action:
text='Update variables throughout experiment'
triggered :: experiment.evaluateAll()
enamldef EvalProp(GroupBox):
attr prop
padding = 0
flat = True
title << prop.name
constraints = [desc.width==func.width, func.width==val.width, hbox(desc,func,val), align('v_center',desc,func,val)]
# can be made to show an error status by setting valid to false
attr valid = True
Field: desc:
text := prop.description
placeholder = 'description'
Field: func:
text := prop.function
placeholder = prop.placeholder
style_class << 'valid' if prop.valid else 'invalid'
Label: val:
# showlabel can be set False e.g. for when long strings are entered in the func Field
text << prop.valueStr if prop.showlabel else ''
enamldef MultilineProp(GroupBox):
attr prop
flat=True
title:=prop.name
constraints=[vbox(desc,hbox(func,val)),align('top',func,val)]
Field: desc:
text:=prop.description
placeholder='description'
MultilineField: func:
text:=prop.function
Label: val:
text << prop.valueStr
enamldef LabelBox(HGroup):
alias checked: box.checked
alias text: label.text
padding=0
hug_height='strong'
hug_width='strong'
align_widths = False
Label: label:
pass
CheckBox: box:
pass
enamldef CheckField(HGroup):
alias checked: box.checked
alias text: field.text
alias placeholder: field.placeholder
padding = 0
hug_height='strong'
hug_width='strong'
align_widths = False
CheckBox: box:
pass
Field: field:
pass
enamldef LabelField(VGroup):
alias label: l1.text
alias text: f1.text
alias placeholder: f1.placeholder
padding = 0
hug_height='strong'
hug_width='strong'
Label: l1:
pass
Field: f1:
pass
#class RefreshableComboBox(ComboBox):
# refresh = EnamlEvent
enamldef ExperimentPage(Window):
attr experiment
title = 'Experiment'
attr creator
closing :: creator.open_windows.pop(name)
Container:
padding = 0
style_class << 'valid' if experiment.valid else 'invalid'
ScrollArea:
style_class << 'valid' if experiment.valid else 'invalid'
Form: form:
constraints = [(midline==left)|'strong'] #,(width==parent.contents_width)|'strong']
Label: text='ROI Rows'
IntField: value := experiment.ROI_rows
Label: text='ROI Columns'
IntField: value := experiment.ROI_columns
Label: text='ROI Background Rows'
IntField: value := experiment.ROI_bg_rows
Label: text='ROI Background Columns'
IntField: value := experiment.ROI_bg_columns
Label:
text="Status:"
Label:
text<<experiment.statusStr
Label:
text='Pause after iteration'
CheckBox:
checked:=experiment.pauseAfterIteration
Label:
text='Pause after measurement'
CheckBox:
checked:=experiment.pauseAfterMeasurement
Label:
text='Pause after error'
CheckBox:
checked:=experiment.pauseAfterError
Label:
text='Reload settings after pause?'
CheckBox:
checked:=experiment.reload_settings_after_pause
Label:
text='Keep repeating same experiments automatically?'
CheckBox:
checked:=experiment.repeat_experiment_automatically
Label:
text = 'enable sounds'
CheckBox:
checked := experiment.enable_sounds
Label:
text = 'start each instrument in a separate thread'
CheckBox:
checked := experiment.enable_instrument_threads
Label: text='Save Data?'
CheckField:
checked:=experiment.saveData
text:=experiment.localDataPath
placeholder='local data path'
Label: text='Save Settings?'
CheckBox:
checked:=experiment.saveSettings
Label: text='Save separate notes.txt?'
CheckBox:
checked:=experiment.save_separate_notes
Label: text='Save 2013 style files?'
CheckBox:
checked:=experiment.save2013styleFiles
Label: text='Copy Data to Network?'
CheckField:
checked:=experiment.copyDataToNetwork
text:=experiment.networkDataPath
placeholder='network data path'
Label: text='Experiment description suffix for filename'
Field: text:=experiment.experimentDescriptionFilenameSuffix
Label: text='Measurement Timeout [s]'
FloatField: value:=experiment.measurementTimeout
Label: text='Measurements per Iteration'
IntField: value:=experiment.measurementsPerIteration
Label: text='E-mail on error/completion?'
CheckField:
checked:=experiment.willSendEmail
text:=experiment.emailAddresses
Label: text='Progress'
Label: text<<'{}%'.format(experiment.progressGUI)
Label: text='Iteration'
Label: text<<experiment.iterationStr
Label: text='Measurement'
Label: text<<experiment.measurementStr
Label: text='Good Measurements'
Label: text<<experiment.goodMeasurementsStr
Label: text='Time started'
Label: text<<experiment.timeStartedStr
Label: text='Time after last measurement'
Label: text<<experiment.currentTimeStr
Label: text='Time elapsed'
Label: text<<experiment.timeElapsedStr
Label: text='Estimated total time'
Label: text<<experiment.totalTimeStr
Label: text='Estimated time remaining'
Label: text<<experiment.timeRemainingStr
Label: text='Estimated completion time'
Label: text<<experiment.completionTimeStr
Label: text='Notes'
MultilineField:
text:=experiment.notes
enamldef VariableEntry(GroupBox):
attr indepVar
attr list_index
#hug_height = 'strong'
#hug_width = 'strong'
#constraints = [vbox(variable,optimizer1,optimizer2,values,status), align('left',variable,optimizer1,optimizer2,values,status)]
HGroup: variable:
align_widths = False
constraints = [nameCont.width==100, descCont.width==200, funcCont.width==200]
Label:
text << list_index
Field: nameCont:
text := indepVar.name
placeholder = 'name'
Field: descCont:
text := indepVar.description
placeholder = 'description'
Field: funcCont:
text := indepVar.function
placeholder = 'function'
Form:
Label:
text = 'optimize?'
CheckBox:
checked := indepVar.optimize
Form:
Label:
text = 'initial step (abs)'
FloatField:
value := indepVar.optimizer_initial_step
Form:
Label:
text = 'end tolerance (abs)'
FloatField:
value := indepVar.optimizer_end_tolerance
Form:
Label:
text = 'min'
FloatField:
value := indepVar.optimizer_min
Form:
Label:
text = 'max'
FloatField:
value := indepVar.optimizer_max
HGroup:
align_widths = False
Label: values:
text << 'values: '+indepVar.valueListStr
Label:
text << 'step: '+str(indepVar.index)+' of '+str(indepVar.steps)
Label:
text = 'current value'
Field:
text << indepVar.currentValueStr
read_only = True
enamldef IndependentVariables(Window):
attr independentVariables
attr creator
closing :: creator.open_windows.pop(name)
title = 'Independent Variables'
style_class << 'valid' if experiment.valid else 'invalid'
Container:
padding = 0
style_class << 'valid' if experiment.valid else 'invalid'
ScrollArea:
style_class << 'valid' if experiment.valid else 'invalid'
Container:
Label:
text = 'Evaluated after Constants and before Dependents. Inner loop on top.'
GroupBox:
HGroup:
SpinBox: spin0:
minimum=0
maximum << independentVariables.length
PushButton: addButton0:
text='+'
clicked::
independentVariables.add_at(spin0.value)
PushButton: removeButton0:
text='-'
clicked::
independentVariables.pop(spin0.value)
RefreshableLooper:
iterable<<independentVariables
VariableEntry:
indepVar << loop_item
list_index << str(loop_index)
enamldef Variables(Window):
attr experiment
attr creator
closing :: creator.open_windows.pop(name)
title = 'Constants and Dependent Variables'
style_class << 'valid' if experiment.valid else 'invalid'
Container:
padding = 0
style_class << 'valid' if experiment.valid else 'invalid'
ScrollArea:
style_class << 'valid' if experiment.valid else 'invalid'
Container: page:
style_class << 'valid' if experiment.valid else 'invalid'
GroupBox: variablesNotToSave:
hug_height='strong'
title='Variables Not To Save to HDF5 (comma separated)'
Field:
text:=experiment.variablesNotToSave
placeholder='scipy,numpy,x'
HGroup:
constraints = [align('top', constants, dependents), constants.width==dependents.width]
GroupBox: constants:
title='Constants (Evaluated 1st, before Independents)'
Label:
text='Define constants using python code below.'
MultilineField:
constraints = [bottom==page.contents_bottom]
text:=experiment.constantsStr
GroupBox: dependents:
title='Dependent Variables (Evaluated 3rd, after Independents)'
Label:
text='Define dependent variables using python code below.'
MultilineField:
constraints = [bottom==page.contents_bottom]
text:=experiment.dependentVariablesStr
enamldef Reports(Window):
attr experiment
attr creator
closing :: creator.open_windows.pop(name)
title = 'Reports'
style_class << 'valid' if experiment.valid else 'invalid'
Container:
padding = 0
style_class << 'valid' if experiment.valid else 'invalid'
ScrollArea:
style_class << 'valid' if experiment.valid else 'invalid'
Container:
style_class << 'valid' if experiment.valid else 'invalid'
HGroup:
GroupBox:
title = 'Constant Report'
hug_height = 'strong'
hug_width = 'strong'
constraints = [hbox(f1,lb1),align('top',f1,lb1)]
MultilineField: f1:
constraints = [height==950, width==600]
text := experiment.constantReport.function
style_class << 'valid' if experiment.constantReport.valid else 'invalid'
Label: lb1:
text << experiment.constantReport.valueStr
GroupBox:
title = 'Variable Report'
hug_height = 'strong'
hug_width = 'strong'
constraints = [hbox(f2,lb2),align('top',f2,lb2)]
MultilineField: f2:
constraints = [height==950, width==600]
text := experiment.variableReport.function
style_class << 'valid' if experiment.variableReport.valid else 'invalid'
Label: lb2:
text << experiment.variableReport.valueStr
enamldef LabViewPage(Window):
attr LabView
attr creator
closing :: creator.open_windows.pop(name)
title = 'PXI communication'
style_class << 'valid' if experiment.valid else 'invalid'
Container:
padding = 0
style_class << 'valid' if experiment.valid else 'invalid'
ScrollArea:
style_class << 'valid' if experiment.valid else 'invalid'
Container:
style_class << 'valid' if experiment.valid else 'invalid'
hug_height='strong'
Container:
constraints=[hbox(b1,b3,b4),b1.width==100,b3.width==100,b4.width==100]
PushButton: b1:
text='open connection'
clicked::
LabView.openThread()
PushButton: b3:
text='update settings'
clicked::
LabView.update()
PushButton: b4:
text='close connection'
clicked::
LabView.close()
Form:
Label:
text='enable communication with LabView system?'
CheckBox:
checked:=LabView.enable
Label:
text='IP address of LabView system'
Field:
text:=LabView.IP
Label:
text='communications port'
IntField:
value:=LabView.port
Label:
text='cycle experiment continuously even when not taking data?'
CheckBox:
checked:=LabView.cycleContinuously
EvalProp:
prop<<LabView.timeout
Form:
Label:
text='connected'
CheckBox:
checked:=LabView.connected
enabled=False
Label: text='LabView error'
Label: text<<str(LabView.error)
GroupBox:
title='TCP output message'
constraints = [vbox(scroller1),(height==500)|'strong']
hug_width='ignore'
ScrollArea:scroller1:
Container:
hug_height='ignore'
hug_width='ignore'
Label:
hug_height='ignore'
hug_width='ignore'
text<<LabView.msg
GroupBox:
title='LabView log'
constraints = [vbox(scroller2),(height==500)|'strong']
hug_width='ignore'
ScrollArea: scroller2:
Container:
hug_height='ignore'
hug_width='ignore'
Label:
hug_height='ignore'
hug_width='ignore'
text<<LabView.log
enamldef DOchannel(Container):
attr channel
attr index
hug_height='strong'
padding=0
constraints=[label.width==25,description.width==3*activeF.width,activeF.width==2*activeL.width,hbox(label,description,activeF,activeL,),align('v_center',label,description,activeF,activeL)]
Label: label:
text=str(index)
Field: description:
text:=channel.description
placeholder='description'
Field: activeF:
text:=channel.active.function
placeholder='active?'
Label: activeL:
text<<str(channel.active.value)
enamldef HSDIOScriptTrigger(StackItem):
attr item
Container:
padding=0
Form:
Label:
text='description'
Field:
placeholder='description'
text:=item.description
EvalProp:
prop<<item.id
EvalProp:
prop<<item.source
EvalProp:
prop<<item.type
EvalProp:
prop<<item.edge
EvalProp:
prop<<item.level
enamldef StartTrigger(GroupBox):
attr trigger
title='Start Trigger'
EvalProp:
prop<<trigger.waitForStartTrigger
EvalProp:
prop<<trigger.source
EvalProp:
prop<<trigger.edge
class RefreshableMPLCanvas(MPLCanvas):
""" An MPLCanvas that can be refreshed on command by toggling refresh.
Requires adding a function to MPLCanvas in
C:\Users\Saffmanlab\AppData\Local\Enthought\Canopy\User\Lib\site-packages\enaml\qt\qt_mpl_canvas.py:
def on_action_set_refresh(self, content):
self.refresh_mpl_widget()
"""
#: Toggle this to refresh the canvas
refresh = d_(Bool())
class RemoveEventContainer(Container):
remove=d_(Bool())
enamldef NumpyAOchannel(Container):
attr channel
attr index
hug_height='strong'
hug_width='strong'
padding=0
Form:
Label: text=str(index)
Field:
text:=channel['description']
placeholder='description'
enamldef NumpyAOchannels(GroupBox):
attr channels
title='channels (#, description)'
hug_height='strong'
hug_width='strong'
Container: controls:
hug_height='strong'
hug_width='strong'
constraints=[hbox(spin0,addButton,removeButton)]
SpinBox: spin0:
minimum=0
maximum<<len(channels.array)
PushButton: addButton:
text='+'
clicked::
channels.add(spin0.value)
PushButton: removeButton:
text='-'
clicked::
channels.remove(spin0.value)
Container:
Include:
objects<<[NumpyAOchannel(channel=x,index=i) for i,x in enumerate(channels.array)]
enamldef NumpyDOchannel(Container):
attr channel
attr index
attr digitalout #the DAQmxDO or HSDIO
attr experiment
hug_height='strong'
hug_width='strong'
padding=0
constraints=[label.width==25,description.width==3*activeF.width,activeF.width==2*activeL.width,hbox(label,description,activeF,activeL,),align('v_center',label,description,activeF,activeL)]
Label: label:
text=str(index)
Field: description:
text:=channel['description']
placeholder='description'
Field: activeF:
text:=channel['function']
placeholder='active?'
validator<<MyBoolValidator(experiment)
text::
channel['value']=experiment.eval_bool(text)
activeL.text=str(channel['value']) #must be updated manually because the channel['value'] identity does not change
digitalout.evaluate()
Label: activeL:
text<<str(channel['value'])
enamldef NumpyDOchannels(GroupBox):
attr channels
title='channels (#, description, active?)'
hug_height='strong'
hug_width='strong'
#constraints=[controls.left==dynoCont.left]
Container: controls:
hug_height='strong'
hug_width='strong'
constraints=[hbox(spin0,addButton,removeButton)]
SpinBox: spin0:
minimum=0
maximum<<len(channels.array)
PushButton: addButton:
text='+'
clicked::
channels.add(spin0.value)
PushButton: removeButton:
text='-'
clicked::
channels.remove(spin0.value)
Container: dynoCont:
Include: dyno:
objects<<[NumpyDOchannel(channel=x,index=i,digitalout=channels.digitalout,experiment=channels.experiment) for i,x in enumerate(channels.array)]
enamldef NumpyState(Form):
attr state
attr experiment
attr waveform
attr value_str
attr valid
padding=0
Field:
constraints = [width == 100,height==20]
style_class << 'valid' if valid else 'invalid'
text:=state['function']
text::
value, parent.valid = experiment.eval_general(text)
if value is None:
state['value'] = 5
parent.value_str = ''
elif (value == 0) or (value ==1):
state['value'] = value
parent.value_str = str(state['value']) #must be updated manually because state['value'] identity does not change
else:
logger.warning('Invalid state in waveform {}. States must evaluate to None, 0 or 1.\n{} = {}'.format(waveform.name,text,value))
state['value'] = 5
parent.value_str = ''
parent.valid = False
waveform.updateFigure()
Label: valueLabel:
constraints = [width==50, height==20]
text << value_str
enamldef ChannelCombo(ComboBox):
attr wfm
attr channels
attr channelList
attr position
items<<[str(i)+' '+x for i,x in enumerate(channels.array['description'])]
index<<int(channelList[position])
index::
channelList[position]=numpy.uint8(index)
wfm.updateFigure()
enamldef TransitionsLabel(Container):
padding=0
Label:
constraints = [height == 20]
text='description'
Label:
constraints = [height == 20]
text='time'
enamldef DescriptionLabel(Label):
constraints = [height == 20]
text='description'
enamldef TimeLabel(Label):
constraints = [height == 20]
text='time'
enamldef TransitionDescription(Field):
attr transition
constraints = [height==20]
placeholder = 'description'