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