1 | |
---|
2 | import wx |
---|
3 | import sys |
---|
4 | from copy import deepcopy |
---|
5 | from DataLoader.data_info import Detector |
---|
6 | from sans.guiframe.utils import check_float |
---|
7 | _BOX_WIDTH = 60 |
---|
8 | |
---|
9 | if sys.platform.count("win32")>0: |
---|
10 | _STATICBOX_WIDTH = 465 |
---|
11 | PANEL_WIDTH = 500 |
---|
12 | PANEL_HEIGHT = 450 |
---|
13 | FONT_VARIANT = 0 |
---|
14 | else: |
---|
15 | _STATICBOX_WIDTH = 480 |
---|
16 | PANEL_WIDTH = 550 |
---|
17 | PANEL_HEIGHT = 480 |
---|
18 | FONT_VARIANT = 1 |
---|
19 | |
---|
20 | class DetectorDialog(wx.Dialog): |
---|
21 | def __init__(self, parent=None, id=-1, manager=None, detector=None, |
---|
22 | title="Detector Editor",size=(PANEL_WIDTH, PANEL_HEIGHT)): |
---|
23 | wx.Dialog.__init__(self, parent=parent, id=id, title=title, size=size) |
---|
24 | try: |
---|
25 | self.parent = parent |
---|
26 | self.manager = manager |
---|
27 | self._detector = detector |
---|
28 | |
---|
29 | self._reset_detector = deepcopy(detector) |
---|
30 | self._notes = "" |
---|
31 | self._description = "Edit Detector" |
---|
32 | self._do_layout() |
---|
33 | self.set_values() |
---|
34 | except: |
---|
35 | print "error", sys.exc_value |
---|
36 | |
---|
37 | def _define_structure(self): |
---|
38 | """ |
---|
39 | define initial sizer |
---|
40 | """ |
---|
41 | self.main_sizer = wx.BoxSizer(wx.VERTICAL) |
---|
42 | self.box_detector = wx.StaticBox(self, -1,str("Edit Selected Detector")) |
---|
43 | self.boxsizer_detector = wx.StaticBoxSizer(self.box_detector, |
---|
44 | wx.VERTICAL) |
---|
45 | detector_box = wx.StaticBox(self, -1, "Edit Number of Detectors") |
---|
46 | self.detector_sizer = wx.StaticBoxSizer(detector_box, wx.VERTICAL) |
---|
47 | self.detector_sizer.SetMinSize((_STATICBOX_WIDTH, -1)) |
---|
48 | self.detector_button_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
49 | self.detector_hint_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
50 | |
---|
51 | self.detector_button_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
52 | self.detector_hint_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
53 | self.instrument_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
54 | self.distance_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
55 | self.offset_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
56 | self.orientation_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
57 | self.beam_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
58 | self.pixel_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
59 | self.slit_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
60 | self.button_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
61 | |
---|
62 | def _layout_detector(self): |
---|
63 | """ |
---|
64 | Do the layout for detector related widgets |
---|
65 | """ |
---|
66 | detector_name_txt = wx.StaticText(self, -1, "Detector:") |
---|
67 | hint_detector_txt = 'Current available detector.' |
---|
68 | detector_name_txt.SetToolTipString(hint_detector_txt) |
---|
69 | self.detector_cbox = wx.ComboBox(self, -1, style=wx.CB_READONLY) |
---|
70 | hint_detector_name_txt = 'Name of detectors.' |
---|
71 | self.detector_cbox.SetToolTipString(hint_detector_name_txt) |
---|
72 | |
---|
73 | self.bt_add_detector = wx.Button(self, -1, "Add") |
---|
74 | self.bt_add_detector.SetToolTipString("Add data's detector.") |
---|
75 | self.bt_add_detector.Bind(wx.EVT_BUTTON, self.add_detector) |
---|
76 | |
---|
77 | self.bt_remove_detector = wx.Button(self, -1, "Remove") |
---|
78 | self.bt_remove_detector.SetToolTipString("Remove data's detector.") |
---|
79 | self.bt_remove_detector.Bind(wx.EVT_BUTTON, self.remove_detector) |
---|
80 | |
---|
81 | self.detector_button_sizer.AddMany([(detector_name_txt, 0, wx.LEFT, 15), |
---|
82 | (self.detector_cbox, 0, wx.LEFT, 5), |
---|
83 | (self.bt_add_detector, 0, wx.LEFT, 10), |
---|
84 | (self.bt_remove_detector, 0, wx.LEFT, 5)]) |
---|
85 | detector_hint_txt = 'No detector is available for this data.' |
---|
86 | self.detector_txt = wx.StaticText(self, -1, detector_hint_txt) |
---|
87 | self.detector_hint_sizer.Add(self.detector_txt, 0, wx.LEFT, 10) |
---|
88 | self.detector_sizer.AddMany([(self.detector_button_sizer, 0, wx.ALL, 10), |
---|
89 | (self.detector_hint_sizer, 0, wx.ALL, 10)]) |
---|
90 | |
---|
91 | self.fill_detector_combox() |
---|
92 | self.enable_detector() |
---|
93 | |
---|
94 | def _layout_instrument_sizer(self): |
---|
95 | """ |
---|
96 | Do the layout for instrument related widgets |
---|
97 | """ |
---|
98 | #Instrument |
---|
99 | instrument_name_txt = wx.StaticText(self, -1, 'Instrument Name : ') |
---|
100 | self.instrument_name_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH*5, 20), style=0) |
---|
101 | self.instrument_sizer.AddMany([(instrument_name_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
102 | (self.instrument_name_tcl, 0, wx.EXPAND)]) |
---|
103 | def _layout_distance(self): |
---|
104 | """ |
---|
105 | Do the layout for distance related widgets |
---|
106 | """ |
---|
107 | distance_txt = wx.StaticText(self, -1, 'Sample to Detector Distance : ') |
---|
108 | self.distance_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) |
---|
109 | distance_unit_txt = wx.StaticText(self, -1, 'Unit: ') |
---|
110 | self.distance_unit_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) |
---|
111 | self.distance_sizer.AddMany([(distance_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
112 | (self.distance_tcl, 0, wx.RIGHT, 10), |
---|
113 | (distance_unit_txt, 0, wx.EXPAND), |
---|
114 | (self.distance_unit_tcl, 0, wx.RIGHT, 10)]) |
---|
115 | |
---|
116 | def _layout_offset(self): |
---|
117 | """ |
---|
118 | Do the layout for offset related widgets |
---|
119 | """ |
---|
120 | #Offset |
---|
121 | offset_txt = wx.StaticText(self, -1, 'Offset:') |
---|
122 | x_offset_txt = wx.StaticText(self, -1, 'x = ') |
---|
123 | self.x_offset_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) |
---|
124 | y_offset_txt = wx.StaticText(self, -1, 'y = ') |
---|
125 | self.y_offset_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) |
---|
126 | z_offset_txt = wx.StaticText(self, -1, 'z = ') |
---|
127 | self.z_offset_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) |
---|
128 | offset_unit_txt = wx.StaticText(self, -1, 'Unit: ') |
---|
129 | self.offset_unit_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) |
---|
130 | self.offset_sizer.AddMany([(offset_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
131 | (x_offset_txt, 0, wx.LEFT, 30), |
---|
132 | (self.x_offset_tcl, 0, wx.RIGHT, 10), |
---|
133 | (y_offset_txt, 0, wx.EXPAND), |
---|
134 | (self.y_offset_tcl, 0, wx.RIGHT, 10), |
---|
135 | (z_offset_txt, 0, wx.EXPAND), |
---|
136 | (self.z_offset_tcl, 0, wx.RIGHT, 10), |
---|
137 | (offset_unit_txt, 0, wx.EXPAND), |
---|
138 | (self.offset_unit_tcl, 0, wx.RIGHT, 10)]) |
---|
139 | |
---|
140 | def _layout_orientation(self): |
---|
141 | """ |
---|
142 | Do the layout for orientation related widgets |
---|
143 | """ |
---|
144 | #Orientation |
---|
145 | orientation_txt = wx.StaticText(self, -1, 'Orientation:') |
---|
146 | x_orientation_txt = wx.StaticText(self, -1, 'x = ') |
---|
147 | self.x_orientation_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) |
---|
148 | y_orientation_txt = wx.StaticText(self, -1, 'y = ') |
---|
149 | self.y_orientation_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) |
---|
150 | z_orientation_txt = wx.StaticText(self, -1, 'z = ') |
---|
151 | self.z_orientation_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) |
---|
152 | orientation_unit_txt = wx.StaticText(self, -1, 'Unit: ') |
---|
153 | self.orientation_unit_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20),style=0) |
---|
154 | self.orientation_sizer.AddMany([(orientation_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
155 | (x_orientation_txt, 0, wx.LEFT, 7), |
---|
156 | (self.x_orientation_tcl, 0, wx.RIGHT, 10), |
---|
157 | (y_orientation_txt, 0, wx.EXPAND), |
---|
158 | (self.y_orientation_tcl, 0, wx.RIGHT, 10), |
---|
159 | (z_orientation_txt, 0, wx.EXPAND), |
---|
160 | (self.z_orientation_tcl, 0, wx.RIGHT, 10), |
---|
161 | (orientation_unit_txt, 0, wx.EXPAND), |
---|
162 | (self.orientation_unit_tcl, 0, wx.RIGHT, 10)]) |
---|
163 | |
---|
164 | def _layout_beam_center(self): |
---|
165 | """ |
---|
166 | Do the layout for beam center related widgets |
---|
167 | """ |
---|
168 | #Beam center |
---|
169 | beam_center_txt = wx.StaticText(self, -1, 'Beam Center:') |
---|
170 | x_beam_center_txt = wx.StaticText(self, -1, 'x = ') |
---|
171 | self.x_beam_center_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) |
---|
172 | y_beam_center_txt = wx.StaticText(self, -1, 'y = ') |
---|
173 | self.y_beam_center_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) |
---|
174 | z_beam_center_txt = wx.StaticText(self, -1, 'z = ') |
---|
175 | self.z_beam_center_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) |
---|
176 | beam_center_unit_txt = wx.StaticText(self, -1, 'Unit: ') |
---|
177 | self.beam_center_unit_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) |
---|
178 | self.beam_sizer.AddMany([(beam_center_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
179 | (x_beam_center_txt, 0, wx.EXPAND), |
---|
180 | (self.x_beam_center_tcl, 0, wx.RIGHT, 10), |
---|
181 | (y_beam_center_txt, 0, wx.EXPAND), |
---|
182 | (self.y_beam_center_tcl, 0, wx.RIGHT, 10), |
---|
183 | (z_beam_center_txt, 0, wx.EXPAND), |
---|
184 | (self.z_beam_center_tcl, 0, wx.RIGHT, 10), |
---|
185 | (beam_center_unit_txt, 0, wx.EXPAND), |
---|
186 | (self.beam_center_unit_tcl, 0,wx.RIGHT, 10)]) |
---|
187 | |
---|
188 | def _layout_pixel_size(self): |
---|
189 | """ |
---|
190 | Do the layout for pixel size related widgets |
---|
191 | """ |
---|
192 | #Pixel Size |
---|
193 | pixel_size_txt = wx.StaticText(self, -1, 'Pixel Size:') |
---|
194 | x_pixel_size_txt = wx.StaticText(self, -1, 'x = ') |
---|
195 | self.x_pixel_size_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) |
---|
196 | y_pixel_size_txt = wx.StaticText(self, -1, 'y = ') |
---|
197 | self.y_pixel_size_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) |
---|
198 | z_pixel_size_txt = wx.StaticText(self, -1, 'z = ') |
---|
199 | self.z_pixel_size_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) |
---|
200 | pixel_size_unit_txt = wx.StaticText(self, -1, 'Unit: ') |
---|
201 | self.pixel_size_unit_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) |
---|
202 | self.pixel_sizer.AddMany([(pixel_size_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
203 | (x_pixel_size_txt, 0, wx.LEFT, 17), |
---|
204 | (self.x_pixel_size_tcl, 0, wx.RIGHT, 10), |
---|
205 | (y_pixel_size_txt, 0, wx.EXPAND), |
---|
206 | (self.y_pixel_size_tcl, 0, wx.RIGHT, 10), |
---|
207 | (z_pixel_size_txt, 0, wx.EXPAND), |
---|
208 | (self.z_pixel_size_tcl, 0, wx.RIGHT, 10), |
---|
209 | (pixel_size_unit_txt, 0, wx.EXPAND), |
---|
210 | (self.pixel_size_unit_tcl, 0, wx.RIGHT, 10)]) |
---|
211 | |
---|
212 | def _layout_slit_length(self): |
---|
213 | """ |
---|
214 | Do the layout for slit length related widgets |
---|
215 | """ |
---|
216 | #slit length |
---|
217 | slit_length_txt = wx.StaticText(self, -1, 'Slit Length: ') |
---|
218 | self.slit_length_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) |
---|
219 | slit_length_unit_txt = wx.StaticText(self, -1, 'Unit: ') |
---|
220 | self.slit_length_unit_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) |
---|
221 | self.slit_sizer.AddMany([(slit_length_txt, 0, wx.LEFT, 10), |
---|
222 | (self.slit_length_tcl, 0, wx.RIGHT, 10), |
---|
223 | (slit_length_unit_txt, 0, wx.EXPAND), |
---|
224 | (self.slit_length_unit_tcl, 0,wx.RIGHT, 10)]) |
---|
225 | |
---|
226 | def _layout_button(self): |
---|
227 | """ |
---|
228 | Do the layout for the button widgets |
---|
229 | """ |
---|
230 | self.bt_apply = wx.Button(self, -1,'Apply') |
---|
231 | self.bt_apply.Bind(wx.EVT_BUTTON, self.on_click_apply) |
---|
232 | self.bt_apply.SetToolTipString("Apply current changes to the detector.") |
---|
233 | self.bt_cancel = wx.Button(self, -1,'Cancel') |
---|
234 | self.bt_cancel.SetToolTipString("Cancel current changes.") |
---|
235 | self.bt_cancel.Bind(wx.EVT_BUTTON, self.on_click_cancel) |
---|
236 | self.bt_close = wx.Button(self, wx.ID_CANCEL,'Close') |
---|
237 | self.bt_close.SetToolTipString("Close window.") |
---|
238 | self.button_sizer.AddMany([(self.bt_apply, 0, wx.LEFT, 200), |
---|
239 | (self.bt_cancel, 0, wx.LEFT, 10), |
---|
240 | (self.bt_close, 0, wx.LEFT, 10)]) |
---|
241 | |
---|
242 | def _do_layout(self, data=None): |
---|
243 | """ |
---|
244 | Draw the current panel |
---|
245 | """ |
---|
246 | self._define_structure() |
---|
247 | self._layout_detector() |
---|
248 | self._layout_instrument_sizer() |
---|
249 | self._layout_distance() |
---|
250 | self._layout_offset() |
---|
251 | self._layout_orientation() |
---|
252 | self._layout_beam_center() |
---|
253 | self._layout_pixel_size() |
---|
254 | self._layout_slit_length() |
---|
255 | self._layout_button() |
---|
256 | |
---|
257 | self.boxsizer_detector.AddMany([(self.instrument_sizer, 0, |
---|
258 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5), |
---|
259 | (self.distance_sizer, 0, |
---|
260 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5), |
---|
261 | (self.offset_sizer, 0, |
---|
262 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5), |
---|
263 | (self.orientation_sizer, 0, |
---|
264 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5), |
---|
265 | (self.beam_sizer, 0, |
---|
266 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5), |
---|
267 | (self.pixel_sizer, 0, |
---|
268 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5), |
---|
269 | (self.slit_sizer, 0, |
---|
270 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5)]) |
---|
271 | self.main_sizer.AddMany([(self.detector_sizer, 0, wx.ALL, 10), |
---|
272 | (self.boxsizer_detector, 0, wx.ALL, 10), |
---|
273 | (self.button_sizer, 0, |
---|
274 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5)]) |
---|
275 | |
---|
276 | self.SetSizer(self.main_sizer) |
---|
277 | self.SetAutoLayout(True) |
---|
278 | |
---|
279 | def reset_detector(self): |
---|
280 | """ |
---|
281 | put the default value of the detector back to the current detector |
---|
282 | """ |
---|
283 | self._detector = deepcopy(self._reset_detector) |
---|
284 | self.detector_cbox.Clear() |
---|
285 | self.fill_detector_combox() |
---|
286 | self.set_values() |
---|
287 | |
---|
288 | def set_manager(self, manager): |
---|
289 | """ |
---|
290 | Set manager of this window |
---|
291 | """ |
---|
292 | self.manager = manager |
---|
293 | |
---|
294 | def fill_detector_combox(self): |
---|
295 | """ |
---|
296 | fill the current combobox with the available detector |
---|
297 | """ |
---|
298 | for detector in self._detector: |
---|
299 | pos = self.detector_cbox.Append(str(detector.name)) |
---|
300 | self.detector_cbox.SetClientData(pos, detector) |
---|
301 | self.detector_cbox.SetSelection(pos) |
---|
302 | self.detector_cbox.SetStringSelection(str(detector.name)) |
---|
303 | |
---|
304 | def reset_detector_combobox(self, edited_detector): |
---|
305 | """ |
---|
306 | take all edited editor and reset clientdata of detector combo box |
---|
307 | """ |
---|
308 | for position in range(self.detector_cbox.GetCount()): |
---|
309 | detector = self.detector_cbox.GetClientData(position) |
---|
310 | if detector == edited_detector: |
---|
311 | detector = edited_detector |
---|
312 | self.detector_cbox.SetString(position, str(detector.name)) |
---|
313 | self.detector_cbox.SetClientData(position, detector) |
---|
314 | self.detector_cbox.SetStringSelection(str(detector.name)) |
---|
315 | |
---|
316 | def add_detector(self, event): |
---|
317 | """ |
---|
318 | Append empty detector to data's list of detector |
---|
319 | """ |
---|
320 | |
---|
321 | if not self.detector_cbox.IsEnabled(): |
---|
322 | self.detector_cbox.Enable() |
---|
323 | detector = Detector() |
---|
324 | self._detector.append(detector) |
---|
325 | position = self.detector_cbox.Append(str(detector.name)) |
---|
326 | self.detector_cbox.SetClientData(position, detector) |
---|
327 | self.detector_cbox.SetSelection(position) |
---|
328 | self.enable_detector() |
---|
329 | self.set_values() |
---|
330 | |
---|
331 | def remove_detector(self, event): |
---|
332 | """ |
---|
333 | Remove detector to data's list of detector |
---|
334 | """ |
---|
335 | if self.detector_cbox.IsEnabled(): |
---|
336 | if self.detector_cbox.GetCount() > 1: |
---|
337 | position = self.detector_cbox.GetCurrentSelection() |
---|
338 | detector = self.detector_cbox.GetClientData(position) |
---|
339 | if detector in self._detector: |
---|
340 | self._detector.remove(detector) |
---|
341 | self.detector_cbox.Delete(position) |
---|
342 | #set the combo box box the next available item |
---|
343 | position = self.detector_cbox.GetCount() |
---|
344 | if position > 0: |
---|
345 | position -= 1 |
---|
346 | self.detector_cbox.SetSelection(position) |
---|
347 | self.set_values() |
---|
348 | #disable or enable the combo box when necessary |
---|
349 | self.enable_detector() |
---|
350 | |
---|
351 | def enable_detector(self): |
---|
352 | """ |
---|
353 | Enable /disable widgets crelated to detector |
---|
354 | """ |
---|
355 | if self._detector is not None and self.detector_cbox.GetCount() > 0: |
---|
356 | self.detector_cbox.Enable() |
---|
357 | self.bt_remove_detector.Enable() |
---|
358 | n_detector = self.detector_cbox.GetCount() |
---|
359 | detector_hint_txt = 'Detectors available: %s '%str(n_detector) |
---|
360 | if len(self._detector) > 1: |
---|
361 | self.bt_remove_detector.Enable() |
---|
362 | else: |
---|
363 | self.bt_remove_detector.Disable() |
---|
364 | else: |
---|
365 | self.detector_cbox.Disable() |
---|
366 | self.bt_remove_detector.Disable() |
---|
367 | detector_hint_txt = 'No detector is available for this data.' |
---|
368 | self.detector_txt.SetLabel(detector_hint_txt) |
---|
369 | |
---|
370 | def set_detector(self, detector): |
---|
371 | """ |
---|
372 | set detector for data |
---|
373 | """ |
---|
374 | if self._detector is None: |
---|
375 | return |
---|
376 | if self._detector: |
---|
377 | for item in self._detector: |
---|
378 | if item == detector: |
---|
379 | item = detector |
---|
380 | self.reset_detector_combobox(edited_detector=detector) |
---|
381 | return |
---|
382 | |
---|
383 | def get_current_detector(self): |
---|
384 | """ |
---|
385 | """ |
---|
386 | if not self.detector_cbox.IsEnabled(): |
---|
387 | return None, None, None |
---|
388 | position = self.detector_cbox.GetSelection() |
---|
389 | if position == wx.NOT_FOUND: |
---|
390 | return None, None, None |
---|
391 | detector_name = self.detector_cbox.GetStringSelection() |
---|
392 | detector = self.detector_cbox.GetClientData(position) |
---|
393 | return detector, detector_name, position |
---|
394 | |
---|
395 | def set_values(self): |
---|
396 | """ |
---|
397 | take the detector values of the current data and display them |
---|
398 | through the panel |
---|
399 | """ |
---|
400 | detector, _, _ = self.get_current_detector() |
---|
401 | if detector is None: |
---|
402 | return |
---|
403 | self.instrument_name_tcl.SetValue(str(detector.name)) |
---|
404 | #Distance |
---|
405 | distance = detector.distance |
---|
406 | self.distance_tcl.SetValue(str(distance)) |
---|
407 | self.distance_unit_tcl.SetValue(str(detector.distance_unit)) |
---|
408 | #Offset |
---|
409 | x, y, z = detector.offset.x, detector.offset.y , detector.offset.z |
---|
410 | self.x_offset_tcl.SetValue(str(x)) |
---|
411 | self.y_offset_tcl.SetValue(str(y)) |
---|
412 | self.z_offset_tcl.SetValue(str(z)) |
---|
413 | self.offset_unit_tcl.SetValue(str(detector.offset_unit)) |
---|
414 | #Orientation |
---|
415 | x, y, z = detector.orientation.x, detector.orientation.y, detector.orientation.z |
---|
416 | self.x_orientation_tcl.SetValue(str(x)) |
---|
417 | self.y_orientation_tcl.SetValue(str(y)) |
---|
418 | self.z_orientation_tcl.SetValue(str(z)) |
---|
419 | self.orientation_unit_tcl.SetValue(str(detector.orientation_unit)) |
---|
420 | #Beam center |
---|
421 | x, y, z = detector.beam_center.x, detector.beam_center.y, detector.beam_center.z |
---|
422 | self.x_beam_center_tcl.SetValue(str(x)) |
---|
423 | self.y_beam_center_tcl.SetValue(str(y)) |
---|
424 | self.z_beam_center_tcl.SetValue(str(z)) |
---|
425 | self.beam_center_unit_tcl.SetValue(str(detector.beam_center_unit)) |
---|
426 | #Pixel size |
---|
427 | x, y, z = detector.pixel_size.x, detector.pixel_size.y, detector.pixel_size.z |
---|
428 | self.x_pixel_size_tcl.SetValue(str(x)) |
---|
429 | self.y_pixel_size_tcl.SetValue(str(y)) |
---|
430 | self.z_pixel_size_tcl.SetValue(str(z)) |
---|
431 | self.pixel_size_unit_tcl.SetValue(str(detector.pixel_size_unit)) |
---|
432 | #Slit length |
---|
433 | slit_length = detector.slit_length |
---|
434 | self.slit_length_tcl.SetValue(str(detector.slit_length)) |
---|
435 | self.slit_length_unit_tcl.SetValue(str(detector.slit_length_unit)) |
---|
436 | |
---|
437 | def get_detector(self): |
---|
438 | """ |
---|
439 | return the current detector |
---|
440 | """ |
---|
441 | return self._detector |
---|
442 | |
---|
443 | def get_notes(self): |
---|
444 | """ |
---|
445 | return notes |
---|
446 | """ |
---|
447 | return self._notes |
---|
448 | |
---|
449 | def on_change_instrument(self): |
---|
450 | """ |
---|
451 | Change instrument |
---|
452 | """ |
---|
453 | detector, detector_name, position = self.get_current_detector() |
---|
454 | if detector is None: |
---|
455 | return |
---|
456 | #Change the name of the detector |
---|
457 | name = self.instrument_name_tcl.GetValue().lstrip().rstrip() |
---|
458 | if name == "" or name == str(None): |
---|
459 | name = None |
---|
460 | if detector_name != name: |
---|
461 | self._notes += " Instrument's " |
---|
462 | self._notes += "name from %s to %s \n"%(detector_name, name) |
---|
463 | detector.name = name |
---|
464 | self.detector_cbox.SetString(position, str(detector.name)) |
---|
465 | self.detector_cbox.SetClientData(position, detector) |
---|
466 | self.detector_cbox.SetStringSelection(str(detector.name)) |
---|
467 | |
---|
468 | def on_change_distance(self): |
---|
469 | """ |
---|
470 | Change distance of the sample to the detector |
---|
471 | """ |
---|
472 | detector, _, position = self.get_current_detector() |
---|
473 | if detector is None: |
---|
474 | return |
---|
475 | #Change the distance |
---|
476 | distance = self.distance_tcl.GetValue().lstrip().rstrip() |
---|
477 | if distance == "" or distance == str(None): |
---|
478 | distance = None |
---|
479 | detector.distance = distance |
---|
480 | else: |
---|
481 | if check_float(self.distance_tcl): |
---|
482 | if detector.distance != float(distance): |
---|
483 | self._notes += " Change Distance from" |
---|
484 | self._notes += " %s to %s \n"%(detector.distance, distance) |
---|
485 | detector.distance = float(distance) |
---|
486 | else: |
---|
487 | self._notes += "Error: Expected a float for the distance won't changes " |
---|
488 | self._notes += "%s to %s"%(detector.distance, distance) |
---|
489 | #change the distance unit |
---|
490 | unit = self.distance_unit_tcl.GetValue().lstrip().rstrip() |
---|
491 | if detector.distance_unit != unit: |
---|
492 | self._notes += " Change distance's unit from " |
---|
493 | self._notes += "%s to %s"%(detector.distance_unit, unit) |
---|
494 | |
---|
495 | self.detector_cbox.SetString(position, str(detector.name)) |
---|
496 | self.detector_cbox.SetClientData(position, detector) |
---|
497 | self.detector_cbox.SetStringSelection(str(detector.name)) |
---|
498 | |
---|
499 | def on_change_offset(self): |
---|
500 | """ |
---|
501 | Change the detector offset |
---|
502 | """ |
---|
503 | detector, _, position = self.get_current_detector() |
---|
504 | if detector is None: |
---|
505 | return |
---|
506 | #Change x coordinate |
---|
507 | x_offset = self.x_offset_tcl.GetValue().lstrip().rstrip() |
---|
508 | if x_offset == "" or x_offset == str(None): |
---|
509 | x_offset = None |
---|
510 | detector.offset.x = x_offset |
---|
511 | else: |
---|
512 | if check_float(self.x_offset_tcl): |
---|
513 | if detector.offset.x != float(x_offset): |
---|
514 | self._notes += "Change x of offset from" |
---|
515 | self._notes += " %s to %s \n"%(detector.offset.x, x_offset) |
---|
516 | detector.offset.x = float(x_offset) |
---|
517 | else: |
---|
518 | self._notes += "Error: Expected a float for the offset 's x " |
---|
519 | self._notes += "won't changes x offset" |
---|
520 | self._notes += " from %s to %s"%(detector.offset.x, x_offset) |
---|
521 | #Change y coordinate |
---|
522 | y_offset = self.y_offset_tcl.GetValue().lstrip().rstrip() |
---|
523 | if y_offset == "" or y_offset == str(None): |
---|
524 | y_offset = None |
---|
525 | detector.offset.y = y_offset |
---|
526 | else: |
---|
527 | if check_float(self.y_offset_tcl): |
---|
528 | if detector.offset.y != float(y_offset): |
---|
529 | self._notes += "Change y of offset from " |
---|
530 | self._notes += "%s to %s \n"%(detector.offset.y, y_offset) |
---|
531 | detector.offset.y = float(y_offset) |
---|
532 | else: |
---|
533 | self._notes += "Error: Expected a float for the offset 's y " |
---|
534 | self._notes += "won't changes y " |
---|
535 | self._notes += "offset from %s to %s"%(detector.offset.y\ |
---|
536 | ,y_offset) |
---|
537 | #Change z coordinate |
---|
538 | z_offset = self.z_offset_tcl.GetValue().lstrip().rstrip() |
---|
539 | if z_offset == "" or z_offset == str(None): |
---|
540 | z_offset = None |
---|
541 | detector.offset.z = z_offset |
---|
542 | else: |
---|
543 | if check_float(self.z_offset_tcl): |
---|
544 | if detector.offset.z != float(z_offset): |
---|
545 | self._notes += "Change z of" |
---|
546 | self._notes += "offset from %s to %s \n"%(detector.offset.z,\ |
---|
547 | z_offset) |
---|
548 | detector.offset.z = float(z_offset) |
---|
549 | else: |
---|
550 | self._notes += "Error: Expected a float for the offset 's x " |
---|
551 | self._notes += "won't changes z" |
---|
552 | self._notes += "offset from %s to %s"%(detector.offset.z, z_offset) |
---|
553 | #change the offset unit |
---|
554 | unit = self.offset_unit_tcl.GetValue().lstrip().rstrip() |
---|
555 | if detector.offset_unit != unit: |
---|
556 | self._notes += " Change Offset's" |
---|
557 | self._notes += "unit from %s to %s"%(detector.offset_unit, unit) |
---|
558 | |
---|
559 | self.detector_cbox.SetString(position, str(detector.name)) |
---|
560 | self.detector_cbox.SetClientData(position, detector) |
---|
561 | self.detector_cbox.SetStringSelection(str(detector.name)) |
---|
562 | |
---|
563 | def on_change_orientation(self): |
---|
564 | """ |
---|
565 | Change the detector orientation |
---|
566 | """ |
---|
567 | detector, _, position = self.get_current_detector() |
---|
568 | if detector is None: |
---|
569 | return |
---|
570 | #Change x coordinate |
---|
571 | x_orientation = self.x_orientation_tcl.GetValue().lstrip().rstrip() |
---|
572 | if x_orientation == "" or x_orientation == str(None): |
---|
573 | x_orientation = None |
---|
574 | detector.orientation.x = x_orientation |
---|
575 | else: |
---|
576 | if check_float(self.x_orientation_tcl): |
---|
577 | if detector.orientation.x != float(x_orientation): |
---|
578 | self._notes += "Change x of orientation from " |
---|
579 | self._notes += "%s to %s \n"%(detector.orientation.x, x_orientation) |
---|
580 | detector.orientation.x = float(x_orientation) |
---|
581 | else: |
---|
582 | self._notes += "Error: Expected a float for the orientation 's x " |
---|
583 | self._notes += "won't changes x orientation from " |
---|
584 | self._notes += "%s to %s"%(detector.orientation.x, x_orientation) |
---|
585 | #Change y coordinate |
---|
586 | y_orientation = self.y_orientation_tcl.GetValue().lstrip().rstrip() |
---|
587 | if y_orientation == "" or y_orientation == str(None): |
---|
588 | y_orientation = None |
---|
589 | detector.orientation.y = y_orientation |
---|
590 | else: |
---|
591 | if check_float(self.y_orientation_tcl): |
---|
592 | if detector.orientation.y != float(y_orientation): |
---|
593 | self._notes += "Change y of orientation from " |
---|
594 | self._notes += "%s to %s \n"%(detector.orientation.y, y_orientation) |
---|
595 | detector.orientation.y = float(y_orientation) |
---|
596 | else: |
---|
597 | self._notes += "Error: Expected a float for the orientation's y " |
---|
598 | self._notes += "won't changes y orientation from " |
---|
599 | self._notes += "%s to %s"%(detector.orientation.y, y_orientation) |
---|
600 | #Change z coordinate |
---|
601 | z_orientation = self.z_orientation_tcl.GetValue().lstrip().rstrip() |
---|
602 | if z_orientation == "" or z_orientation == str(None): |
---|
603 | z_orientation = None |
---|
604 | detector.orientation.z = z_orientation |
---|
605 | else: |
---|
606 | if check_float(self.z_orientation_tcl): |
---|
607 | if detector.orientation.z != float(z_orientation): |
---|
608 | self._notes += "Change z of offset from " |
---|
609 | self._notes += "%s to %s \n"%(detector.orientation.z, z_orientation) |
---|
610 | detector.orientation.z = float(z_orientation) |
---|
611 | else: |
---|
612 | self._notes += "Error: Expected a float for the orientation 's x " |
---|
613 | self._notes += "won't changes z orientation from " |
---|
614 | self._notes += "%s to %s"%(detector.orientation.z, z_orientation) |
---|
615 | #change the orientation unit |
---|
616 | unit = self.orientation_unit_tcl.GetValue().lstrip().rstrip() |
---|
617 | if detector.orientation_unit != unit: |
---|
618 | self._notes += " Change orientation's unit from " |
---|
619 | self._notes += "%s to %s"%(detector.orientation_unit, unit) |
---|
620 | |
---|
621 | self.detector_cbox.SetString(position, str(detector.name)) |
---|
622 | self.detector_cbox.SetClientData(position, detector) |
---|
623 | self.detector_cbox.SetStringSelection(str(detector.name)) |
---|
624 | |
---|
625 | def on_change_beam_center(self): |
---|
626 | """ |
---|
627 | Change the detector beam center |
---|
628 | """ |
---|
629 | |
---|
630 | detector, _, position = self.get_current_detector() |
---|
631 | if detector is None: |
---|
632 | return |
---|
633 | #Change x coordinate |
---|
634 | x_beam_center = self.x_beam_center_tcl.GetValue().lstrip().rstrip() |
---|
635 | if x_beam_center == "" or x_beam_center == str(None): |
---|
636 | x_beam_center = None |
---|
637 | detector.beam_center.x = x_beam_center |
---|
638 | else: |
---|
639 | if check_float(self.x_beam_center_tcl): |
---|
640 | if detector.beam_center.x != float(x_beam_center): |
---|
641 | self._notes += "Change x of offset from " |
---|
642 | self._notes += "%s to %s \n"%(detector.beam_center.x, x_beam_center) |
---|
643 | detector.beam_center.x = float(x_beam_center) |
---|
644 | else: |
---|
645 | self._notes += "Error: Expected a float for the beam center 's x " |
---|
646 | self._notes += "won't changes x beam center from " |
---|
647 | self._notes += "%s to %s"%(detector.beam_center.x, x_beam_center) |
---|
648 | #Change y coordinate |
---|
649 | y_beam_center = self.y_beam_center_tcl.GetValue().lstrip().rstrip() |
---|
650 | if y_beam_center == "" or y_beam_center == str(None): |
---|
651 | y_beam_center = None |
---|
652 | detector.beam_center.y = y_beam_center |
---|
653 | else: |
---|
654 | if check_float(self.y_beam_center_tcl): |
---|
655 | if detector.beam_center.y != float(y_beam_center): |
---|
656 | self._notes += "Change y of beam center from " |
---|
657 | self._notes += "%s to %s \n"%(detector.beam_center.y, y_beam_center) |
---|
658 | detector.beam_center.y = float(y_beam_center) |
---|
659 | else: |
---|
660 | self._notes += "Error: Expected a float for the beam center 's y " |
---|
661 | self._notes += "won't changes y beam center from " |
---|
662 | self._notes += "%s to %s"%(detector.beam_center.y, y_beam_center) |
---|
663 | #Change z coordinate |
---|
664 | z_beam_center = self.z_beam_center_tcl.GetValue().lstrip().rstrip() |
---|
665 | if z_beam_center == "" or z_beam_center == str(None): |
---|
666 | z_beam_center = None |
---|
667 | detector.beam_center.z = z_beam_center |
---|
668 | else: |
---|
669 | if check_float(self.z_beam_center_tcl): |
---|
670 | if detector.beam_center.z != float(z_beam_center): |
---|
671 | self._notes += "Change z of beam center from " |
---|
672 | self._notes += "%s to %s \n"%(detector.beam_center.z, z_beam_center) |
---|
673 | detector.beam_center.z = float(z_beam_center) |
---|
674 | else: |
---|
675 | self._notes += "Error: Expected a float for the offset 's x " |
---|
676 | self._notes += "won't changes z beam center from " |
---|
677 | self._notes += "%s to %s"%(detector.beam_center.z, z_beam_center) |
---|
678 | #change the beam center unit |
---|
679 | unit = self.beam_center_unit_tcl.GetValue().lstrip().rstrip() |
---|
680 | if detector.beam_center_unit != unit: |
---|
681 | self._notes += " Change beam center's unit from " |
---|
682 | self._notes += "%s to %s"%(detector.beam_center_unit, unit) |
---|
683 | |
---|
684 | self.detector_cbox.SetString(position, str(detector.name)) |
---|
685 | self.detector_cbox.SetClientData(position, detector) |
---|
686 | self.detector_cbox.SetStringSelection(str(detector.name)) |
---|
687 | |
---|
688 | def on_change_pixel_size(self): |
---|
689 | """ |
---|
690 | Change the detector pixel size |
---|
691 | """ |
---|
692 | detector, _, position = self.get_current_detector() |
---|
693 | if detector is None: |
---|
694 | return |
---|
695 | #Change x coordinate |
---|
696 | x_pixel_size = self.x_pixel_size_tcl.GetValue().lstrip().rstrip() |
---|
697 | if x_pixel_size == "" or x_pixel_size == str(None): |
---|
698 | x_pixel_size = None |
---|
699 | else: |
---|
700 | if check_float(self.x_pixel_size_tcl): |
---|
701 | if detector.pixel_size.x != float(x_pixel_size) : |
---|
702 | self._notes += "Change x of pixel size from " |
---|
703 | self._notes += "%s to %s \n"%(detector.pixel_size.x, x_pixel_size) |
---|
704 | detector.pixel_size.x = float(x_pixel_size) |
---|
705 | else: |
---|
706 | self._notes += "Error: Expected a float for the pixel size 's x " |
---|
707 | self._notes += "won't changes x pixel size from " |
---|
708 | self._notes += "%s to %s"%(detector.pixel_size.x, x_pixel_size) |
---|
709 | #Change y coordinate |
---|
710 | y_pixel_size = self.y_pixel_size_tcl.GetValue().lstrip().rstrip() |
---|
711 | if y_pixel_size == "" or y_pixel_size == str(None): |
---|
712 | y_pixel_size = None |
---|
713 | detector.pixel_size.y = y_pixel_size |
---|
714 | else: |
---|
715 | if check_float(self.y_pixel_size_tcl): |
---|
716 | if detector.pixel_size.y != float(y_pixel_size): |
---|
717 | self._notes += "Change y of pixel size from " |
---|
718 | self._notes += "%s to %s \n"%(detector.pixel_size.y, y_pixel_size) |
---|
719 | detector.pixel_size.y = float(y_pixel_size) |
---|
720 | else: |
---|
721 | self._notes += "Error: Expected a float for the pixel size's y " |
---|
722 | self._notes += "won't changes y pixel size from " |
---|
723 | self._notes += "%s to %s"%(detector.pixel_size.y, y_pixel_size) |
---|
724 | #Change z coordinate |
---|
725 | z_pixel_size = self.z_pixel_size_tcl.GetValue().lstrip().rstrip() |
---|
726 | if z_pixel_size == "" or z_pixel_size == str(None): |
---|
727 | z_pixel_size = None |
---|
728 | detector.pixel_size.z = z_pixel_size |
---|
729 | else: |
---|
730 | if check_float(self.z_pixel_size_tcl): |
---|
731 | if detector.pixel_size.z != float(z_pixel_size): |
---|
732 | self._notes += "Change z of pixel size from " |
---|
733 | self._notes += "%s to %s \n"%(detector.pixel_size.z, z_pixel_size) |
---|
734 | detector.pixel_size.z = float(z_pixel_size) |
---|
735 | else: |
---|
736 | self._notes += "Error: Expected a float for the offset 's x " |
---|
737 | self._notes += "won't changes z pixel size from " |
---|
738 | self._notes += "%s to %s"%(detector.pixel_size.z, z_pixel_size) |
---|
739 | #change the beam center unit |
---|
740 | unit = self.pixel_size_unit_tcl.GetValue().lstrip().rstrip() |
---|
741 | if detector.pixel_size_unit != unit: |
---|
742 | self._notes += " Change pixel size's unit from " |
---|
743 | self._notes += "%s to %s"%(detector.pixel_size_unit, unit) |
---|
744 | |
---|
745 | self.detector_cbox.SetString(position, str(detector.name)) |
---|
746 | self.detector_cbox.SetClientData(position, detector) |
---|
747 | self.detector_cbox.SetStringSelection(str(detector.name)) |
---|
748 | |
---|
749 | def on_change_slit_length(self): |
---|
750 | """ |
---|
751 | Change slit length of the detector |
---|
752 | """ |
---|
753 | detector, _, position = self.get_current_detector() |
---|
754 | if detector is None: |
---|
755 | return |
---|
756 | #Change the distance |
---|
757 | slit_length = self.slit_length_tcl.GetValue().lstrip().rstrip() |
---|
758 | if slit_length == "" or slit_length == str(None): |
---|
759 | slit_length = None |
---|
760 | detector.slit_length = slit_length |
---|
761 | else: |
---|
762 | if check_float(self.slit_length_tcl): |
---|
763 | if detector.slit_length != float(slit_length): |
---|
764 | self._notes += " Change slit length from" |
---|
765 | self._notes += " %s to %s \n"%(detector.slit_length, slit_length) |
---|
766 | detector.slit_length = float(slit_length) |
---|
767 | else: |
---|
768 | self._notes += "Error: Expected a float for the slit length won't changes " |
---|
769 | self._notes += "%s to %s"%(detector.slit_length, slit_length) |
---|
770 | #change the distance unit |
---|
771 | unit = self.slit_length_unit_tcl.GetValue().lstrip().rstrip() |
---|
772 | if detector.slit_length_unit != unit: |
---|
773 | self._notes += " Change slit length's unit from " |
---|
774 | self._notes += "%s to %s"%(detector.slit_length_unit_tcl, unit) |
---|
775 | |
---|
776 | self.detector_cbox.SetString(position, str(detector.name)) |
---|
777 | self.detector_cbox.SetClientData(position, detector) |
---|
778 | self.detector_cbox.SetStringSelection(str(detector.name)) |
---|
779 | |
---|
780 | def on_click_cancel(self, event): |
---|
781 | """ |
---|
782 | reset the current detector to its initial values |
---|
783 | """ |
---|
784 | self.reset_detector() |
---|
785 | self.set_values() |
---|
786 | if self.manager is not None: |
---|
787 | self.manager.set_detector(self._detector) |
---|
788 | |
---|
789 | def on_click_apply(self, event): |
---|
790 | """ |
---|
791 | Apply user values to the detector |
---|
792 | """ |
---|
793 | self.on_change_instrument() |
---|
794 | self.on_change_distance() |
---|
795 | self.on_change_instrument() |
---|
796 | self.on_change_beam_center() |
---|
797 | self.on_change_offset() |
---|
798 | self.on_change_orientation() |
---|
799 | self.on_change_pixel_size() |
---|
800 | self.on_change_slit_length() |
---|
801 | for detector in self._detector: |
---|
802 | self.manager.set_detector(self._detector, self._notes) |
---|
803 | |
---|
804 | if __name__ == "__main__": |
---|
805 | app = wx.App() |
---|
806 | detector = Detector() |
---|
807 | dlg = DetectorDialog(detector=[detector]) |
---|
808 | dlg.ShowModal() |
---|
809 | app.MainLoop() |
---|
810 | |
---|