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 | _BOX_WIDTH = 60 |
---|
8 | |
---|
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 SourceDialog(wx.Dialog): |
---|
21 | def __init__(self, parent=None, manager=None, source=None, *args, **kwds): |
---|
22 | kwds['title'] = "Source Editor" |
---|
23 | kwds['size'] =(PANEL_WIDTH, PANEL_HEIGHT) |
---|
24 | wx.Dialog.__init__(self, parent=parent, *args, **kwds) |
---|
25 | |
---|
26 | self.parent = parent |
---|
27 | self.manager = manager |
---|
28 | self._source = source |
---|
29 | self._reset_source = deepcopy(source) |
---|
30 | self._notes = "" |
---|
31 | self._description = "Edit source" |
---|
32 | self._do_layout() |
---|
33 | self.set_values() |
---|
34 | |
---|
35 | def _define_structure(self): |
---|
36 | """ |
---|
37 | define initial sizer |
---|
38 | """ |
---|
39 | self.main_sizer = wx.BoxSizer(wx.VERTICAL) |
---|
40 | self.box_source = wx.StaticBox(self, -1,str("source")) |
---|
41 | self.boxsizer_source = wx.StaticBoxSizer(self.box_source, |
---|
42 | wx.VERTICAL) |
---|
43 | self.name_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
44 | self.radiation_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
45 | self.beam_shape_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
46 | self.wavelength_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
47 | self.wavelength_min_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
48 | self.wavelength_max_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
49 | self.wavelength_spread_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
50 | self.beam_size_name_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
51 | self.beam_size_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
52 | self.button_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
53 | |
---|
54 | def _layout_name(self): |
---|
55 | """ |
---|
56 | Do the layout for sample name related widgets |
---|
57 | """ |
---|
58 | # Sample name [string] |
---|
59 | sample_name_txt = wx.StaticText(self, -1, 'Sample Name : ') |
---|
60 | self.sample_name_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH*5, 20), style=0) |
---|
61 | self.name_sizer.AddMany([(sample_name_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
62 | (self.sample_name_tcl, 0, wx.EXPAND)]) |
---|
63 | def _layout_radiation(self): |
---|
64 | """ |
---|
65 | Do the layout for radiation related widgets |
---|
66 | """ |
---|
67 | #Radiation type [string] |
---|
68 | radiation_txt = wx.StaticText(self, -1, 'Radiation: ') |
---|
69 | self.radiation_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) |
---|
70 | self.radiation_sizer.AddMany([(radiation_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
71 | (self.radiation_tcl, 0, wx.LEFT, 20)]) |
---|
72 | |
---|
73 | def _layout_beam_shape(self): |
---|
74 | """ |
---|
75 | Do the layout for beam shape related widgets |
---|
76 | """ |
---|
77 | #Beam shape [string] |
---|
78 | beam_shape_txt = wx.StaticText(self, -1, 'Beam shape:') |
---|
79 | self.beam_shape_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) |
---|
80 | self.beam_shape_sizer.AddMany([(beam_shape_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
81 | (self.beam_shape_tcl, 0, wx.LEFT, 10)]) |
---|
82 | |
---|
83 | def _layout_wavelength(self): |
---|
84 | """ |
---|
85 | Do the layout for wavelength related widgets |
---|
86 | """ |
---|
87 | #Wavelength [float] [Angstrom] |
---|
88 | wavelength_txt = wx.StaticText(self, -1, 'wavelength:') |
---|
89 | self.wavelength_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) |
---|
90 | wavelength_unit_txt = wx.StaticText(self, -1, 'Unit: ') |
---|
91 | self.wavelength_unit_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20),style=0) |
---|
92 | self.wavelength_sizer.AddMany([(wavelength_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
93 | (self.wavelength_tcl, 0, wx.LEFT, 12), |
---|
94 | (wavelength_unit_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
95 | (self.wavelength_unit_tcl, 0, wx.EXPAND)]) |
---|
96 | |
---|
97 | def _layout_wavelength_min(self): |
---|
98 | """ |
---|
99 | Do the layout for wavelength min related widgets |
---|
100 | """ |
---|
101 | #Minimum wavelength [float] [Angstrom] |
---|
102 | wavelength_min_txt = wx.StaticText(self, -1, 'Wavelength min:') |
---|
103 | self.wavelength_min_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) |
---|
104 | wavelength_min_unit_txt = wx.StaticText(self, -1, 'Unit: ') |
---|
105 | self.wavelength_min_unit_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20),style=0) |
---|
106 | self.wavelength_min_sizer.AddMany([(wavelength_min_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
107 | (self.wavelength_min_tcl, 0, wx.LEFT, 10), |
---|
108 | (wavelength_min_unit_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
109 | (self.wavelength_min_unit_tcl, 0, wx.EXPAND)]) |
---|
110 | |
---|
111 | def _layout_wavelength_max(self): |
---|
112 | """ |
---|
113 | Do the layout for wavelength max related widgets |
---|
114 | """ |
---|
115 | #Maximum wavelength [float] [Angstrom] |
---|
116 | wavelength_max_txt = wx.StaticText(self, -1, 'Wavelength max:') |
---|
117 | self.wavelength_max_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) |
---|
118 | wavelength_max_unit_txt = wx.StaticText(self, -1, 'Unit: ') |
---|
119 | self.wavelength_max_unit_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20),style=0) |
---|
120 | self.wavelength_max_sizer.AddMany([(wavelength_max_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
121 | (self.wavelength_max_tcl, 0, wx.LEFT, 7), |
---|
122 | (wavelength_max_unit_txt, 0,wx.LEFT|wx.RIGHT, 10), |
---|
123 | (self.wavelength_max_unit_tcl, 0, wx.EXPAND)]) |
---|
124 | |
---|
125 | def _layout_wavelength_spread(self): |
---|
126 | """ |
---|
127 | Do the layout for wavelength spread related widgets |
---|
128 | """ |
---|
129 | ## Wavelength spread [float] [Angstrom] |
---|
130 | wavelength_spread = None |
---|
131 | wavelength_spread_unit = 'percent' |
---|
132 | wavelength_spread_txt = wx.StaticText(self, -1, 'Wavelength spread:') |
---|
133 | self.wavelength_spread_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) |
---|
134 | wavelength_spread_unit_txt = wx.StaticText(self, -1, 'Unit: ') |
---|
135 | self.wavelength_spread_unit_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20),style=0) |
---|
136 | self.wavelength_spread_sizer.AddMany([(wavelength_spread_txt, 0, wx.LEFT, 10), |
---|
137 | (self.wavelength_spread_tcl, 0, wx.LEFT, 5), |
---|
138 | (wavelength_spread_unit_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
139 | (self.wavelength_spread_unit_tcl, 0, wx.EXPAND)]) |
---|
140 | def _layout_beam_size_name(self): |
---|
141 | """ |
---|
142 | Do the layout for beam size name related widgets |
---|
143 | """ |
---|
144 | # Beam size name [string] |
---|
145 | beam_size_name_txt = wx.StaticText(self, -1, 'Beam size name : ') |
---|
146 | self.beam_size_name_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH*5, 20), style=0) |
---|
147 | self.beam_size_name_sizer.AddMany([(beam_size_name_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
148 | (self.beam_size_name_tcl, 0, wx.EXPAND)]) |
---|
149 | |
---|
150 | def _layout_beam_size(self): |
---|
151 | """ |
---|
152 | Do the layout for beam size related widgets |
---|
153 | """ |
---|
154 | ## Beam size [Vector] [mm] |
---|
155 | beam_size = None |
---|
156 | beam_size_unit = 'mm' |
---|
157 | |
---|
158 | beam_size_txt = wx.StaticText(self, -1, 'Beam size:') |
---|
159 | x_beam_size_txt = wx.StaticText(self, -1, 'x = ') |
---|
160 | self.x_beam_size_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) |
---|
161 | y_beam_size_txt = wx.StaticText(self, -1, 'y = ') |
---|
162 | self.y_beam_size_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) |
---|
163 | z_beam_size_txt = wx.StaticText(self, -1, 'z = ') |
---|
164 | self.z_beam_size_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) |
---|
165 | beam_size_unit_txt = wx.StaticText(self, -1, 'Unit: ') |
---|
166 | self.beam_size_unit_tcl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=0) |
---|
167 | self.beam_size_sizer.AddMany([(beam_size_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
168 | (x_beam_size_txt, 0, wx.LEFT, 17), |
---|
169 | (self.x_beam_size_tcl, 0, wx.RIGHT, 10), |
---|
170 | (y_beam_size_txt, 0, wx.EXPAND), |
---|
171 | (self.y_beam_size_tcl, 0, wx.RIGHT, 10), |
---|
172 | (z_beam_size_txt, 0, wx.EXPAND), |
---|
173 | (self.z_beam_size_tcl, 0, wx.RIGHT, 10), |
---|
174 | (beam_size_unit_txt, 0, wx.EXPAND), |
---|
175 | (self.beam_size_unit_tcl, 0, wx.RIGHT, 10)]) |
---|
176 | |
---|
177 | def _layout_button(self): |
---|
178 | """ |
---|
179 | Do the layout for the button widgets |
---|
180 | """ |
---|
181 | self.bt_apply = wx.Button(self, -1,'Apply') |
---|
182 | self.bt_apply.Bind(wx.EVT_BUTTON, self.on_click_apply) |
---|
183 | self.bt_apply.SetToolTipString("Apply current changes to the source.") |
---|
184 | self.bt_cancel = wx.Button(self, -1,'Cancel') |
---|
185 | self.bt_cancel.SetToolTipString("Cancel current changes.") |
---|
186 | self.bt_cancel.Bind(wx.EVT_BUTTON, self.on_click_cancel) |
---|
187 | self.bt_close = wx.Button(self, wx.ID_CANCEL,'Close') |
---|
188 | self.bt_close.SetToolTipString("Close window.") |
---|
189 | self.button_sizer.AddMany([(self.bt_apply, 0, wx.LEFT, 200), |
---|
190 | (self.bt_cancel, 0, wx.LEFT, 10), |
---|
191 | (self.bt_close, 0, wx.LEFT, 10)]) |
---|
192 | |
---|
193 | def _do_layout(self, data=None): |
---|
194 | """ |
---|
195 | Draw the current panel |
---|
196 | """ |
---|
197 | self._define_structure() |
---|
198 | self._layout_name() |
---|
199 | self._layout_radiation() |
---|
200 | self._layout_beam_shape() |
---|
201 | self._layout_wavelength() |
---|
202 | self._layout_wavelength_min() |
---|
203 | self._layout_wavelength_max() |
---|
204 | self._layout_wavelength_spread() |
---|
205 | self._layout_beam_size_name() |
---|
206 | self._layout_beam_size() |
---|
207 | self._layout_button() |
---|
208 | |
---|
209 | self.boxsizer_source.AddMany([(self.name_sizer, 0, |
---|
210 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5), |
---|
211 | (self.radiation_sizer, 0, |
---|
212 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5), |
---|
213 | (self.beam_shape_sizer, 0, |
---|
214 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5), |
---|
215 | (self.wavelength_sizer, 0, |
---|
216 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5), |
---|
217 | (self.wavelength_min_sizer, 0, |
---|
218 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5), |
---|
219 | (self.wavelength_max_sizer, 0, |
---|
220 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5), |
---|
221 | (self.wavelength_spread_sizer, 0, |
---|
222 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5), |
---|
223 | (self.beam_size_name_sizer, 0, |
---|
224 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5), |
---|
225 | (self.beam_size_sizer, 0, |
---|
226 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5)]) |
---|
227 | self.main_sizer.AddMany([(self.boxsizer_source, 0, wx.ALL, 10), |
---|
228 | (self.button_sizer, 0, |
---|
229 | wx.EXPAND|wx.TOP|wx.BOTTOM, 5)]) |
---|
230 | |
---|
231 | self.SetSizer(self.main_sizer) |
---|
232 | self.SetAutoLayout(True) |
---|
233 | |
---|
234 | def set_manager(self, manager): |
---|
235 | """ |
---|
236 | Set manager of this window |
---|
237 | """ |
---|
238 | self.manager = manager |
---|
239 | |
---|
240 | def reset_source(self): |
---|
241 | """ |
---|
242 | put back initial values of the source |
---|
243 | """ |
---|
244 | self._source.name = self._reset_source.name |
---|
245 | self._source.radiation = self._reset_source.radiation |
---|
246 | self._source.beam_size_name = self._reset_source.beam_size_name |
---|
247 | |
---|
248 | self._source.beam_size.x = self._reset_source.beam_size.x |
---|
249 | self._source.beam_size.y = self._reset_source.beam_size.y |
---|
250 | self._source.beam_size.z = self._reset_source.beam_size.z |
---|
251 | self._source.beam_size_unit = self._reset_source.beam_size_unit |
---|
252 | |
---|
253 | self._source.beam_shape = self._reset_source.beam_shape |
---|
254 | self._source.wavelength = self._reset_source.wavelength |
---|
255 | self._source.wavelength_unit = self._reset_source.wavelength_unit |
---|
256 | ## Minimum wavelength [float] [Angstrom] |
---|
257 | self._source.wavelength_min = self._reset_source.wavelength_min |
---|
258 | self._source.wavelength_min_unit = self._reset_source.wavelength_min_unit |
---|
259 | |
---|
260 | self._source.wavelength_max = self._reset_source.wavelength_max |
---|
261 | self._source.wavelength_max_unit = self._reset_source.wavelength_max_unit |
---|
262 | |
---|
263 | self._source.wavelength_spread = self._reset_source.wavelength_spread |
---|
264 | self._source.wavelength_spread_unit = self._reset_source.wavelength_spread_unit |
---|
265 | |
---|
266 | def set_values(self): |
---|
267 | """ |
---|
268 | take the source values of the current data and display them |
---|
269 | through the panel |
---|
270 | """ |
---|
271 | source = self._source |
---|
272 | #Name |
---|
273 | self.sample_name_tcl.SetValue(str(source.name)) |
---|
274 | #Radiation |
---|
275 | self.radiation_tcl.SetValue(str(source.radiation)) |
---|
276 | #Beam shape |
---|
277 | self.beam_shape_tcl.SetValue(str(source.beam_shape)) |
---|
278 | #Wavelength |
---|
279 | self.wavelength_tcl.SetValue(str(source.wavelength)) |
---|
280 | self.wavelength_unit_tcl.SetValue(str(source.wavelength_unit)) |
---|
281 | #Wavelength min |
---|
282 | self.wavelength_min_tcl.SetValue(str(source.wavelength_min)) |
---|
283 | self.wavelength_min_unit_tcl.SetValue(str(source.wavelength_min_unit)) |
---|
284 | #Wavelength max |
---|
285 | self.wavelength_max_tcl.SetValue(str(source.wavelength_max)) |
---|
286 | self.wavelength_max_unit_tcl.SetValue(str(source.wavelength_max_unit)) |
---|
287 | #Wavelength spread |
---|
288 | self.wavelength_spread_tcl.SetValue(str(source.wavelength_spread)) |
---|
289 | self.wavelength_spread_unit_tcl.SetValue(str(source.wavelength_spread_unit)) |
---|
290 | #Beam size |
---|
291 | self.beam_size_name_tcl.SetValue(str(source.beam_size_name)) |
---|
292 | x, y, z = source.beam_size.x, source.beam_size.y , source.beam_size.z |
---|
293 | self.x_beam_size_tcl.SetValue(str(x)) |
---|
294 | self.y_beam_size_tcl.SetValue(str(y)) |
---|
295 | self.z_beam_size_tcl.SetValue(str(z)) |
---|
296 | self.beam_size_unit_tcl.SetValue(str(source.beam_size_unit)) |
---|
297 | |
---|
298 | def get_source(self): |
---|
299 | """ |
---|
300 | return the current source |
---|
301 | """ |
---|
302 | return self._source |
---|
303 | |
---|
304 | def get_notes(self): |
---|
305 | """ |
---|
306 | return notes |
---|
307 | """ |
---|
308 | return self._notes |
---|
309 | |
---|
310 | def on_change_name(self): |
---|
311 | """ |
---|
312 | Change name |
---|
313 | """ |
---|
314 | #Change the name of the source |
---|
315 | name = self.sample_name_tcl.GetValue().lstrip().rstrip() |
---|
316 | if name == "" or name == str(None): |
---|
317 | name = None |
---|
318 | if self._source.name != name: |
---|
319 | self._notes += "Change sample 's " |
---|
320 | self._notes += "name from %s to %s \n"%(self._source.name, name) |
---|
321 | self._source.name = name |
---|
322 | |
---|
323 | def on_change_radiation(self): |
---|
324 | """ |
---|
325 | Change radiation of the sample |
---|
326 | """ |
---|
327 | #Change radiation |
---|
328 | radiation = self.radiation_tcl.GetValue().lstrip().rstrip() |
---|
329 | self._source.radiation = radiation |
---|
330 | self._notes += " Change radiation from" |
---|
331 | self._notes += " %s to %s \n"%(self._source.radiation, radiation) |
---|
332 | |
---|
333 | def on_change_beam_shape(self): |
---|
334 | """ |
---|
335 | Change beams shape |
---|
336 | """ |
---|
337 | #Change beam shape |
---|
338 | beam_shape = self.beam_shape_tcl.GetValue().lstrip().rstrip() |
---|
339 | self._source.beam_shape = beam_shape |
---|
340 | self._notes += " Change beam shape from" |
---|
341 | self._notes += " %s to %s \n"%(self._source.beam_shape, beam_shape) |
---|
342 | |
---|
343 | def on_change_wavelength(self): |
---|
344 | """ |
---|
345 | Change the wavelength |
---|
346 | """ |
---|
347 | #Change wavelength |
---|
348 | wavelength = self.wavelength_tcl.GetValue().lstrip().rstrip() |
---|
349 | self._source.wavelength = wavelength |
---|
350 | self._notes += " Change wavelength from" |
---|
351 | self._notes += " %s to %s \n"%(self._source.wavelength, wavelength) |
---|
352 | #change the wavelength unit |
---|
353 | unit = self.wavelength_unit_tcl.GetValue().lstrip().rstrip() |
---|
354 | if self._source.wavelength_unit != unit: |
---|
355 | self._notes += " Change wavelength's unit from " |
---|
356 | self._notes += "%s to %s"%(self._source.wavelength_unit, unit) |
---|
357 | |
---|
358 | def on_change_wavelength_min(self): |
---|
359 | """ |
---|
360 | Change the wavelength minimum |
---|
361 | """ |
---|
362 | #Change wavelength min |
---|
363 | wavelength_min = self.wavelength_min_tcl.GetValue().lstrip().rstrip() |
---|
364 | self._source.wavelength_min = wavelength_min |
---|
365 | self._notes += " Change wavelength min from" |
---|
366 | self._notes += " %s to %s \n"%(self._source.wavelength_min, wavelength_min) |
---|
367 | #change the wavelength min unit |
---|
368 | unit = self.wavelength_min_unit_tcl.GetValue().lstrip().rstrip() |
---|
369 | if self._source.wavelength_min_unit != unit: |
---|
370 | self._notes += " Change wavelength min's unit from " |
---|
371 | self._notes += "%s to %s"%(self._source.wavelength_min_unit, unit) |
---|
372 | |
---|
373 | def on_change_wavelength_max(self): |
---|
374 | """ |
---|
375 | Change the wavelength maximum |
---|
376 | """ |
---|
377 | #Change wavelength max |
---|
378 | wavelength_max = self.wavelength_max_tcl.GetValue().lstrip().rstrip() |
---|
379 | self._source.wavelength_max = wavelength_max |
---|
380 | self._notes += " Change wavelength max from" |
---|
381 | self._notes += " %s to %s \n"%(self._source.wavelength_max, wavelength_max) |
---|
382 | #change the wavelength max unit |
---|
383 | unit = self.wavelength_max_unit_tcl.GetValue().lstrip().rstrip() |
---|
384 | if self._source.wavelength_max_unit != unit: |
---|
385 | self._notes += " Change wavelength max's unit from " |
---|
386 | self._notes += "%s to %s"%(self._source.wavelength_max_unit, unit) |
---|
387 | |
---|
388 | def on_change_wavelength_spread(self): |
---|
389 | """ |
---|
390 | Change the wavelength spread |
---|
391 | """ |
---|
392 | #Change wavelength spread |
---|
393 | wavelength_spread = self.wavelength_spread_tcl.GetValue().lstrip().rstrip() |
---|
394 | self._notes += " Change wavelength spread from" |
---|
395 | self._notes += " %s to %s \n"%(self._source.wavelength_spread, wavelength_spread) |
---|
396 | self._source.wavelength_spread = wavelength_spread |
---|
397 | #change the wavelength spread unit |
---|
398 | unit = self.wavelength_spread_unit_tcl.GetValue().lstrip().rstrip() |
---|
399 | if self._source.wavelength_spread_unit != unit: |
---|
400 | self._notes += " Change wavelength spread's unit from " |
---|
401 | self._notes += "%s to %s"%(self._source.wavelength_spread_unit, unit) |
---|
402 | self._source.wavelength_spread_unit = unit |
---|
403 | |
---|
404 | def on_change_beam_size_name(self): |
---|
405 | """ |
---|
406 | Change beam size name |
---|
407 | """ |
---|
408 | #Change beam size name |
---|
409 | name = self.beam_size_name_tcl.GetValue().lstrip().rstrip() |
---|
410 | if name == "" or name == str(None): |
---|
411 | name = None |
---|
412 | if self._source.beam_size_name != name: |
---|
413 | self._notes += "Change beam size 's " |
---|
414 | self._notes += "name from %s to %s \n"%(self._source.beam_size_name, name) |
---|
415 | self._source.name = name |
---|
416 | |
---|
417 | def on_change_beam_size(self): |
---|
418 | """ |
---|
419 | Change beam size |
---|
420 | """ |
---|
421 | #Change x coordinate |
---|
422 | x_beam_size = self.x_beam_size_tcl.GetValue().lstrip().rstrip() |
---|
423 | if x_beam_size == "" or x_beam_size == str(None): |
---|
424 | x_beam_size = None |
---|
425 | else: |
---|
426 | if check_float(self.x_beam_size_tcl): |
---|
427 | if self._source.beam_size.x != float(x_beam_size) : |
---|
428 | self._notes += "Change x of beam size from " |
---|
429 | self._notes += "%s to %s \n"%(self._source.beam_size.x, x_beam_size) |
---|
430 | self._source.beam_size.x = float(x_beam_size) |
---|
431 | else: |
---|
432 | self._notes += "Error: Expected a float for the beam size 's x " |
---|
433 | self._notes += "won't changes x beam size from " |
---|
434 | self._notes += "%s to %s"%(self._source.beam_size.x, x_beam_size) |
---|
435 | #Change y coordinate |
---|
436 | y_beam_size = self.y_beam_size_tcl.GetValue().lstrip().rstrip() |
---|
437 | if y_beam_size == "" or y_beam_size == str(None): |
---|
438 | y_beam_size = None |
---|
439 | self._source.beam_size.y = y_beam_size |
---|
440 | else: |
---|
441 | if check_float(self.y_beam_size_tcl): |
---|
442 | if self._source.beam_size.y != float(y_beam_size): |
---|
443 | self._notes += "Change y of beam size from " |
---|
444 | self._notes += "%s to %s \n"%(self._source.beam_size.y, y_beam_size) |
---|
445 | self._source.beam_size.y = float(y_beam_size) |
---|
446 | else: |
---|
447 | self._notes += "Error: Expected a float for the beam size's y " |
---|
448 | self._notes += "won't changes y beam size from " |
---|
449 | self._notes += "%s to %s"%(self._source.beam_size.y, y_beam_size) |
---|
450 | #Change z coordinate |
---|
451 | z_beam_size = self.z_beam_size_tcl.GetValue().lstrip().rstrip() |
---|
452 | if z_beam_size == "" or z_beam_size == str(None): |
---|
453 | z_beam_size = None |
---|
454 | self._source.beam_size.z = z_beam_size |
---|
455 | else: |
---|
456 | if check_float(self.z_beam_size_tcl): |
---|
457 | if self._source.beam_size.z != float(z_beam_size): |
---|
458 | self._notes += "Change z of beam size from " |
---|
459 | self._notes += "%s to %s \n"%(self._source.beam_size.z, z_beam_size) |
---|
460 | self._source.beam_size.z = float(z_beam_size) |
---|
461 | else: |
---|
462 | self._notes += "Error: Expected a float for the beam size 's z " |
---|
463 | self._notes += "won't changes z beam size from " |
---|
464 | self._notes += "%s to %s"%(self._source.beam_size.z, z_beam_size) |
---|
465 | #change the beam center unit |
---|
466 | unit = self.beam_size_unit_tcl.GetValue().lstrip().rstrip() |
---|
467 | if self._source.beam_size_unit != unit: |
---|
468 | self._notes += " Change beam size's unit from " |
---|
469 | self._notes += "%s to %s"%(self._source.beam_size_unit, unit) |
---|
470 | self._source.beam_size_unit = unit |
---|
471 | |
---|
472 | def on_click_apply(self, event): |
---|
473 | """ |
---|
474 | Apply user values to the source |
---|
475 | """ |
---|
476 | self.on_change_name() |
---|
477 | self.on_change_radiation() |
---|
478 | self.on_change_beam_shape() |
---|
479 | self.on_change_wavelength() |
---|
480 | self.on_change_wavelength_min() |
---|
481 | self.on_change_wavelength_max() |
---|
482 | self.on_change_wavelength_spread() |
---|
483 | self.on_change_beam_size_name() |
---|
484 | self.on_change_beam_size() |
---|
485 | if self.manager is not None: |
---|
486 | self.manager.set_source(self._source, self._notes) |
---|
487 | |
---|
488 | def on_click_cancel(self, event): |
---|
489 | """ |
---|
490 | reset the current source |
---|
491 | """ |
---|
492 | self.reset_source() |
---|
493 | self.set_values() |
---|
494 | if self.manager is not None: |
---|
495 | self.manager.set_source(self._source) |
---|
496 | |
---|
497 | if __name__ =="__main__": |
---|
498 | app = wx.App() |
---|
499 | # Instantiate a loader |
---|
500 | loader = Loader() |
---|
501 | # Load data |
---|
502 | data = loader.load("MAR07232_rest.ASC") |
---|
503 | dlg = SourceDialog(source=data.source) |
---|
504 | dlg.ShowModal() |
---|
505 | app.MainLoop() |
---|
506 | |
---|