-
Notifications
You must be signed in to change notification settings - Fork 11
/
ExpSettingsView.enaml
218 lines (204 loc) · 6.2 KB
/
ExpSettingsView.enaml
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
from enaml.widgets.api import MainWindow, Window, Container, Notebook, Page, MenuBar, \
Menu, Action, FileDialogEx, ComboBox, PushButton, PopupView, Label, \
CheckBox, Form, Field, GroupBox
from enaml.core.api import Looper
from enaml.layout.api import hbox, vbox, spacer, align
from ChannelsViews import ChannelLibraryView
from instruments.InstrumentManagerView import InstrumentManagerView
from SweepsViews import SweepManager
from MeasFiltersViews import MeasFilterManager
import os, sys, time
def get_update_script_file_callback(expSettings):
def update_script_file_callback(dlg):
if dlg.result == 'accepted': #if the pressed "open" otherwise we get 'rejected'
expSettings.curFileName = dlg.path
print(expSettings.curFileName)
return update_script_file_callback
enamldef NotificationPopup(PopupView):
attr displayText = ''
foreground = 'white'
background = 'rgba(30, 30, 30, 0.85)'
window_type = 'tool_tip'
parent_anchor = (1.0, 1.0)
anchor = (1.0, 1.0)
offset = (-10, -10)
timeout = 1
fade_in_duration = 200
fade_out_duration = 200
Container:
Label:
foreground = 'white'
text = displayText
align = 'center'
enamldef ErrorPopup(Window): error_win:
title = 'Error!'
modality = 'application_modal'
attr displayText = ''
Container:
constraints = []
Label:
text = displayText
PushButton: ok_btn:
text = 'Okay'
clicked ::
error_win.close()
enamldef ExpSettingsView(MainWindow): main:
attr expSettings
attr curFileName := expSettings.curFileName
title = 'Experiment Settings'
MenuBar:
Menu:
title = '&File'
Action:
text = 'Save\tCtrl+S'
tool_tip << 'Save to {}'.format(curFileName)
triggered ::
expSettings.write_to_file()
if expSettings.write_libraries():
NotificationPopup(main, window_type='window', displayText="Settings saved").show()
else:
ep = ErrorPopup(displayText=expSettings.format_errors())
ep.show()
ep.center_on_widget(main)
Action:
text = 'Save Config As\tCtrl+Shift+S'
tool_tip = 'Save to a new setting file'
triggered ::
path = FileDialogEx.get_existing_directory(main,show_dirs_only=False)
if not os.path.isdir(path) and path !='':
print("{} does not exist so creating it".format(path))
os.mkdir(path)
try:
expSettings.save_config(path)
NotificationPopup(main, window_type='window', displayText="Config Saved").show()
except Exception as e:
err_str = expSettings.format_errors()
if not err_str:
err_str = str(e)
ep = ErrorPopup(displayText=err_str)
ep.show()
ep.center_on_widget(main)
Action:
text = 'Load Config\tCtrl+Shift+O'
tool_tip = 'Load Config Files from Saved Location'
triggered ::
path = FileDialogEx.get_existing_directory(main,show_dirs_only=False)
if not os.path.isdir(path):
print('% s Does not Exist: Creating %s'%(path,path))
ep = ErrorPopup(displayText=expSettings.format_errors())
ep.show()
ep.center_on_widget(main)
os.mkdir(path)
try:
expSettings.load_config(path)
NotificationPopup(main, window_type='window', displayText="New Config Loaded ... Restarting GUI").show()
os.execl(sys.executable, sys.executable, * sys.argv)
except Exception as e:
err_str = expSettings.format_errors()
if not err_str:
err_str = str(e)
ep = ErrorPopup(displayText=err_str)
ep.show()
ep.center_on_widget(main)
Action:
text = "Stash current settings"
enabled = False
triggered ::
NotificationPopup(main, window_type='window', displayText="Settings stashed").show()
Action:
text = "Pop stashed settings"
enabled = False
triggered ::
NotificationPopup(main, window_type='window', displayText="Stashed settings applied").show()
Action:
text = 'Quit\tCtrl+Q'
triggered :: main.close()
Menu:
title = '&Mode'
Action:
text = 'CW Mode'
checkable = True
checked := expSettings.CWMode
Action:
text = 'Debug\tCtrl+D'
tool_tip = 'Start debugger console'
checkable = True
toggled :: import pdb; pdb.set_trace()
Container:
constraints = [
vbox(
tabs,
hbox(exp_meta_info, spacer, cbValidateForm, settingsApply)
),
align("v_center", exp_meta_info, cbValidateForm, settingsApply )
]
padding = 5
Notebook: tabs:
tab_style = 'preferences'
Page:
title = 'Channels'
closable = False
ChannelLibraryView:
channelLib := expSettings.channels
logicalChannelManager := expSettings.logicalChannelManager
physicalChannelManager := expSettings.physicalChannelManager
instrumentLib := expSettings.instruments
Page:
title = 'Instruments'
closable = False
InstrumentManagerView:
instrLib := expSettings.instruments
Page:
title = "Measurements"
closable = False
MeasFilterManager:
filterLib := expSettings.measurements
Page:
title = "Sweeps"
closable = False
SweepManager:
sweepLib := expSettings.sweeps
GroupBox: exp_meta_info:
constraints = [hbox(meta_label, meta_field, meta_button)]
Label: meta_label:
text = "Exp Meta File"
Field: meta_field:
text := expSettings.meta_file
PushButton: meta_button:
text = "Load"
clicked ::
try:
expSettings.load_meta()
NotificationPopup(
main,
window_type='window',
parent_anchor=(0, 1.0),
anchor=(0,1),
offset=(10,-10),
displayText="Meta file info loaded").show()
except Exception as e:
err_str = expSettings.format_errors()
if not err_str:
err_str = str(e)
ep = ErrorPopup(displayText=err_str)
ep.show()
ep.center_on_widget(main)
Form: cbValidateForm:
Label:
text = "Validate"
CheckBox:
checked := expSettings.validate
PushButton: settingsApply:
text = 'Apply'
clicked ::
expSettings.write_to_file()
try:
expSettings.write_libraries()
NotificationPopup(main, window_type='window', displayText="Settings saved").show()
except Exception as e:
err_str = expSettings.format_errors()
if not err_str:
err_str = str(e)
ep = ErrorPopup(displayText=err_str)
ep.show()
ep.center_on_widget(main)