1 | |
---|
2 | import wx |
---|
3 | import sys |
---|
4 | from copy import deepcopy |
---|
5 | from DataLoader.loader import Loader |
---|
6 | from sans.guiframe.utils import check_float |
---|
7 | |
---|
8 | _BOX_WIDTH = 60 |
---|
9 | if sys.platform.count("win32")>0: |
---|
10 | _STATICBOX_WIDTH = 450 |
---|
11 | PANEL_WIDTH = 500 |
---|
12 | PANEL_HEIGHT = 430 |
---|
13 | FONT_VARIANT = 0 |
---|
14 | else: |
---|
15 | _STATICBOX_WIDTH = 480 |
---|
16 | PANEL_WIDTH = 530 |
---|
17 | PANEL_HEIGHT = 430 |
---|
18 | FONT_VARIANT = 1 |
---|
19 | |
---|
20 | class SampleDialog(wx.Dialog): |
---|
21 | def __init__(self, parent=None, manager=None, sample=None, |
---|
22 | size=(PANEL_WIDTH, PANEL_HEIGHT),title='Sample Editor'): |
---|
23 | |
---|
24 | wx.Dialog.__init__(self, parent=parent, size=size, title=title) |
---|
25 | self.parent = parent |
---|
26 | self.manager = manager |
---|
27 | self._sample = sample |
---|
28 | self._reset_sample = deepcopy(sample) |
---|
29 | self._notes = "" |
---|
30 | self._description = "Edit Sample" |
---|
31 | self._do_layout() |
---|
32 | self.set_values() |
---|
33 | |
---|
34 | def _define_structure(self): |
---|
35 | """ |
---|
36 | define initial sizer |
---|
37 | """ |
---|
38 | self.main_sizer = wx.BoxSizer(wx.VERTICAL) |
---|
39 | self.box_sample = wx.StaticBox(self, -1,str("Sample")) |
---|
40 | self.boxsizer_sample = wx.StaticBoxSizer(self.box_sample, |
---|
41 | wx.VERTICAL) |
---|
42 | self.name_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
43 | self.id_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
44 | self.thickness_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
45 | self.transmission_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
46 | self.temperature_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
47 | self.position_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
48 | self.orientation_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
49 | self.details_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
50 | self.button_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
51 | |
---|
52 | def _layout_name(self): |
---|
53 | """ |
---|
54 | Do the layout for sample name related widgets |
---|
55 | """ |
---|
56 | ## Short name for sample [string] |
---|
57 | sample_name_txt = wx.StaticText(self, -1, 'Sample Name : ') |
---|
58 | self.sample_name_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH*5, 20), style=0) |
---|
59 | self.name_sizer.AddMany([(sample_name_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
60 | (self.sample_name_tcl, 0, wx.EXPAND)]) |
---|
61 | def _layout_id(self): |
---|
62 | """ |
---|
63 | Do the layout for id related widgets |
---|
64 | """ |
---|
65 | ## ID [String] |
---|
66 | id_txt = wx.StaticText(self, -1, 'ID: ') |
---|
67 | self.id_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) |
---|
68 | self.id_sizer.AddMany([(id_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
69 | (self.id_tcl, 0, wx.LEFT, 55)]) |
---|
70 | |
---|
71 | def _layout_thickness(self): |
---|
72 | """ |
---|
73 | Do the layout for thickness related widgets |
---|
74 | """ |
---|
75 | ## Thickness [float] [mm] |
---|
76 | thickness_txt = wx.StaticText(self, -1, 'Thickness:') |
---|
77 | self.thickness_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20),style=0) |
---|
78 | thickness_unit_txt = wx.StaticText(self, -1, 'Unit: ') |
---|
79 | self.thickness_unit_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), |
---|
80 | style=0) |
---|
81 | self.thickness_sizer.AddMany([(thickness_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
82 | (self.thickness_tcl, 0, wx.LEFT, 25), |
---|
83 | (thickness_unit_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
84 | (self.thickness_unit_tcl, 0, wx.EXPAND)]) |
---|
85 | def _layout_transmission(self): |
---|
86 | """ |
---|
87 | Do the layout for transmission related widgets |
---|
88 | """ |
---|
89 | ## Transmission [float] [fraction] |
---|
90 | transmission = None |
---|
91 | transmission_txt = wx.StaticText(self, -1, 'Transmission:') |
---|
92 | self.transmission_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20),style=0) |
---|
93 | self.transmission_sizer.AddMany([(transmission_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
94 | (self.transmission_tcl, 0, wx.LEFT, 12)]) |
---|
95 | |
---|
96 | def _layout_temperature(self): |
---|
97 | """ |
---|
98 | Do the layout for temperature related widgets |
---|
99 | """ |
---|
100 | ## Temperature [float] [C] |
---|
101 | temperature_txt = wx.StaticText(self, -1, 'Temperature:') |
---|
102 | self.temperature_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) |
---|
103 | temperature_unit_txt = wx.StaticText(self, -1, 'Unit: ') |
---|
104 | self.temperature_unit_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), |
---|
105 | style=0) |
---|
106 | self.temperature_sizer.AddMany([(temperature_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
107 | (self.temperature_tcl, 0, wx.LEFT, 10), |
---|
108 | (temperature_unit_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
109 | (self.temperature_unit_tcl, 0, wx.EXPAND)]) |
---|
110 | |
---|
111 | def _layout_position(self): |
---|
112 | """ |
---|
113 | Do the layout for position related widgets |
---|
114 | """ |
---|
115 | ## Position [Vector] [mm] |
---|
116 | position_txt = wx.StaticText(self, -1, 'Position:') |
---|
117 | x_position_txt = wx.StaticText(self, -1, 'x = ') |
---|
118 | self.x_position_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) |
---|
119 | y_position_txt = wx.StaticText(self, -1, 'y = ') |
---|
120 | self.y_position_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) |
---|
121 | z_position_txt = wx.StaticText(self, -1, 'z = ') |
---|
122 | self.z_position_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) |
---|
123 | position_unit_txt = wx.StaticText(self, -1, 'Unit: ') |
---|
124 | self.position_unit_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) |
---|
125 | self.position_sizer.AddMany([(position_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
126 | (x_position_txt, 0, wx.LEFT, 14), |
---|
127 | (self.x_position_tcl, 0, wx.RIGHT, 10), |
---|
128 | (y_position_txt, 0, wx.EXPAND), |
---|
129 | (self.y_position_tcl, 0, wx.RIGHT, 10), |
---|
130 | (z_position_txt, 0, wx.EXPAND), |
---|
131 | (self.z_position_tcl, 0, wx.RIGHT, 10), |
---|
132 | (position_unit_txt, 0, wx.EXPAND), |
---|
133 | (self.position_unit_tcl, 0, wx.RIGHT, 10)]) |
---|
134 | def _layout_orientation(self): |
---|
135 | """ |
---|
136 | Do the layout for orientation related widgets |
---|
137 | """ |
---|
138 | ## Orientation [Vector] [degrees] |
---|
139 | orientation_txt = wx.StaticText(self, -1, 'Orientation:') |
---|
140 | x_orientation_txt = wx.StaticText(self, -1, 'x = ') |
---|
141 | self.x_orientation_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) |
---|
142 | y_orientation_txt = wx.StaticText(self, -1, 'y = ') |
---|
143 | self.y_orientation_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) |
---|
144 | z_orientation_txt = wx.StaticText(self, -1, 'z = ') |
---|
145 | self.z_orientation_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) |
---|
146 | orientation_unit_txt = wx.StaticText(self, -1, 'Unit: ') |
---|
147 | self.orientation_unit_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) |
---|
148 | self.orientation_sizer.AddMany([(orientation_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
149 | (x_orientation_txt, 0, wx.LEFT, 0), |
---|
150 | (self.x_orientation_tcl, 0, wx.RIGHT, 10), |
---|
151 | (y_orientation_txt, 0, wx.EXPAND), |
---|
152 | (self.y_orientation_tcl, 0, wx.RIGHT, 10), |
---|
153 | (z_orientation_txt, 0, wx.EXPAND), |
---|
154 | (self.z_orientation_tcl, 0, wx.RIGHT, 10), |
---|
155 | (orientation_unit_txt, 0, wx.EXPAND), |
---|
156 | (self.orientation_unit_tcl, 0, wx.RIGHT, 10)]) |
---|
157 | |
---|
158 | def _layout_details(self): |
---|
159 | """ |
---|
160 | Do the layout for beam size name related widgets |
---|
161 | """ |
---|
162 | ## Details |
---|
163 | details = None |
---|
164 | details_txt = wx.StaticText(self, -1, 'Details: ') |
---|
165 | self.details_tcl = wx.TextCtrl(self, -1,size=(_BOX_WIDTH*5,_BOX_WIDTH), |
---|
166 | style=wx.TE_MULTILINE | wx.HSCROLL) |
---|
167 | self.details_sizer.AddMany([(details_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
168 | (self.details_tcl, 0, wx.EXPAND)]) |
---|
169 | |
---|
170 | def _layout_button(self): |
---|
171 | """ |
---|
172 | Do the layout for the button widgets |
---|
173 | """ |
---|
174 | self.bt_apply = wx.Button(self, -1,'Apply') |
---|
175 | self.bt_apply.Bind(wx.EVT_BUTTON, self.on_click_apply) |
---|
176 | self.bt_apply.SetToolTipString("Apply current changes to the sample.") |
---|
177 | self.bt_cancel = wx.Button(self, -1,'Cancel') |
---|
178 | self.bt_cancel.SetToolTipString("Cancel current changes.") |
---|
179 | self.bt_cancel.Bind(wx.EVT_BUTTON, self.on_click_cancel) |
---|
180 | self.bt_close = wx.Button(self, wx.ID_CANCEL,'Close') |
---|
181 | self.bt_close.SetToolTipString("Close window.") |
---|
182 | self.button_sizer.AddMany([(self.bt_apply, 0, wx.LEFT, 200), |
---|
183 | (self.bt_cancel, 0, wx.LEFT, 10), |
---|
184 | (self.bt_close, 0, wx.LEFT, 10)]) |
---|
185 | |
---|
186 | def _do_layout(self, data=None): |
---|
187 | """ |
---|
188 | Draw the current panel |
---|
189 | """ |
---|
190 | self._define_structure() |
---|
191 | self._layout_name() |
---|
192 | self._layout_id() |
---|
193 | self._layout_thickness() |
---|
194 | self._layout_transmission() |
---|
195 | self._layout_temperature() |
---|
196 | self._layout_position() |
---|
197 | self._layout_orientation() |
---|
198 | self._layout_details() |
---|
199 | self._layout_button() |
---|
200 | self.boxsizer_sample.AddMany([(self.name_sizer, 0, |
---|
201 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5), |
---|
202 | (self.id_sizer, 0, |
---|
203 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5), |
---|
204 | (self.thickness_sizer, 0, |
---|
205 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5), |
---|
206 | (self.transmission_sizer, 0, |
---|
207 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5), |
---|
208 | (self.temperature_sizer, 0, |
---|
209 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5), |
---|
210 | (self.position_sizer, 0, |
---|
211 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5), |
---|
212 | (self.orientation_sizer, 0, |
---|
213 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5), |
---|
214 | (self.details_sizer, 0, |
---|
215 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5)]) |
---|
216 | self.main_sizer.AddMany([(self.boxsizer_sample, 0, wx.ALL, 10), |
---|
217 | (self.button_sizer, 0, |
---|
218 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5)]) |
---|
219 | |
---|
220 | self.SetSizer(self.main_sizer) |
---|
221 | self.SetAutoLayout(True) |
---|
222 | |
---|
223 | def reset_sample(self): |
---|
224 | """ |
---|
225 | Put initial values of the sample back to the current sample |
---|
226 | """ |
---|
227 | self._sample.name = self._reset_sample.name |
---|
228 | self._sample.ID = self._reset_sample.ID |
---|
229 | self._sample.thickness = self._reset_sample.thickness |
---|
230 | self._sample.thickness_unit = self._reset_sample.thickness_unit |
---|
231 | self._sample.transmission = self._reset_sample.transmission |
---|
232 | self._sample.temperature = self._reset_sample.temperature |
---|
233 | self._sample.temperature_unit = self._reset_sample.temperature_unit |
---|
234 | |
---|
235 | self._sample.position.x = self._reset_sample.position.x |
---|
236 | self._sample.position.y = self._reset_sample.position.y |
---|
237 | self._sample.position.z = self._reset_sample.position.x |
---|
238 | self._sample.position_unit = self._reset_sample.position_unit |
---|
239 | |
---|
240 | self._sample.orientation.x = self._reset_sample.orientation.x |
---|
241 | self._sample.orientation.y = self._reset_sample.orientation.y |
---|
242 | self._sample.orientation.z = self._reset_sample.orientation.x |
---|
243 | self._sample.orientation_unit = self._reset_sample.orientation_unit |
---|
244 | |
---|
245 | self._sample.details = self._reset_sample.details |
---|
246 | |
---|
247 | def set_manager(self, manager): |
---|
248 | """ |
---|
249 | Set manager of this window |
---|
250 | """ |
---|
251 | self.manager = manager |
---|
252 | |
---|
253 | def set_values(self): |
---|
254 | """ |
---|
255 | take the sample values of the current data and display them |
---|
256 | through the panel |
---|
257 | """ |
---|
258 | sample = self._sample |
---|
259 | #Name |
---|
260 | self.sample_name_tcl.SetValue(str(sample.name)) |
---|
261 | #id |
---|
262 | self.id_tcl.SetValue(str(sample.ID)) |
---|
263 | #thickness |
---|
264 | self.thickness_tcl.SetValue(str(sample.thickness)) |
---|
265 | self.thickness_unit_tcl.SetValue(str(sample.thickness_unit)) |
---|
266 | #transmission |
---|
267 | self.transmission_tcl.SetValue(str(sample.transmission)) |
---|
268 | #temperature |
---|
269 | self.temperature_tcl.SetValue(str(sample.temperature)) |
---|
270 | self.temperature_unit_tcl.SetValue(str(sample.temperature_unit)) |
---|
271 | #position |
---|
272 | x, y, z = sample.position.x, sample.position.y , sample.position.z |
---|
273 | self.x_position_tcl.SetValue(str(x)) |
---|
274 | self.y_position_tcl.SetValue(str(y)) |
---|
275 | self.z_position_tcl.SetValue(str(z)) |
---|
276 | self.position_unit_tcl.SetValue(str(sample.position_unit)) |
---|
277 | #orientation |
---|
278 | x, y, z = sample.orientation.x, sample.orientation.y , sample.orientation.z |
---|
279 | self.x_orientation_tcl.SetValue(str(x)) |
---|
280 | self.y_orientation_tcl.SetValue(str(y)) |
---|
281 | self.z_orientation_tcl.SetValue(str(z)) |
---|
282 | self.orientation_unit_tcl.SetValue(str(sample.orientation_unit)) |
---|
283 | |
---|
284 | self.set_details(sample) |
---|
285 | |
---|
286 | def set_details(self, sample): |
---|
287 | """ |
---|
288 | print details on the current sample |
---|
289 | """ |
---|
290 | #detail |
---|
291 | msg = '' |
---|
292 | if sample.details is not None or sample.details: |
---|
293 | for item in sample.details: |
---|
294 | msg += " %s\n" % item |
---|
295 | self.details_tcl.SetValue(str(msg)) |
---|
296 | |
---|
297 | def get_sample(self): |
---|
298 | """ |
---|
299 | return the current sample |
---|
300 | """ |
---|
301 | return self._sample |
---|
302 | |
---|
303 | def get_notes(self): |
---|
304 | """ |
---|
305 | return notes |
---|
306 | """ |
---|
307 | return self._notes |
---|
308 | |
---|
309 | def on_change_name(self): |
---|
310 | """ |
---|
311 | Change name |
---|
312 | """ |
---|
313 | #Change the name of the sample |
---|
314 | name = self.sample_name_tcl.GetValue().lstrip().rstrip() |
---|
315 | if name == "" or name == str(None): |
---|
316 | name = None |
---|
317 | if self._sample.name != name: |
---|
318 | self._notes += "Change sample 's " |
---|
319 | self._notes += "name from %s to %s \n"%(self._sample.name, name) |
---|
320 | self._sample.name = name |
---|
321 | |
---|
322 | def on_change_id(self): |
---|
323 | """ |
---|
324 | Change id of the sample |
---|
325 | """ |
---|
326 | #Change id |
---|
327 | id = self.id_tcl.GetValue().lstrip().rstrip() |
---|
328 | self._sample.ID = id |
---|
329 | self._notes += " Change ID from" |
---|
330 | self._notes += " %s to %s \n"%(self._sample.ID, id) |
---|
331 | |
---|
332 | def on_change_thickness(self): |
---|
333 | """ |
---|
334 | Change thickness |
---|
335 | """ |
---|
336 | #Change thickness |
---|
337 | thickness = self.thickness_tcl.GetValue().lstrip().rstrip() |
---|
338 | self._sample.thickness = thickness |
---|
339 | self._notes += " Change thickness from" |
---|
340 | self._notes += " %s to %s \n"%(self._sample.thickness, thickness) |
---|
341 | |
---|
342 | def on_change_transmission(self): |
---|
343 | """ |
---|
344 | Change transmission |
---|
345 | """ |
---|
346 | #Change transmission |
---|
347 | transmission = self.transmission_tcl.GetValue().lstrip().rstrip() |
---|
348 | if self._sample.transmission != transmission: |
---|
349 | self._notes += " Change transmission from" |
---|
350 | self._notes += " %s to %s \n"%(self._sample.transmission, transmission) |
---|
351 | self._sample.transmission = transmission |
---|
352 | |
---|
353 | def on_change_temperature(self): |
---|
354 | """ |
---|
355 | Change temperature |
---|
356 | """ |
---|
357 | #Change temperature |
---|
358 | temperature = self.temperature_tcl.GetValue().lstrip().rstrip() |
---|
359 | self._sample.temperature = temperature |
---|
360 | self._notes += " Change temperature from" |
---|
361 | self._notes += " %s to %s \n"%(self._sample.temperature, temperature) |
---|
362 | #change temperature unit |
---|
363 | unit = self.temperature_unit_tcl.GetValue().lstrip().rstrip() |
---|
364 | if self._sample.temperature_unit != unit: |
---|
365 | self._notes += " Change temperature's unit from " |
---|
366 | self._notes += "%s to %s"%(self._sample.temperature_unit, unit) |
---|
367 | self._sample.temperature_unit = unit |
---|
368 | |
---|
369 | def on_change_position(self): |
---|
370 | """ |
---|
371 | Change position |
---|
372 | """ |
---|
373 | #Change x coordinate |
---|
374 | x_position = self.x_position_tcl.GetValue().lstrip().rstrip() |
---|
375 | if x_position == "" or x_position == str(None): |
---|
376 | x_position = None |
---|
377 | else: |
---|
378 | if check_float(self.x_position_tcl): |
---|
379 | if self._sample.position.x != float(x_position) : |
---|
380 | self._notes += "Change x of position from " |
---|
381 | self._notes += "%s to %s \n"%(self._sample.position.x, x_position) |
---|
382 | self._sample.position.x = float(x_position) |
---|
383 | else: |
---|
384 | self._notes += "Error: Expected a float for the position 's x " |
---|
385 | self._notes += "won't changes x position from " |
---|
386 | self._notes += "%s to %s"%(self._sample.position.x, x_position) |
---|
387 | #Change y coordinate |
---|
388 | y_position = self.y_position_tcl.GetValue().lstrip().rstrip() |
---|
389 | if y_position == "" or y_position == str(None): |
---|
390 | y_position = None |
---|
391 | self._sample.position.y = y_position |
---|
392 | else: |
---|
393 | if check_float(self.y_position_tcl): |
---|
394 | if self._sample.position.y != float(y_position): |
---|
395 | self._notes += "Change y of position from " |
---|
396 | self._notes += "%s to %s \n"%(self._sample.position.y, y_position) |
---|
397 | self._sample.position.y = float(y_position) |
---|
398 | else: |
---|
399 | self._notes += "Error: Expected a float for the beam size's y " |
---|
400 | self._notes += "won't changes y position from " |
---|
401 | self._notes += "%s to %s"%(self._sample.position.y, y_position) |
---|
402 | #Change z coordinate |
---|
403 | z_position = self.z_position_tcl.GetValue().lstrip().rstrip() |
---|
404 | if z_position == "" or z_position == str(None): |
---|
405 | z_position = None |
---|
406 | self._sample.position.z = z_position |
---|
407 | else: |
---|
408 | if check_float(self.z_position_tcl): |
---|
409 | if self._sample.position.z != float(z_position): |
---|
410 | self._notes += "Change z of position from " |
---|
411 | self._notes += "%s to %s \n"%(self._sample.position.z, z_position) |
---|
412 | self._sample.position.z = float(z_position) |
---|
413 | else: |
---|
414 | self._notes += "Error: Expected a float for position's x " |
---|
415 | self._notes += "won't changes z position from " |
---|
416 | self._notes += "%s to %s"%(self._sample.position.z, z_position) |
---|
417 | #change the beam center unit |
---|
418 | unit = self.position_unit_tcl.GetValue().lstrip().rstrip() |
---|
419 | if self._sample.position_unit != unit: |
---|
420 | self._notes += " Change position's unit from " |
---|
421 | self._notes += "%s to %s"%(self._sample.position_unit, unit) |
---|
422 | |
---|
423 | def on_change_orientation(self): |
---|
424 | """ |
---|
425 | Change orientation |
---|
426 | """ |
---|
427 | #Change x coordinate |
---|
428 | x_orientation = self.x_orientation_tcl.GetValue().lstrip().rstrip() |
---|
429 | if x_orientation == "" or x_orientation == str(None): |
---|
430 | x_orientation = None |
---|
431 | else: |
---|
432 | if check_float(self.x_orientation_tcl): |
---|
433 | if self._sample.orientation.x != float(x_orientation) : |
---|
434 | self._notes += "Change x of orientation from " |
---|
435 | self._notes += "%s to %s \n"%(self._sample.orientation.x, |
---|
436 | x_orientation) |
---|
437 | self._sample.orientation.x = float(x_orientation) |
---|
438 | else: |
---|
439 | self._notes += "Error: Expected a float for orientation 's x " |
---|
440 | self._notes += "won't changes x orientation from " |
---|
441 | self._notes += "%s to %s"%(self._sample.orientation.x, x_orientation) |
---|
442 | #Change y coordinate |
---|
443 | y_orientation = self.y_orientation_tcl.GetValue().lstrip().rstrip() |
---|
444 | if y_orientation == "" or y_orientation == str(None): |
---|
445 | y_orientation = None |
---|
446 | self._sample.orientation.y = y_orientation |
---|
447 | else: |
---|
448 | if check_float(self.y_orientation_tcl): |
---|
449 | if self._sample.orientation.y != float(y_orientation): |
---|
450 | self._notes += "Change y of orientation from " |
---|
451 | self._notes += "%s to %s \n"%(self._sample.orientation.y, y_orientation) |
---|
452 | self._sample.orientation.y = float(y_orientation) |
---|
453 | else: |
---|
454 | self._notes += "Error: Expected a float for orientation's y " |
---|
455 | self._notes += "won't changes y orientation from " |
---|
456 | self._notes += "%s to %s"%(self._sample.orientation.y, y_orientation) |
---|
457 | #Change z coordinate |
---|
458 | z_orientation = self.z_orientation_tcl.GetValue().lstrip().rstrip() |
---|
459 | if z_orientation == "" or z_orientation == str(None): |
---|
460 | z_orientation = None |
---|
461 | self._sample.orientation.z = z_orientation |
---|
462 | else: |
---|
463 | if check_float(self.z_orientation_tcl): |
---|
464 | if self._sample.orientation.z != float(z_orientation): |
---|
465 | self._notes += "Change z of orientation from " |
---|
466 | self._notes += "%s to %s \n"%(self._sample.orientation.z, z_orientation) |
---|
467 | self._sample.orientation.z = float(z_orientation) |
---|
468 | else: |
---|
469 | self._notes += "Error: Expected a float for orientation 's x " |
---|
470 | self._notes += "won't changes z orientation from " |
---|
471 | self._notes += "%s to %s"%(self._sample.orientation.z, z_orientation) |
---|
472 | #change the beam center unit |
---|
473 | unit = self.orientation_unit_tcl.GetValue().lstrip().rstrip() |
---|
474 | if self._sample.orientation_unit != unit: |
---|
475 | self._notes += " Change orientation's unit from " |
---|
476 | self._notes += "%s to %s"%(self._sample.orientation_unit, unit) |
---|
477 | |
---|
478 | def on_change_details(self): |
---|
479 | """ |
---|
480 | Change details |
---|
481 | """ |
---|
482 | #Change details |
---|
483 | details = self.details_tcl.GetValue().lstrip().rstrip() |
---|
484 | msg = "" |
---|
485 | if self._sample.details is not None or self._sample.details: |
---|
486 | for item in self._sample.details: |
---|
487 | if item != details: |
---|
488 | msg += " %s\n" % item |
---|
489 | self._notes += " Change details from" |
---|
490 | self._notes += " %s to %s \n"%(msg, details) |
---|
491 | self._sample.details.append(details) |
---|
492 | |
---|
493 | def on_click_apply(self, event): |
---|
494 | """ |
---|
495 | Apply user values to the sample |
---|
496 | """ |
---|
497 | self.on_change_name() |
---|
498 | self.on_change_id() |
---|
499 | self.on_change_thickness() |
---|
500 | self.on_change_transmission() |
---|
501 | self.on_change_temperature() |
---|
502 | self.on_change_position() |
---|
503 | self.on_change_orientation() |
---|
504 | self.on_change_details() |
---|
505 | self.set_details(self._sample) |
---|
506 | if self.manager is not None: |
---|
507 | self.manager.set_sample(self._sample) |
---|
508 | |
---|
509 | def on_click_cancel(self, event): |
---|
510 | """ |
---|
511 | leave the sample as it is and close |
---|
512 | """ |
---|
513 | self.reset_sample() |
---|
514 | self.set_values() |
---|
515 | if self.manager is not None: |
---|
516 | self.manager.set_sample(self._sample, self._notes) |
---|
517 | |
---|
518 | if __name__ =="__main__": |
---|
519 | |
---|
520 | app = wx.App() |
---|
521 | # Instantiate a loader |
---|
522 | loader = Loader() |
---|
523 | # Load data |
---|
524 | data = loader.load("MAR07232_rest.ASC") |
---|
525 | #print output |
---|
526 | dlg = SampleDialog(sample=data.sample) |
---|
527 | dlg.ShowModal() |
---|
528 | #print dlg.get_sample() |
---|
529 | app.MainLoop() |
---|
530 | |
---|