1 | """ |
---|
2 | This module provide GUI for the neutron scattering length density calculator |
---|
3 | |
---|
4 | """ |
---|
5 | import copy |
---|
6 | import time |
---|
7 | import sys |
---|
8 | import os |
---|
9 | import wx |
---|
10 | from wx.lib.scrolledpanel import ScrolledPanel |
---|
11 | from sans.invariant import invariant |
---|
12 | from sans.guiframe.utils import format_number |
---|
13 | from sans.guiframe.utils import check_float |
---|
14 | from sans.guiframe.events import StatusEvent |
---|
15 | from sans.guiframe.events import AppendBookmarkEvent |
---|
16 | from .invariant_details import InvariantDetailsPanel |
---|
17 | from .invariant_details import InvariantContainer |
---|
18 | from .invariant_widgets import OutputTextCtrl |
---|
19 | from .invariant_widgets import InvTextCtrl |
---|
20 | from .invariant_state import InvariantState as IState |
---|
21 | from sans.guiframe.panel_base import PanelBase |
---|
22 | # The minimum q-value to be used when extrapolating |
---|
23 | Q_MINIMUM = 1e-5 |
---|
24 | # The maximum q-value to be used when extrapolating |
---|
25 | Q_MAXIMUM = 10 |
---|
26 | # the ratio of maximum q value/(qmax of data) to plot the theory data |
---|
27 | Q_MAXIMUM_PLOT = 3 |
---|
28 | # the number of points to consider during fit |
---|
29 | NPTS = 10 |
---|
30 | #Default value for background |
---|
31 | BACKGROUND = 0.0 |
---|
32 | #default value for the scale |
---|
33 | SCALE = 1.0 |
---|
34 | #default value of the contrast |
---|
35 | CONTRAST = 1.0 |
---|
36 | #default value of the power used for power law |
---|
37 | POWER = 4.0 |
---|
38 | #Invariant panel size |
---|
39 | _BOX_WIDTH = 76 |
---|
40 | |
---|
41 | |
---|
42 | if sys.platform.count("win32") > 0: |
---|
43 | _STATICBOX_WIDTH = 420 |
---|
44 | PANEL_WIDTH = 500 |
---|
45 | PANEL_HEIGHT = 700 |
---|
46 | FONT_VARIANT = 0 |
---|
47 | else: |
---|
48 | _STATICBOX_WIDTH = 450 |
---|
49 | PANEL_WIDTH = 530 |
---|
50 | PANEL_HEIGHT = 700 |
---|
51 | FONT_VARIANT = 1 |
---|
52 | |
---|
53 | |
---|
54 | class InvariantPanel(ScrolledPanel, PanelBase): |
---|
55 | """ |
---|
56 | Provides the Invariant GUI. |
---|
57 | """ |
---|
58 | ## Internal nickname for the window, used by the AUI manager |
---|
59 | window_name = "Invariant" |
---|
60 | ## Name to appear on the window title bar |
---|
61 | window_caption = "Invariant" |
---|
62 | ## Flag to tell the AUI manager to put this panel in the center pane |
---|
63 | CENTER_PANE = True |
---|
64 | def __init__(self, parent, data=None, manager=None, *args, **kwds): |
---|
65 | kwds["size"] = (PANEL_WIDTH, PANEL_HEIGHT) |
---|
66 | kwds["style"] = wx.FULL_REPAINT_ON_RESIZE |
---|
67 | ScrolledPanel.__init__(self, parent=parent, *args, **kwds) |
---|
68 | PanelBase.__init__(self, parent) |
---|
69 | self.SetupScrolling() |
---|
70 | #Font size |
---|
71 | self.SetWindowVariant(variant=FONT_VARIANT) |
---|
72 | #Object that receive status event |
---|
73 | self.parent = parent |
---|
74 | #plug-in using this panel |
---|
75 | self._manager = manager |
---|
76 | #Data uses for computation |
---|
77 | self._data = data |
---|
78 | self._scale = SCALE |
---|
79 | self._background = BACKGROUND |
---|
80 | self._bmark = None |
---|
81 | self.bookmark_num = 0 |
---|
82 | |
---|
83 | self._set_bookmark_menu() |
---|
84 | #Init state |
---|
85 | self.set_state() |
---|
86 | # default flags for state |
---|
87 | self.new_state = False |
---|
88 | self.is_state_data = False |
---|
89 | self.is_power_out = False |
---|
90 | |
---|
91 | #container of invariant value |
---|
92 | self.inv_container = None |
---|
93 | #Draw the panel |
---|
94 | self._do_layout() |
---|
95 | self.reset_panel() |
---|
96 | self._reset_state_list() |
---|
97 | ## Default file location for save |
---|
98 | self._default_save_location = os.getcwd() |
---|
99 | if self.parent is not None: |
---|
100 | msg = "" |
---|
101 | wx.PostEvent(self.parent,StatusEvent(status=msg, info="info")) |
---|
102 | self._default_save_location =\ |
---|
103 | self.parent._default_save_location |
---|
104 | |
---|
105 | self._set_bookmark_flag(False) |
---|
106 | |
---|
107 | def get_data(self): |
---|
108 | """ |
---|
109 | """ |
---|
110 | return self._manager.get_data() |
---|
111 | |
---|
112 | def get_state(self): |
---|
113 | """ |
---|
114 | """ |
---|
115 | return self.state |
---|
116 | |
---|
117 | def set_data(self, data): |
---|
118 | """ |
---|
119 | Set the data |
---|
120 | """ |
---|
121 | self._data = data |
---|
122 | #edit the panel |
---|
123 | if self._data is not None: |
---|
124 | self._delete_bookmark_items() |
---|
125 | self.get_state_by_num(0) |
---|
126 | data_name = self._data.name |
---|
127 | data_qmin = min (self._data.x) |
---|
128 | data_qmax = max (self._data.x) |
---|
129 | self.data_name_tcl.SetValue(str(data_name)) |
---|
130 | self.data_min_tcl.SetValue(str(data_qmin)) |
---|
131 | self.data_max_tcl.SetValue(str(data_qmax)) |
---|
132 | self.reset_panel() |
---|
133 | self.compute_invariant(event=None) |
---|
134 | self.state.file = self._data.name |
---|
135 | #Reset the list of states |
---|
136 | self.state.data = copy.deepcopy(data) |
---|
137 | self._set_save_flag(True) |
---|
138 | self._set_preview_flag(False) |
---|
139 | self._reset_state_list() |
---|
140 | self._set_bookmark_flag(True) |
---|
141 | return True |
---|
142 | |
---|
143 | def _delete_bookmark_items(self): |
---|
144 | """ |
---|
145 | Delete bookmark menu items |
---|
146 | """ |
---|
147 | # delete toolbar menu |
---|
148 | self.parent.reset_bookmark_menu(self) |
---|
149 | self.parent._update_toolbar_helper() |
---|
150 | # delete popUpMenu items |
---|
151 | pos = 0 |
---|
152 | for item in self.popUpMenu.GetMenuItems(): |
---|
153 | pos += 1 |
---|
154 | if pos < 3: |
---|
155 | continue |
---|
156 | self.popUpMenu.DestroyItem(item) |
---|
157 | |
---|
158 | def set_message(self): |
---|
159 | """ |
---|
160 | Display warning message if available |
---|
161 | """ |
---|
162 | if self.inv_container is not None: |
---|
163 | if self.inv_container.existing_warning: |
---|
164 | msg = "Warning! Computations on invariant require your " |
---|
165 | msg += "attention.\n Please click on Details button." |
---|
166 | self.hint_msg_txt.SetForegroundColour("red") |
---|
167 | |
---|
168 | wx.PostEvent(self.parent, |
---|
169 | StatusEvent(status=msg,info="warning")) |
---|
170 | else: |
---|
171 | msg = "For more information, click on Details button." |
---|
172 | self.hint_msg_txt.SetForegroundColour("black") |
---|
173 | wx.PostEvent(self.parent, |
---|
174 | StatusEvent(status=msg,info="info")) |
---|
175 | self.hint_msg_txt.SetLabel(msg) |
---|
176 | |
---|
177 | |
---|
178 | def set_manager(self, manager): |
---|
179 | """ |
---|
180 | set value for the manager |
---|
181 | """ |
---|
182 | self._manager = manager |
---|
183 | |
---|
184 | def save_project(self, doc=None): |
---|
185 | """ |
---|
186 | return an xml node containing state of the panel |
---|
187 | that guiframe can write to file |
---|
188 | """ |
---|
189 | data = self.get_data() |
---|
190 | state = self.get_state() |
---|
191 | if data is not None: |
---|
192 | new_doc = self._manager.state_reader.write_toXML(data, state) |
---|
193 | if new_doc is not None: |
---|
194 | if doc is not None and hasattr(doc, "firstChild"): |
---|
195 | child = new_doc.firstChild.firstChild |
---|
196 | doc.firstChild.appendChild(child) |
---|
197 | else: |
---|
198 | doc = new_doc |
---|
199 | return doc |
---|
200 | |
---|
201 | def set_state(self,state=None,data=None): |
---|
202 | """ |
---|
203 | set state when loading it from a .inv/.svs file |
---|
204 | """ |
---|
205 | |
---|
206 | if state == None and data == None: |
---|
207 | self.state = IState() |
---|
208 | elif state == None or data == None: return |
---|
209 | else: |
---|
210 | new_state = copy.deepcopy(state) |
---|
211 | self.new_state = True |
---|
212 | if not self.set_data(data): |
---|
213 | return |
---|
214 | |
---|
215 | self.state = new_state |
---|
216 | self.state.file = data.name |
---|
217 | |
---|
218 | num = self.state.saved_state['state_num'] |
---|
219 | if num > 0 : |
---|
220 | self._set_undo_flag(True) |
---|
221 | if num < len(state.state_list) - 1: |
---|
222 | self._set_redo_flag(True) |
---|
223 | |
---|
224 | # get bookmarks |
---|
225 | self.bookmark_num = len(self.state.bookmark_list) |
---|
226 | total_bookmark_num = self.bookmark_num + 1 |
---|
227 | |
---|
228 | for ind in range(1,total_bookmark_num): |
---|
229 | #bookmark_num = ind |
---|
230 | value = self.state.bookmark_list[ind] |
---|
231 | name = "%d] bookmarked at %s on %s"% (ind,value[0], value[1]) |
---|
232 | # append it to menu |
---|
233 | id = wx.NewId() |
---|
234 | self.popUpMenu.Append(id,name,str('')) |
---|
235 | wx.EVT_MENU(self, id, self._back_to_bookmark) |
---|
236 | wx.PostEvent(self.parent, AppendBookmarkEvent(title=name, |
---|
237 | hint='', |
---|
238 | handler=self._back_to_bookmark)) |
---|
239 | |
---|
240 | self.get_state_by_num(state_num=str(num)) |
---|
241 | |
---|
242 | self._get_input_list() |
---|
243 | #make sure that the data is reset (especially |
---|
244 | # when loaded from a inv file) |
---|
245 | self.state.data = self._data |
---|
246 | self._set_preview_flag(False) |
---|
247 | self.new_state = False |
---|
248 | self.is_state_data = False |
---|
249 | |
---|
250 | def clear_panel(self): |
---|
251 | """ |
---|
252 | Clear panel to defaults, used by set_state of manager |
---|
253 | """ |
---|
254 | |
---|
255 | self._data = None |
---|
256 | # default data testctrl |
---|
257 | self.hint_msg_txt.SetLabel('') |
---|
258 | data_name = '' |
---|
259 | data_qmin = '' |
---|
260 | data_qmax = '' |
---|
261 | self.data_name_tcl.SetValue(str(data_name)) |
---|
262 | self.data_min_tcl.SetValue(str(data_qmin)) |
---|
263 | self.data_max_tcl.SetValue(str(data_qmax)) |
---|
264 | #reset output textctrl |
---|
265 | self._reset_output() |
---|
266 | #reset panel |
---|
267 | self.reset_panel() |
---|
268 | #reset state w/o data |
---|
269 | self.set_state() |
---|
270 | # default flags for state |
---|
271 | self.new_state = False |
---|
272 | self.is_state_data = False |
---|
273 | self.is_power_out = False |
---|
274 | |
---|
275 | def get_background(self): |
---|
276 | """ |
---|
277 | return the background textcrtl value as a float |
---|
278 | """ |
---|
279 | background = self.background_tcl.GetValue().lstrip().rstrip() |
---|
280 | if background == "": |
---|
281 | raise ValueError, "Need a background" |
---|
282 | if check_float(self.background_tcl): |
---|
283 | return float(background) |
---|
284 | else: |
---|
285 | msg = "Receive invalid value for background : %s" % (background) |
---|
286 | raise ValueError, msg |
---|
287 | |
---|
288 | def get_scale(self): |
---|
289 | """ |
---|
290 | return the scale textcrtl value as a float |
---|
291 | """ |
---|
292 | scale = self.scale_tcl.GetValue().lstrip().rstrip() |
---|
293 | if scale == "": |
---|
294 | raise ValueError, "Need a background" |
---|
295 | if check_float(self.scale_tcl): |
---|
296 | if float(scale) <= 0.0: |
---|
297 | self.scale_tcl.SetBackgroundColour("pink") |
---|
298 | self.scale_tcl.Refresh() |
---|
299 | msg = "Receive invalid value for scale: %s" % (scale) |
---|
300 | raise ValueError, msg |
---|
301 | return float(scale) |
---|
302 | else: |
---|
303 | raise ValueError, "Receive invalid value for scale : %s" % (scale) |
---|
304 | |
---|
305 | def get_contrast(self): |
---|
306 | """ |
---|
307 | return the contrast textcrtl value as a float |
---|
308 | """ |
---|
309 | par_str = self.contrast_tcl.GetValue().strip() |
---|
310 | contrast = None |
---|
311 | if par_str !=" " and check_float(self.contrast_tcl): |
---|
312 | contrast = float(par_str) |
---|
313 | return contrast |
---|
314 | |
---|
315 | def get_extrapolation_type(self, low_q, high_q): |
---|
316 | """ |
---|
317 | """ |
---|
318 | extrapolation = None |
---|
319 | if low_q and not high_q: |
---|
320 | extrapolation = "low" |
---|
321 | elif not low_q and high_q: |
---|
322 | extrapolation = "high" |
---|
323 | elif low_q and high_q: |
---|
324 | extrapolation = "both" |
---|
325 | return extrapolation |
---|
326 | |
---|
327 | def get_porod_const(self): |
---|
328 | """ |
---|
329 | return the porod constant textcrtl value as a float |
---|
330 | """ |
---|
331 | par_str = self.porod_constant_tcl.GetValue().strip() |
---|
332 | porod_const = None |
---|
333 | if par_str != "" and check_float(self.porod_constant_tcl): |
---|
334 | porod_const = float(par_str) |
---|
335 | return porod_const |
---|
336 | |
---|
337 | def get_volume(self, inv, contrast, extrapolation): |
---|
338 | """ |
---|
339 | """ |
---|
340 | if contrast is not None: |
---|
341 | try: |
---|
342 | v, dv = inv.get_volume_fraction_with_error(contrast=contrast, |
---|
343 | extrapolation=extrapolation) |
---|
344 | self.volume_tcl.SetValue(format_number(v)) |
---|
345 | self.volume_err_tcl.SetValue(format_number(dv)) |
---|
346 | except: |
---|
347 | self.volume_tcl.SetValue(format_number(None)) |
---|
348 | self.volume_err_tcl.SetValue(format_number(None)) |
---|
349 | msg = "Error occurred computing volume " |
---|
350 | msg += " fraction: %s" % sys.exc_value |
---|
351 | wx.PostEvent(self.parent, StatusEvent(status=msg, |
---|
352 | info="error", |
---|
353 | type="stop")) |
---|
354 | |
---|
355 | def get_surface(self, inv, contrast, porod_const, extrapolation): |
---|
356 | """ |
---|
357 | """ |
---|
358 | if contrast is not None and porod_const is not None: |
---|
359 | try: |
---|
360 | s, ds = inv.get_surface_with_error(contrast=contrast, |
---|
361 | porod_const=porod_const, |
---|
362 | extrapolation=extrapolation) |
---|
363 | self.surface_tcl.SetValue(format_number(s)) |
---|
364 | self.surface_err_tcl.SetValue(format_number(ds)) |
---|
365 | except: |
---|
366 | self.surface_tcl.SetValue(format_number(None)) |
---|
367 | self.surface_err_tcl.SetValue(format_number(None)) |
---|
368 | msg = "Error occurred computing " |
---|
369 | msg += "specific surface: %s" % sys.exc_value |
---|
370 | wx.PostEvent(self.parent, StatusEvent(status=msg, info="error", |
---|
371 | type="stop")) |
---|
372 | |
---|
373 | def get_total_qstar(self, inv, extrapolation): |
---|
374 | """ |
---|
375 | """ |
---|
376 | try: |
---|
377 | qstar_total, qstar_total_err = inv.get_qstar_with_error(extrapolation) |
---|
378 | self.invariant_total_tcl.SetValue(format_number(qstar_total)) |
---|
379 | self.invariant_total_err_tcl.SetValue(format_number(qstar_total_err)) |
---|
380 | self.inv_container.qstar_total = qstar_total |
---|
381 | self.inv_container.qstar_total_err = qstar_total_err |
---|
382 | except: |
---|
383 | self.inv_container.qstar_total = "Error" |
---|
384 | self.inv_container.qstar_total_err = "Error" |
---|
385 | self.invariant_total_tcl.SetValue(format_number(None)) |
---|
386 | self.invariant_total_err_tcl.SetValue(format_number(None)) |
---|
387 | msg = "Error occurred computing invariant using" |
---|
388 | msg += " extrapolation: %s" % sys.exc_value |
---|
389 | wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) |
---|
390 | |
---|
391 | def get_low_qstar(self, inv, npts_low, low_q=False): |
---|
392 | """ |
---|
393 | """ |
---|
394 | if low_q: |
---|
395 | try: |
---|
396 | qstar_low, qstar_low_err = inv.get_qstar_low() |
---|
397 | self.inv_container.qstar_low = qstar_low |
---|
398 | self.inv_container.qstar_low_err = qstar_low_err |
---|
399 | extrapolated_data = inv.get_extra_data_low(npts_in=npts_low) |
---|
400 | power_low = inv.get_extrapolation_power(range='low') |
---|
401 | if self.power_law_low.GetValue(): |
---|
402 | self.power_low_tcl.SetValue(format_number(power_low)) |
---|
403 | self._manager.plot_theory(data=extrapolated_data, |
---|
404 | name="Low-Q extrapolation") |
---|
405 | except: |
---|
406 | raise |
---|
407 | self.inv_container.qstar_low = "ERROR" |
---|
408 | self.inv_container.qstar_low_err = "ERROR" |
---|
409 | self._manager.plot_theory(name="Low-Q extrapolation") |
---|
410 | msg = "Error occurred computing low-Q " |
---|
411 | msg += "invariant: %s" % sys.exc_value |
---|
412 | wx.PostEvent(self.parent, |
---|
413 | StatusEvent(status=msg, type="stop")) |
---|
414 | else: |
---|
415 | try: |
---|
416 | self._manager.plot_theory(name="Low-Q extrapolation") |
---|
417 | except: pass |
---|
418 | |
---|
419 | def get_high_qstar(self, inv, high_q=False): |
---|
420 | """ |
---|
421 | """ |
---|
422 | if high_q: |
---|
423 | try: |
---|
424 | qmax_plot = Q_MAXIMUM_PLOT * max(self._data.x) |
---|
425 | if qmax_plot > Q_MAXIMUM: qmax_plot = Q_MAXIMUM |
---|
426 | qstar_high, qstar_high_err = inv.get_qstar_high() |
---|
427 | self.inv_container.qstar_high = qstar_high |
---|
428 | self.inv_container.qstar_high_err = qstar_high_err |
---|
429 | power_high = inv.get_extrapolation_power(range='high') |
---|
430 | self.power_high_tcl.SetValue(format_number(power_high)) |
---|
431 | high_out_data = inv.get_extra_data_high(q_end=qmax_plot, |
---|
432 | npts=500) |
---|
433 | self._manager.plot_theory(data=high_out_data, |
---|
434 | name="High-Q extrapolation") |
---|
435 | except: |
---|
436 | #raise |
---|
437 | self.inv_container.qstar_high = "ERROR" |
---|
438 | self.inv_container.qstar_high_err = "ERROR" |
---|
439 | self._manager.plot_theory(name="High-Q extrapolation") |
---|
440 | msg = "Error occurred computing high-Q " |
---|
441 | msg += "invariant: %s" % sys.exc_value |
---|
442 | wx.PostEvent(self.parent, StatusEvent(status=msg, |
---|
443 | type="stop")) |
---|
444 | else: |
---|
445 | try: |
---|
446 | self._manager.plot_theory(name="High-Q extrapolation") |
---|
447 | except: pass |
---|
448 | |
---|
449 | def get_qstar(self, inv): |
---|
450 | """ |
---|
451 | """ |
---|
452 | qstar, qstar_err = inv.get_qstar_with_error() |
---|
453 | self.inv_container.qstar = qstar |
---|
454 | self.inv_container.qstar_err = qstar_err |
---|
455 | |
---|
456 | def set_extrapolation_low(self, inv, low_q=False): |
---|
457 | """ |
---|
458 | return float value necessary to compute invariant a low q |
---|
459 | """ |
---|
460 | #get funtion |
---|
461 | if self.guinier.GetValue(): |
---|
462 | function_low = "guinier" |
---|
463 | # get the function |
---|
464 | power_low = None #2.0/3.0 |
---|
465 | if self.power_law_low.GetValue(): |
---|
466 | function_low = "power_law" |
---|
467 | if self.fit_enable_low.GetValue(): |
---|
468 | #set value of power_low to none to allow fitting |
---|
469 | power_low = None |
---|
470 | else: |
---|
471 | power_low = self.power_low_tcl.GetValue().lstrip().rstrip() |
---|
472 | if check_float(self.power_low_tcl): |
---|
473 | power_low = float(power_low) |
---|
474 | else: |
---|
475 | if low_q : |
---|
476 | #Raise error only when qstar at low q is requested |
---|
477 | msg = "Expect float for power at low q, " |
---|
478 | msg += " got %s" % (power_low) |
---|
479 | raise ValueError, msg |
---|
480 | |
---|
481 | #Get the number of points to extrapolated |
---|
482 | npts_low = self.npts_low_tcl.GetValue().lstrip().rstrip() |
---|
483 | if check_float(self.npts_low_tcl): |
---|
484 | npts_low = float(npts_low) |
---|
485 | else: |
---|
486 | if low_q: |
---|
487 | msg = "Expect float for number of points at low q," |
---|
488 | msg += " got %s" % (npts_low) |
---|
489 | raise ValueError, msg |
---|
490 | #Set the invariant calculator |
---|
491 | inv.set_extrapolation(range="low", npts=npts_low, |
---|
492 | function=function_low, power=power_low) |
---|
493 | return inv, npts_low |
---|
494 | |
---|
495 | |
---|
496 | def set_extrapolation_high(self, inv, high_q=False): |
---|
497 | """ |
---|
498 | return float value necessary to compute invariant a high q |
---|
499 | """ |
---|
500 | power_high = None |
---|
501 | #if self.power_law_high.GetValue(): |
---|
502 | function_high = "power_law" |
---|
503 | if self.fit_enable_high.GetValue(): |
---|
504 | #set value of power_high to none to allow fitting |
---|
505 | power_high = None |
---|
506 | else: |
---|
507 | power_high = self.power_high_tcl.GetValue().lstrip().rstrip() |
---|
508 | if check_float(self.power_high_tcl): |
---|
509 | power_high = float(power_high) |
---|
510 | else: |
---|
511 | if high_q : |
---|
512 | #Raise error only when qstar at high q is requested |
---|
513 | msg = "Expect float for power at high q," |
---|
514 | msg += " got %s" % (power_high) |
---|
515 | raise ValueError, msg |
---|
516 | |
---|
517 | npts_high = self.npts_high_tcl.GetValue().lstrip().rstrip() |
---|
518 | if check_float(self.npts_high_tcl): |
---|
519 | npts_high = float(npts_high) |
---|
520 | else: |
---|
521 | if high_q: |
---|
522 | msg = "Expect float for number of points at high q," |
---|
523 | msg += " got %s" % (npts_high) |
---|
524 | raise ValueError, msg |
---|
525 | inv.set_extrapolation(range="high", npts=npts_high, |
---|
526 | function=function_high, power=power_high) |
---|
527 | return inv, npts_high |
---|
528 | |
---|
529 | def display_details(self, event): |
---|
530 | """ |
---|
531 | open another panel for more details on invariant calculation |
---|
532 | """ |
---|
533 | panel = InvariantDetailsPanel(parent=self, |
---|
534 | qstar_container=self.inv_container) |
---|
535 | panel.ShowModal() |
---|
536 | panel.Destroy() |
---|
537 | self.button_calculate.SetFocus() |
---|
538 | |
---|
539 | def compute_invariant(self, event=None): |
---|
540 | """ |
---|
541 | compute invariant |
---|
542 | """ |
---|
543 | if self._data == None: |
---|
544 | msg = "\n\nData must be loaded first in order" |
---|
545 | msg += " to perform a compution..." |
---|
546 | wx.PostEvent(self.parent, StatusEvent(status=msg)) |
---|
547 | # set a state for this computation for saving |
---|
548 | elif event != None: |
---|
549 | self._set_compute_state(state='compute') |
---|
550 | self._set_bookmark_flag(True) |
---|
551 | msg= "\n\nStarting a new invariant computation..." |
---|
552 | wx.PostEvent(self.parent, StatusEvent(status=msg)) |
---|
553 | |
---|
554 | |
---|
555 | if self._data is None: |
---|
556 | return |
---|
557 | self.button_details.Enable() |
---|
558 | #clear outputs textctrl |
---|
559 | self._reset_output() |
---|
560 | try: |
---|
561 | background = self.get_background() |
---|
562 | scale = self.get_scale() |
---|
563 | except: |
---|
564 | msg = "Invariant Error: %s" % (sys.exc_value) |
---|
565 | wx.PostEvent(self.parent, StatusEvent(status=msg, type="stop")) |
---|
566 | return |
---|
567 | |
---|
568 | low_q = self.enable_low_cbox.GetValue() |
---|
569 | high_q = self.enable_high_cbox.GetValue() |
---|
570 | temp_data = copy.deepcopy(self._data) |
---|
571 | |
---|
572 | #set invariant calculator |
---|
573 | inv = invariant.InvariantCalculator(data=temp_data, |
---|
574 | background=background, |
---|
575 | scale=scale) |
---|
576 | try: |
---|
577 | inv, npts_low = self.set_extrapolation_low(inv=inv, low_q=low_q) |
---|
578 | inv, npts_high = self.set_extrapolation_high(inv=inv, high_q=high_q) |
---|
579 | except: |
---|
580 | msg = "Error occurred computing invariant: %s" % sys.exc_value |
---|
581 | wx.PostEvent(self.parent, StatusEvent(status=msg, |
---|
582 | info="warning",type="stop")) |
---|
583 | return |
---|
584 | #check the type of extrapolation |
---|
585 | extrapolation = self.get_extrapolation_type(low_q=low_q, high_q=high_q) |
---|
586 | |
---|
587 | #Compute invariant |
---|
588 | bkg_changed = False |
---|
589 | scale_changed = False |
---|
590 | try: |
---|
591 | self.get_qstar(inv=inv) |
---|
592 | #if scale_changed or bkg_changed: |
---|
593 | #self._manager.plot_data(data=inv.get_data()) |
---|
594 | |
---|
595 | except: |
---|
596 | msg= "Error occurred computing invariant: %s" % sys.exc_value |
---|
597 | wx.PostEvent(self.parent, StatusEvent(status=msg, |
---|
598 | info="warning", |
---|
599 | type="stop")) |
---|
600 | return |
---|
601 | |
---|
602 | #Compute qstar extrapolated to low q range |
---|
603 | self.get_low_qstar(inv=inv, npts_low=npts_low, low_q=low_q) |
---|
604 | #Compute qstar extrapolated to high q range |
---|
605 | self.get_high_qstar(inv=inv, high_q=high_q) |
---|
606 | #Compute qstar extrapolated to total q range and set value to txtcrtl |
---|
607 | self.get_total_qstar(inv=inv, extrapolation=extrapolation) |
---|
608 | # Parse additional parameters |
---|
609 | porod_const = self.get_porod_const() |
---|
610 | contrast = self.get_contrast() |
---|
611 | |
---|
612 | try: |
---|
613 | #Compute volume and set value to txtcrtl |
---|
614 | self.get_volume(inv=inv, contrast=contrast, |
---|
615 | extrapolation=extrapolation) |
---|
616 | #compute surface and set value to txtcrtl |
---|
617 | except: |
---|
618 | msg = "Error occurred computing invariant: %s" % sys.exc_value |
---|
619 | wx.PostEvent(self.parent, StatusEvent(status=msg, |
---|
620 | info="warning", |
---|
621 | type="stop")) |
---|
622 | try: |
---|
623 | self.get_surface(inv=inv, contrast=contrast, |
---|
624 | porod_const=porod_const, |
---|
625 | extrapolation=extrapolation) |
---|
626 | |
---|
627 | except: |
---|
628 | msg = "Error occurred computing invariant: %s" % sys.exc_value |
---|
629 | wx.PostEvent(self.parent, StatusEvent(status=msg, |
---|
630 | info="warning", |
---|
631 | type="stop")) |
---|
632 | |
---|
633 | #compute percentage of each invariant |
---|
634 | self.inv_container.compute_percentage() |
---|
635 | |
---|
636 | #display a message |
---|
637 | self.set_message() |
---|
638 | |
---|
639 | # reset power_out to default to get ready for another '_on_text' |
---|
640 | if self.is_power_out == True: |
---|
641 | self.state.container = copy.deepcopy(self.inv_container) |
---|
642 | self.state.timestamp= self._get_time_stamp() |
---|
643 | msg = self.state.__str__() |
---|
644 | self.state.set_report_string() |
---|
645 | self.is_power_out = False |
---|
646 | wx.PostEvent(self.parent, StatusEvent(status = msg )) |
---|
647 | |
---|
648 | #enable the button_ok for more details |
---|
649 | self._set_preview_flag(True) |
---|
650 | |
---|
651 | if event != None: |
---|
652 | self._set_preview_flag(True) |
---|
653 | self._set_save_flag(True) |
---|
654 | wx.PostEvent(self.parent, |
---|
655 | StatusEvent(status='\nFinished invariant computation...')) |
---|
656 | |
---|
657 | def on_undo(self,event=None): |
---|
658 | """ |
---|
659 | Go back to the previous state |
---|
660 | |
---|
661 | : param event: undo button event |
---|
662 | """ |
---|
663 | if self.state.state_num < 0: |
---|
664 | return |
---|
665 | self.is_power_out = True |
---|
666 | # get the previous state_num |
---|
667 | pre_state_num = int(self.state.saved_state['state_num']) - 1 |
---|
668 | |
---|
669 | self.get_state_by_num(state_num=str(pre_state_num)) |
---|
670 | |
---|
671 | if float(pre_state_num) <= 0: |
---|
672 | self._set_undo_flag(False) |
---|
673 | else: |
---|
674 | self._set_undo_flag(True) |
---|
675 | self._set_redo_flag(True) |
---|
676 | self.is_power_out = False |
---|
677 | self._info_state_num() |
---|
678 | |
---|
679 | |
---|
680 | def on_redo(self,event=None): |
---|
681 | """ |
---|
682 | Go forward to the previous state |
---|
683 | |
---|
684 | : param event: redo button event |
---|
685 | """ |
---|
686 | self.is_power_out = True |
---|
687 | # get the next state_num |
---|
688 | next_state_num = int(self.state.saved_state['state_num']) + 1 |
---|
689 | |
---|
690 | self.get_state_by_num(state_num=str(next_state_num)) |
---|
691 | |
---|
692 | if float(next_state_num)+2 > len(self.state.state_list): |
---|
693 | self._set_redo_flag(False) |
---|
694 | else: |
---|
695 | self._set_redo_flag(True) |
---|
696 | |
---|
697 | self._set_undo_flag(True) |
---|
698 | self.is_power_out = False |
---|
699 | self._info_state_num() |
---|
700 | |
---|
701 | def on_preview(self, event=None): |
---|
702 | """ |
---|
703 | Invoke report dialog panel |
---|
704 | |
---|
705 | : param event: report button event |
---|
706 | """ |
---|
707 | from .report_dialog import ReportDialog |
---|
708 | |
---|
709 | self.state.set_report_string() |
---|
710 | report_html_str = self.state.report_str |
---|
711 | report_text_str = self.state.__str__() |
---|
712 | report_img = self.state.image |
---|
713 | report_list = [report_html_str,report_text_str,report_img] |
---|
714 | dialog = ReportDialog(report_list, None, -1, "") |
---|
715 | dialog.ShowModal() |
---|
716 | |
---|
717 | def get_state_by_num(self,state_num=None): |
---|
718 | """ |
---|
719 | Get the state given by number |
---|
720 | |
---|
721 | : param state_num: the given state number |
---|
722 | """ |
---|
723 | if state_num == None: |
---|
724 | return |
---|
725 | |
---|
726 | backup_state_list = copy.deepcopy(self.state.state_list) |
---|
727 | |
---|
728 | # get the previous state |
---|
729 | try: |
---|
730 | current_state = copy.deepcopy(self.state.state_list[str(state_num)]) |
---|
731 | # get the previously computed state number |
---|
732 | #(computation before the state changes happened) |
---|
733 | current_compute_num = str(current_state['compute_num']) |
---|
734 | except : |
---|
735 | raise |
---|
736 | #raise ValueError, "No such state exists in history" |
---|
737 | |
---|
738 | # get the state at pre_compute_num |
---|
739 | comp_state = copy.deepcopy(self.state.state_list[current_compute_num]) |
---|
740 | |
---|
741 | # set the parameters |
---|
742 | for key in comp_state: |
---|
743 | value = comp_state[key] |
---|
744 | try: |
---|
745 | exec "self.%s.SetValue(str(%s))" % (key, value) |
---|
746 | except TypeError: |
---|
747 | exec "self.%s.SetValue(%s)" % (key, value) |
---|
748 | except: |
---|
749 | pass |
---|
750 | |
---|
751 | self.compute_invariant(event=None) |
---|
752 | |
---|
753 | # set the input params at the state at pre_state_num |
---|
754 | for key in current_state: |
---|
755 | # set the inputs and boxes |
---|
756 | value = current_state[key] |
---|
757 | try: |
---|
758 | exec 'self.%s.SetValue(str(%s))' % (key, value) |
---|
759 | except TypeError: |
---|
760 | exec 'self.%s.SetValue(%s)' % (key, value) |
---|
761 | except: |
---|
762 | pass |
---|
763 | |
---|
764 | self._enable_high_q_section(event=None) |
---|
765 | self._enable_low_q_section(event=None) |
---|
766 | self.state.state_list = backup_state_list |
---|
767 | self.state.saved_state = current_state |
---|
768 | self.state.state_num = state_num |
---|
769 | |
---|
770 | |
---|
771 | def get_bookmark_by_num(self, num=None): |
---|
772 | """ |
---|
773 | Get the bookmark state given by number |
---|
774 | |
---|
775 | : param num: the given bookmark number |
---|
776 | |
---|
777 | """ |
---|
778 | current_state = {} |
---|
779 | comp_state = {} |
---|
780 | backup_state_list = copy.deepcopy(self.state.state_list) |
---|
781 | |
---|
782 | # get the previous state |
---|
783 | try: |
---|
784 | time,date,current_state,comp_state = self.state.bookmark_list[int(num)] |
---|
785 | except : |
---|
786 | raise ValueError, "No such bookmark exists" |
---|
787 | |
---|
788 | # set the parameters |
---|
789 | for key in comp_state: |
---|
790 | value = comp_state[key] |
---|
791 | try: |
---|
792 | exec "self.%s.SetValue(str(%s))" % (key, value) |
---|
793 | except TypeError: |
---|
794 | exec "self.%s.SetValue(%s)" % (key, value) |
---|
795 | except: |
---|
796 | pass |
---|
797 | |
---|
798 | self.compute_invariant(event=None) |
---|
799 | # set the input params at the state of pre_state_num |
---|
800 | for key in current_state: |
---|
801 | value = current_state[key] |
---|
802 | try: |
---|
803 | exec 'self.%s.SetValue(str(%s))' % (key, value) |
---|
804 | except TypeError: |
---|
805 | exec 'self.%s.SetValue(%s)' % (key, value) |
---|
806 | except: |
---|
807 | pass |
---|
808 | self.state.saved_state = copy.deepcopy(current_state) |
---|
809 | |
---|
810 | self._enable_high_q_section(event=None) |
---|
811 | self._enable_low_q_section(event=None) |
---|
812 | self.state.state_list = backup_state_list |
---|
813 | #self.state.saved_state = current_state |
---|
814 | #self.state.state_num = state_num |
---|
815 | |
---|
816 | def reset_panel(self): |
---|
817 | """ |
---|
818 | set the panel at its initial state. |
---|
819 | """ |
---|
820 | self.background_tcl.SetValue(str(BACKGROUND)) |
---|
821 | self.scale_tcl.SetValue(str(SCALE)) |
---|
822 | self.contrast_tcl.SetValue(str(CONTRAST)) |
---|
823 | self.porod_constant_tcl.SetValue('') |
---|
824 | self.npts_low_tcl.SetValue(str(NPTS)) |
---|
825 | self.enable_low_cbox.SetValue(False) |
---|
826 | self.fix_enable_low.SetValue(True) |
---|
827 | self.power_low_tcl.SetValue(str(POWER)) |
---|
828 | self.guinier.SetValue(True) |
---|
829 | self.power_low_tcl.Disable() |
---|
830 | self.enable_high_cbox.SetValue(False) |
---|
831 | self.fix_enable_high.SetValue(True) |
---|
832 | self.power_high_tcl.SetValue(str(POWER)) |
---|
833 | self.npts_high_tcl.SetValue(str(NPTS)) |
---|
834 | self.button_details.Disable() |
---|
835 | #Change the state of txtcrtl to enable/disable |
---|
836 | self._enable_low_q_section() |
---|
837 | #Change the state of txtcrtl to enable/disable |
---|
838 | self._enable_high_q_section() |
---|
839 | self._reset_output() |
---|
840 | self._set_undo_flag(False) |
---|
841 | self._set_redo_flag(False) |
---|
842 | self._set_bookmark_flag(False) |
---|
843 | self._set_preview_flag(False) |
---|
844 | self._set_save_flag(False) |
---|
845 | self.button_calculate.SetFocus() |
---|
846 | #self.SetupScrolling() |
---|
847 | |
---|
848 | def _set_state(self, event): |
---|
849 | """ |
---|
850 | Set the state list |
---|
851 | |
---|
852 | :param event: rb/cb event |
---|
853 | """ |
---|
854 | if event == None: |
---|
855 | return |
---|
856 | obj = event.GetEventObject() |
---|
857 | name = str(obj.GetName()) |
---|
858 | value = str(obj.GetValue()) |
---|
859 | rb_list = [['power_law_low','guinier'], |
---|
860 | ['fit_enable_low','fix_enable_low'], |
---|
861 | ['fit_enable_high','fix_enable_high']] |
---|
862 | |
---|
863 | try: |
---|
864 | if value == None or value.lstrip().rstrip() =='': |
---|
865 | value = 'None' |
---|
866 | exec 'self.state.%s = %s' % (name, value) |
---|
867 | exec "self.state.saved_state['%s'] = %s" % (name, value) |
---|
868 | |
---|
869 | # set the count part of radio button clicked |
---|
870 | #False for the saved_state |
---|
871 | for title,content in rb_list: |
---|
872 | if name == title: |
---|
873 | name = content |
---|
874 | value = False |
---|
875 | elif name == content: |
---|
876 | name = title |
---|
877 | value = False |
---|
878 | exec "self.state.saved_state['%s'] = %s" % (name, value) |
---|
879 | |
---|
880 | # Instead of changing the future, create a new future. |
---|
881 | max_state_num = len(self.state.state_list) - 1 |
---|
882 | self.state.saved_state['state_num'] = max_state_num |
---|
883 | |
---|
884 | self.state.saved_state['state_num'] += 1 |
---|
885 | self.state.state_num = self.state.saved_state['state_num'] |
---|
886 | self.state.state_list[str(self.state.state_num)] = self.state.clone_state()#copy.deepcopy(self.state.saved_state) |
---|
887 | except: |
---|
888 | pass |
---|
889 | |
---|
890 | self._set_undo_flag(True) |
---|
891 | self._set_redo_flag(False) |
---|
892 | #event.Skip() |
---|
893 | |
---|
894 | def _set_compute_state(self,state=None): |
---|
895 | """ |
---|
896 | Notify the compute_invariant state to self.state |
---|
897 | |
---|
898 | : param state: set 'compute' when the computation is |
---|
899 | activated by the 'compute' button, else None |
---|
900 | |
---|
901 | """ |
---|
902 | # reset the default |
---|
903 | if state != 'compute': |
---|
904 | self.new_state = False |
---|
905 | self.is_power_out = False |
---|
906 | else: |
---|
907 | self.is_power_out = True |
---|
908 | # Instead of changing the future, create a new future. |
---|
909 | max_state_num = len(self.state.state_list)-1 |
---|
910 | self.state.saved_state['state_num'] = max_state_num |
---|
911 | # A new computation is also A state |
---|
912 | #copy.deepcopy(self.state.saved_state) |
---|
913 | temp_saved_states = self.state.clone_state() |
---|
914 | temp_saved_states['state_num'] += 1 |
---|
915 | self.state.state_num = temp_saved_states['state_num'] |
---|
916 | |
---|
917 | |
---|
918 | # set the state number of the computation |
---|
919 | if state == 'compute': |
---|
920 | temp_saved_states['compute_num'] = self.state.state_num |
---|
921 | self.state.saved_state= copy.deepcopy(temp_saved_states) |
---|
922 | #copy.deepcopy(self.state.saved_state) |
---|
923 | self.state.state_list[str(self.state.state_num)] = self.state.clone_state() |
---|
924 | |
---|
925 | # A computation is a new state, so delete the states with any higher |
---|
926 | # state numbers |
---|
927 | for i in range(self.state.state_num+1,len(self.state.state_list)): |
---|
928 | try: |
---|
929 | del (self.state.state_list[str(i)]) |
---|
930 | except: |
---|
931 | pass |
---|
932 | # Enable the undo button if it was not |
---|
933 | self._set_undo_flag(True) |
---|
934 | self._set_redo_flag(False) |
---|
935 | |
---|
936 | def _reset_state_list(self, data=None): |
---|
937 | """ |
---|
938 | Reset the state_list just before data was loading: |
---|
939 | Used in 'set_current_data()' |
---|
940 | """ |
---|
941 | #if data == None: return |
---|
942 | #temp_state = self.state.clone_state() |
---|
943 | #copy.deepcopy(self.state.saved_state) |
---|
944 | # Clear the list |
---|
945 | self.state.state_list.clear() |
---|
946 | self.state.bookmark_list.clear() |
---|
947 | # Set defaults |
---|
948 | self.state.saved_state['state_num'] = 0 |
---|
949 | self.state.saved_state['compute_num'] = 0 |
---|
950 | if self._data != None: |
---|
951 | self.state.saved_state['file'] = str(self._data.name) |
---|
952 | else: |
---|
953 | self.state.saved_state['file'] = 'None' |
---|
954 | self.state.file = self.state.saved_state['file'] |
---|
955 | |
---|
956 | self.state.state_num = self.state.saved_state['state_num'] |
---|
957 | self.state.timestamp = "('00:00:00', '00/00/0000')" |
---|
958 | |
---|
959 | # Put only the current state in the list |
---|
960 | #copy.deepcopy(self.state.saved_state) |
---|
961 | self.state.state_list[str(self.state.state_num)] = self.state.clone_state() |
---|
962 | self._set_undo_flag(False) |
---|
963 | self._set_redo_flag(False) |
---|
964 | self._set_bookmark_flag(False) |
---|
965 | self._set_preview_flag(False) |
---|
966 | self._set_save_flag(False) |
---|
967 | |
---|
968 | |
---|
969 | def _on_text(self, event): |
---|
970 | """ |
---|
971 | Catch text change event to add the state to the state_list |
---|
972 | |
---|
973 | :param event: txtctr event ; assumes not None |
---|
974 | |
---|
975 | """ |
---|
976 | if self._data == None: |
---|
977 | return |
---|
978 | # check if this event is from do/undo button |
---|
979 | if self.state.saved_state['is_time_machine'] or self.new_state: |
---|
980 | #event.Skip() |
---|
981 | return |
---|
982 | |
---|
983 | # get the object |
---|
984 | obj = event.GetEventObject() |
---|
985 | name = str(obj.GetName()) |
---|
986 | value = str(obj.GetValue()) |
---|
987 | state_num = self.state.saved_state['state_num'] |
---|
988 | |
---|
989 | # text event is a new state, so delete the states with higher state_num |
---|
990 | # i.e., change the future |
---|
991 | for i in range(int(state_num)+1,len(self.state.state_list)): |
---|
992 | try: |
---|
993 | del (self.state.state_list[str(i)]) |
---|
994 | except: |
---|
995 | pass |
---|
996 | |
---|
997 | # Instead of changing the future, create a new future. |
---|
998 | #max_state_num = len(self.state.state_list)-1 |
---|
999 | #self.state.saved_state['state_num'] = max_state_num |
---|
1000 | |
---|
1001 | # try to add new state of the text changes in the state_list |
---|
1002 | try: |
---|
1003 | if value.strip() == None: value = '' |
---|
1004 | exec "self.state.%s = '%s'" % (name, value) |
---|
1005 | exec "self.state.saved_state['%s'] = '%s'" % (name, value) |
---|
1006 | exec "self.state.input_list['%s'] = '%s'" % (name, value) |
---|
1007 | if not self.is_power_out: |
---|
1008 | if name != 'power_low_tcl' and name !='power_high_tcl': |
---|
1009 | self.state.saved_state['state_num'] += 1 |
---|
1010 | self.state.state_num = self.state.saved_state['state_num'] |
---|
1011 | #copy.deepcopy(self.state.saved_state) |
---|
1012 | self.state.state_list[str(self.state.state_num)] = self.state.clone_state() |
---|
1013 | except: |
---|
1014 | pass |
---|
1015 | |
---|
1016 | #event.Skip() |
---|
1017 | self._set_undo_flag(True) |
---|
1018 | self._set_redo_flag(False) |
---|
1019 | self._set_bookmark_flag(True) |
---|
1020 | self._set_preview_flag(False) |
---|
1021 | |
---|
1022 | def _on_out_text(self, event): |
---|
1023 | """ |
---|
1024 | Catch ouput text change to add the state |
---|
1025 | |
---|
1026 | :param event: txtctr event ; assumes not None |
---|
1027 | |
---|
1028 | """ |
---|
1029 | # get the object |
---|
1030 | obj = event.GetEventObject() |
---|
1031 | name = str(obj.GetName()) |
---|
1032 | value = str(obj.GetValue()) |
---|
1033 | try: |
---|
1034 | exec "self.state.saved_state['%s'] = '%s'" % (name, value) |
---|
1035 | self.state.state_list[str(self.state.state_num)] = self.state.clone_state() |
---|
1036 | except: |
---|
1037 | pass |
---|
1038 | #if event != None: event.Skip() |
---|
1039 | |
---|
1040 | def _get_input_list(self): |
---|
1041 | """ |
---|
1042 | get input_list; called by set_state |
---|
1043 | """ |
---|
1044 | # get state num of the last compute state |
---|
1045 | compute_num = self.state.saved_state['compute_num'] |
---|
1046 | # find values and put into the input list |
---|
1047 | for key1,value1 in self.state.state_list[str(compute_num)].iteritems(): |
---|
1048 | for key,value in self.state.input_list.iteritems(): |
---|
1049 | if key == key1: |
---|
1050 | self.state.input_list[key]=value1 |
---|
1051 | break |
---|
1052 | |
---|
1053 | def _set_bookmark_menu(self): |
---|
1054 | """ |
---|
1055 | Setup 'bookmark' context menu |
---|
1056 | """ |
---|
1057 | ## Create context menu for page |
---|
1058 | self.popUpMenu = wx.Menu() |
---|
1059 | id = wx.NewId() |
---|
1060 | self._bmark = wx.MenuItem(self.popUpMenu,id,"BookMark", |
---|
1061 | " Bookmark the panel to recall it later") |
---|
1062 | self.popUpMenu.AppendItem(self._bmark) |
---|
1063 | self._bmark.Enable(True) |
---|
1064 | wx.EVT_MENU(self, id, self.on_bookmark) |
---|
1065 | self.popUpMenu.AppendSeparator() |
---|
1066 | self.Bind(wx.EVT_CONTEXT_MENU, self._on_context_menu) |
---|
1067 | |
---|
1068 | def on_bookmark(self,event): |
---|
1069 | """ |
---|
1070 | Save the panel state in memory and add the list on |
---|
1071 | the popup menu on bookmark context menu event |
---|
1072 | """ |
---|
1073 | if self._data == None: return |
---|
1074 | if event == None: return |
---|
1075 | self.bookmark_num += 1 |
---|
1076 | # date and time of the event |
---|
1077 | #year, month, day,hour,minute,second,tda,ty,tm_isdst= time.localtime() |
---|
1078 | #my_time= str(hour)+" : "+str(minute)+" : "+str(second)+" " |
---|
1079 | #date= str( month)+"/"+str(day)+"/"+str(year) |
---|
1080 | my_time, date = self._get_time_stamp() |
---|
1081 | state_num = self.state.state_num |
---|
1082 | compute_num = self.state.saved_state['compute_num'] |
---|
1083 | # name and message of the bookmark list |
---|
1084 | msg= "State saved at %s on %s"%(my_time, date) |
---|
1085 | ## post help message for the selected model |
---|
1086 | msg +=" Right click on the panel to retrieve this state" |
---|
1087 | #wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
1088 | name = "%d] bookmarked at %s on %s"%(self.bookmark_num, my_time, date) |
---|
1089 | |
---|
1090 | # append it to menu |
---|
1091 | id = wx.NewId() |
---|
1092 | self.popUpMenu.Append(id,name,str(msg)) |
---|
1093 | wx.EVT_MENU(self, id, self._back_to_bookmark) |
---|
1094 | state = self.state.clone_state() |
---|
1095 | comp_state = copy.deepcopy(self.state.state_list[str(compute_num)]) |
---|
1096 | self.state.bookmark_list[self.bookmark_num] = [my_time, date, |
---|
1097 | state,comp_state] |
---|
1098 | self.state.toXML(self, doc=None, entry_node=None) |
---|
1099 | |
---|
1100 | wx.PostEvent(self.parent,StatusEvent(status=msg,info="info")) |
---|
1101 | wx.PostEvent(self.parent, |
---|
1102 | AppendBookmarkEvent(title=name, |
---|
1103 | hint=str(msg), |
---|
1104 | handler=self._back_to_bookmark)) |
---|
1105 | |
---|
1106 | def _back_to_bookmark(self,event): |
---|
1107 | """ |
---|
1108 | Bring the panel back to the state of bookmarked requested by |
---|
1109 | context menu event |
---|
1110 | and set it as a new state |
---|
1111 | """ |
---|
1112 | self._manager.on_perspective(event) |
---|
1113 | menu = event.GetEventObject() |
---|
1114 | ## post help message for the selected model |
---|
1115 | msg = menu.GetHelpString(event.GetId()) |
---|
1116 | msg +=" reloaded" |
---|
1117 | wx.PostEvent(self.parent, StatusEvent(status = msg )) |
---|
1118 | |
---|
1119 | name= menu.GetLabel(event.GetId()) |
---|
1120 | |
---|
1121 | num,time = name.split(']') |
---|
1122 | current_state_num = self.state.state_num |
---|
1123 | self.get_bookmark_by_num(num) |
---|
1124 | state_num = int(current_state_num)+1 |
---|
1125 | |
---|
1126 | self.state.saved_state['state_num'] = state_num |
---|
1127 | #copy.deepcopy(self.state.saved_state) |
---|
1128 | self.state.state_list[str(state_num)] = self.state.clone_state() |
---|
1129 | self.state.state_num = state_num |
---|
1130 | |
---|
1131 | self._set_undo_flag(True) |
---|
1132 | self._info_bookmark_num(event) |
---|
1133 | |
---|
1134 | def _info_bookmark_num(self,event=None): |
---|
1135 | """ |
---|
1136 | print the bookmark number in info |
---|
1137 | |
---|
1138 | : event: popUpMenu event |
---|
1139 | """ |
---|
1140 | if event == None: return |
---|
1141 | # get the object |
---|
1142 | menu = event.GetEventObject() |
---|
1143 | item = menu.FindItemById(event.GetId()) |
---|
1144 | text = item.GetText() |
---|
1145 | num = text.split(']')[0] |
---|
1146 | msg = "bookmark num = %s "% num |
---|
1147 | |
---|
1148 | wx.PostEvent(self.parent, StatusEvent(status = msg )) |
---|
1149 | |
---|
1150 | def _info_state_num(self): |
---|
1151 | """ |
---|
1152 | print the current state number in info |
---|
1153 | """ |
---|
1154 | msg = "state num = " |
---|
1155 | msg += self.state.state_num |
---|
1156 | |
---|
1157 | wx.PostEvent(self.parent, StatusEvent(status = msg)) |
---|
1158 | |
---|
1159 | def _get_time_stamp(self): |
---|
1160 | """ |
---|
1161 | return time and date stings |
---|
1162 | """ |
---|
1163 | # date and time |
---|
1164 | year, month, day,hour,minute,second,tda,ty,tm_isdst= time.localtime() |
---|
1165 | my_time= str(hour)+":"+str(minute)+":"+str(second) |
---|
1166 | date= str( month)+"/"+str(day)+"/"+str(year) |
---|
1167 | return my_time, date |
---|
1168 | |
---|
1169 | |
---|
1170 | def on_save(self, evt=None): |
---|
1171 | """ |
---|
1172 | Save invariant state into a file |
---|
1173 | """ |
---|
1174 | # Ask the user the location of the file to write to. |
---|
1175 | path = None |
---|
1176 | if self.parent != None: |
---|
1177 | self._default_save_location =\ |
---|
1178 | self.parent._default_save_location |
---|
1179 | if self._default_save_location == None: |
---|
1180 | self._default_save_location = os.getcwd() |
---|
1181 | dlg = wx.FileDialog(self, "Choose a file", |
---|
1182 | self._default_save_location, \ |
---|
1183 | self.window_caption, "*.inv", wx.SAVE) |
---|
1184 | if dlg.ShowModal() == wx.ID_OK: |
---|
1185 | path = dlg.GetPath() |
---|
1186 | self._default_save_location = os.path.dirname(path) |
---|
1187 | if self.parent != None: |
---|
1188 | self.parent._default_save_location =\ |
---|
1189 | self._default_save_location |
---|
1190 | else: |
---|
1191 | return None |
---|
1192 | |
---|
1193 | dlg.Destroy() |
---|
1194 | # MAC always needs the extension for saving |
---|
1195 | extens = ".inv" |
---|
1196 | # Make sure the ext included in the file name |
---|
1197 | fName = os.path.splitext(path)[0] + extens |
---|
1198 | self._manager.save_file(filepath=fName, state=self.state) |
---|
1199 | |
---|
1200 | def _show_message(self, mssg='',msg='Warning'): |
---|
1201 | """ |
---|
1202 | Show warning message when resetting data |
---|
1203 | """ |
---|
1204 | # no message for now |
---|
1205 | return True |
---|
1206 | count_bf = self.data_cbbox.GetCount() |
---|
1207 | if count_bf > 1: |
---|
1208 | msg += "Loading a new data set will reset all the work" |
---|
1209 | msg += " done in this panel. \n\r" |
---|
1210 | mssg += "Please make sure to save it first... \n\r" |
---|
1211 | answer = wx.MessageBox(mssg, msg, |
---|
1212 | wx.CANCEL|wx.OK|wx.ICON_EXCLAMATION) |
---|
1213 | |
---|
1214 | if answer == wx.OK: |
---|
1215 | return True |
---|
1216 | else: |
---|
1217 | return False |
---|
1218 | else: True |
---|
1219 | |
---|
1220 | def _reset_output(self): |
---|
1221 | """ |
---|
1222 | clear outputs textcrtl |
---|
1223 | """ |
---|
1224 | self.invariant_total_tcl.Clear() |
---|
1225 | self.invariant_total_err_tcl.Clear() |
---|
1226 | self.volume_tcl.Clear() |
---|
1227 | self.volume_err_tcl.Clear() |
---|
1228 | self.surface_tcl.Clear() |
---|
1229 | self.surface_err_tcl.Clear() |
---|
1230 | #prepare a new container to put result of invariant |
---|
1231 | self.inv_container = InvariantContainer() |
---|
1232 | |
---|
1233 | |
---|
1234 | def _on_context_menu(self,event): |
---|
1235 | |
---|
1236 | pos = event.GetPosition() |
---|
1237 | pos = self.ScreenToClient(pos) |
---|
1238 | |
---|
1239 | self.PopupMenu(self.popUpMenu, pos) |
---|
1240 | |
---|
1241 | def _define_structure(self): |
---|
1242 | """ |
---|
1243 | Define main sizers needed for this panel |
---|
1244 | """ |
---|
1245 | ## Box sizers must be defined first before |
---|
1246 | #defining buttons/textctrls (MAC). |
---|
1247 | self.main_sizer = wx.BoxSizer(wx.VERTICAL) |
---|
1248 | #Sizer related to outputs |
---|
1249 | outputs_box = wx.StaticBox(self, -1, "Outputs") |
---|
1250 | self.outputs_sizer = wx.StaticBoxSizer(outputs_box, wx.VERTICAL) |
---|
1251 | self.outputs_sizer.SetMinSize((_STATICBOX_WIDTH,-1)) |
---|
1252 | #Sizer related to data |
---|
1253 | data_name_box = wx.StaticBox(self, -1, "I(q) Data Source") |
---|
1254 | self.data_name_boxsizer = wx.StaticBoxSizer(data_name_box, wx.VERTICAL) |
---|
1255 | self.data_name_boxsizer.SetMinSize((_STATICBOX_WIDTH,-1)) |
---|
1256 | self.hint_msg_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
1257 | self.data_name_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
1258 | |
---|
1259 | self.data_range_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
1260 | #Sizer related to inputs |
---|
1261 | self.sizer_input = wx.FlexGridSizer(2, 5, 0, 0) |
---|
1262 | #Sizer related to inputs |
---|
1263 | inputs_box = wx.StaticBox(self, -1, "Customized Inputs") |
---|
1264 | self.inputs_sizer = wx.StaticBoxSizer(inputs_box, wx.VERTICAL) |
---|
1265 | self.inputs_sizer.SetMinSize((_STATICBOX_WIDTH,-1)) |
---|
1266 | #Sizer related to extrapolation |
---|
1267 | extrapolation_box = wx.StaticBox(self, -1, "Extrapolation") |
---|
1268 | self.extrapolation_sizer = wx.StaticBoxSizer(extrapolation_box, |
---|
1269 | wx.VERTICAL) |
---|
1270 | self.extrapolation_sizer.SetMinSize((_STATICBOX_WIDTH,-1)) |
---|
1271 | self.extrapolation_range_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
1272 | self.extrapolation_low_high_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
1273 | #Sizer related to extrapolation at low q range |
---|
1274 | low_q_box = wx.StaticBox(self, -1, "Low Q") |
---|
1275 | self.low_extrapolation_sizer = wx.StaticBoxSizer(low_q_box, wx.VERTICAL) |
---|
1276 | |
---|
1277 | self.low_q_sizer = wx.GridBagSizer(5,5) |
---|
1278 | #Sizer related to extrapolation at low q range |
---|
1279 | high_q_box = wx.StaticBox(self, -1, "High Q") |
---|
1280 | self.high_extrapolation_sizer = wx.StaticBoxSizer(high_q_box, |
---|
1281 | wx.VERTICAL) |
---|
1282 | self.high_q_sizer = wx.GridBagSizer(5,5) |
---|
1283 | #sizer to define outputs |
---|
1284 | self.volume_surface_sizer = wx.GridBagSizer(5,5) |
---|
1285 | #Sizer related to invariant output |
---|
1286 | self.invariant_sizer = wx.GridBagSizer(5, 5) |
---|
1287 | #Sizer related to button |
---|
1288 | self.button_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
1289 | self.button_sizer.SetMinSize((_STATICBOX_WIDTH,-1)) |
---|
1290 | #Sizer related to save button |
---|
1291 | self.save_button_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
1292 | |
---|
1293 | def _layout_data_name(self): |
---|
1294 | """ |
---|
1295 | Draw widgets related to data's name |
---|
1296 | """ |
---|
1297 | #Sizer hint |
---|
1298 | hint_msg = "" |
---|
1299 | |
---|
1300 | self.hint_msg_txt = wx.StaticText(self, -1, hint_msg) |
---|
1301 | self.hint_msg_txt.SetForegroundColour("red") |
---|
1302 | msg = "Highlight = mouse the mouse's cursor on the data until" |
---|
1303 | msg += " the plot's color changes to yellow" |
---|
1304 | self.hint_msg_txt.SetToolTipString(msg) |
---|
1305 | self.hint_msg_sizer.Add(self.hint_msg_txt) |
---|
1306 | #Data name [string] |
---|
1307 | data_name_txt = wx.StaticText(self, -1, 'Name:') |
---|
1308 | |
---|
1309 | self.data_name_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH*4, 20), |
---|
1310 | style=0) |
---|
1311 | self.data_name_tcl.SetToolTipString("Data's name.") |
---|
1312 | self.data_name_sizer.AddMany([(data_name_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
1313 | (self.data_name_tcl, 0, wx.EXPAND)]) |
---|
1314 | #Data range [string] |
---|
1315 | data_range_txt = wx.StaticText(self, -1, 'Total Q Range (1/A): ') |
---|
1316 | data_min_txt = wx.StaticText(self, -1, 'Min : ') |
---|
1317 | self.data_min_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, 20), |
---|
1318 | style=0, name='data_min_tcl') |
---|
1319 | self.data_min_tcl.SetToolTipString("The minimum value of q range.") |
---|
1320 | data_max_txt = wx.StaticText(self, -1, 'Max : ') |
---|
1321 | self.data_max_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, 20), |
---|
1322 | style=0, name='data_max_tcl') |
---|
1323 | self.data_max_tcl.SetToolTipString("The maximum value of q range.") |
---|
1324 | self.data_range_sizer.AddMany([(data_range_txt, 0, wx.RIGHT, 5), |
---|
1325 | (data_min_txt, 0, wx.RIGHT, 5), |
---|
1326 | (self.data_min_tcl, 0, wx.RIGHT, 20), |
---|
1327 | (data_max_txt, 0, wx.RIGHT, 5), |
---|
1328 | (self.data_max_tcl, 0, wx.RIGHT, 10)]) |
---|
1329 | self.data_name_boxsizer.AddMany([(self.hint_msg_sizer, 0 , wx.ALL, 5), |
---|
1330 | (self.data_name_sizer, 0 , wx.ALL, 10), |
---|
1331 | (self.data_range_sizer, 0 , wx.ALL, 10)]) |
---|
1332 | |
---|
1333 | def _enable_fit_power_law_low(self, event=None): |
---|
1334 | """ |
---|
1335 | Enable and disable the power value editing |
---|
1336 | """ |
---|
1337 | if event != None: |
---|
1338 | self._set_bookmark_flag(True) |
---|
1339 | self._set_preview_flag(False) |
---|
1340 | |
---|
1341 | if self.fix_enable_low.IsEnabled(): |
---|
1342 | |
---|
1343 | if self.fix_enable_low.GetValue(): |
---|
1344 | self.fit_enable_low.SetValue(False) |
---|
1345 | self.power_low_tcl.Enable() |
---|
1346 | else: |
---|
1347 | self.fit_enable_low.SetValue(True) |
---|
1348 | self.power_low_tcl.Disable() |
---|
1349 | self._set_state(event=event) |
---|
1350 | |
---|
1351 | def _enable_low_q_section(self, event=None): |
---|
1352 | """ |
---|
1353 | Disable or enable some button if the user enable low q extrapolation |
---|
1354 | """ |
---|
1355 | if event != None: |
---|
1356 | self._set_bookmark_flag(True) |
---|
1357 | self._set_preview_flag(False) |
---|
1358 | |
---|
1359 | if self.enable_low_cbox.GetValue(): |
---|
1360 | self.npts_low_tcl.Enable() |
---|
1361 | self.fix_enable_low.Enable() |
---|
1362 | self.fit_enable_low.Enable() |
---|
1363 | self.guinier.Enable() |
---|
1364 | self.power_law_low.Enable() |
---|
1365 | |
---|
1366 | else: |
---|
1367 | self.npts_low_tcl.Disable() |
---|
1368 | self.fix_enable_low.Disable() |
---|
1369 | self.fit_enable_low.Disable() |
---|
1370 | self.guinier.Disable() |
---|
1371 | self.power_law_low.Disable() |
---|
1372 | |
---|
1373 | self._enable_power_law_low() |
---|
1374 | self._enable_fit_power_law_low() |
---|
1375 | self._set_state(event=event) |
---|
1376 | self.button_calculate.SetFocus() |
---|
1377 | |
---|
1378 | def _enable_power_law_low(self, event=None): |
---|
1379 | """ |
---|
1380 | Enable editing power law section at low q range |
---|
1381 | """ |
---|
1382 | if event != None: |
---|
1383 | self._set_bookmark_flag(True) |
---|
1384 | self._set_preview_flag(False) |
---|
1385 | if self.guinier.GetValue(): |
---|
1386 | self.power_law_low.SetValue(False) |
---|
1387 | self.fix_enable_low.Disable() |
---|
1388 | self.fit_enable_low.Disable() |
---|
1389 | self.power_low_tcl.Disable() |
---|
1390 | else: |
---|
1391 | self.power_law_low.SetValue(True) |
---|
1392 | self.fix_enable_low.Enable() |
---|
1393 | self.fit_enable_low.Enable() |
---|
1394 | self.power_low_tcl.Enable() |
---|
1395 | self._enable_fit_power_law_low() |
---|
1396 | self._set_state(event=event) |
---|
1397 | |
---|
1398 | def _layout_extrapolation_low(self): |
---|
1399 | """ |
---|
1400 | Draw widgets related to extrapolation at low q range |
---|
1401 | """ |
---|
1402 | self.enable_low_cbox = wx.CheckBox(self, -1, |
---|
1403 | "Enable Extrapolate Low Q", |
---|
1404 | name='enable_low_cbox') |
---|
1405 | wx.EVT_CHECKBOX(self, self.enable_low_cbox.GetId(), |
---|
1406 | self._enable_low_q_section) |
---|
1407 | self.fix_enable_low = wx.RadioButton(self, -1, 'Fix', |
---|
1408 | (10, 10), style=wx.RB_GROUP, |
---|
1409 | name='fix_enable_low') |
---|
1410 | self.Bind(wx.EVT_RADIOBUTTON, self._enable_fit_power_law_low, |
---|
1411 | id=self.fix_enable_low.GetId()) |
---|
1412 | self.fit_enable_low = wx.RadioButton(self, -1, 'Fit', (10, 10), |
---|
1413 | name='fit_enable_low') |
---|
1414 | self.Bind(wx.EVT_RADIOBUTTON, self._enable_fit_power_law_low, |
---|
1415 | id=self.fit_enable_low.GetId()) |
---|
1416 | self.guinier = wx.RadioButton(self, -1, 'Guinier', |
---|
1417 | (10, 10), style=wx.RB_GROUP, |
---|
1418 | name='guinier') |
---|
1419 | self.Bind(wx.EVT_RADIOBUTTON, self._enable_power_law_low, |
---|
1420 | id=self.guinier.GetId()) |
---|
1421 | self.power_law_low = wx.RadioButton(self, -1, 'Power Law', |
---|
1422 | (10, 10), name='power_law_low') |
---|
1423 | self.Bind(wx.EVT_RADIOBUTTON, self._enable_power_law_low, |
---|
1424 | id=self.power_law_low.GetId()) |
---|
1425 | |
---|
1426 | npts_low_txt = wx.StaticText(self, -1, 'Npts') |
---|
1427 | self.npts_low_tcl = InvTextCtrl(self, -1, |
---|
1428 | size=(_BOX_WIDTH*2/3, -1), |
---|
1429 | name='npts_low_tcl') |
---|
1430 | wx.EVT_TEXT(self, self.npts_low_tcl.GetId(), self._on_text) |
---|
1431 | msg_hint = "Number of Q points to consider" |
---|
1432 | msg_hint +="while extrapolating the low-Q region" |
---|
1433 | self.npts_low_tcl.SetToolTipString(msg_hint) |
---|
1434 | power_txt = wx.StaticText(self, -1, 'Power') |
---|
1435 | self.power_low_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1), |
---|
1436 | name='power_low_tcl') |
---|
1437 | wx.EVT_TEXT(self, self.power_low_tcl.GetId(), self._on_text) |
---|
1438 | |
---|
1439 | power_hint_txt = "Exponent to apply to the Power_law function." |
---|
1440 | self.power_low_tcl.SetToolTipString(power_hint_txt) |
---|
1441 | iy = 0 |
---|
1442 | ix = 0 |
---|
1443 | self.low_q_sizer.Add(self.enable_low_cbox,(iy, ix), (1, 5), |
---|
1444 | wx.TOP|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
1445 | iy += 1 |
---|
1446 | ix = 0 |
---|
1447 | self.low_q_sizer.Add(npts_low_txt,(iy, ix), (1, 1), |
---|
1448 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
1449 | ix += 1 |
---|
1450 | self.low_q_sizer.Add(self.npts_low_tcl, (iy, ix), (1,1), |
---|
1451 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
1452 | iy += 1 |
---|
1453 | ix = 0 |
---|
1454 | self.low_q_sizer.Add(self.guinier,(iy, ix),(1,2), |
---|
1455 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
1456 | iy += 1 |
---|
1457 | ix = 0 |
---|
1458 | self.low_q_sizer.Add(self.power_law_low,(iy, ix), (1, 2), |
---|
1459 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
1460 | # Parameter controls for power law |
---|
1461 | ix = 1 |
---|
1462 | iy += 1 |
---|
1463 | self.low_q_sizer.Add(self.fix_enable_low,(iy, ix), (1, 1), |
---|
1464 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
1465 | ix += 1 |
---|
1466 | self.low_q_sizer.Add(self.fit_enable_low,(iy, ix),(1,1), |
---|
1467 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
1468 | ix = 1 |
---|
1469 | iy += 1 |
---|
1470 | self.low_q_sizer.Add(power_txt,(iy, ix), (1, 1), |
---|
1471 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
1472 | ix += 1 |
---|
1473 | self.low_q_sizer.Add(self.power_low_tcl, (iy, ix), (1, 1), |
---|
1474 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
1475 | self.low_extrapolation_sizer.Add(self.low_q_sizer) |
---|
1476 | |
---|
1477 | def _enable_fit_power_law_high(self, event=None): |
---|
1478 | """ |
---|
1479 | Enable and disable the power value editing |
---|
1480 | """ |
---|
1481 | if event != None: |
---|
1482 | self._set_bookmark_flag(True) |
---|
1483 | |
---|
1484 | self._set_preview_flag(False) |
---|
1485 | if self.fix_enable_high.IsEnabled(): |
---|
1486 | if self.fix_enable_high.GetValue(): |
---|
1487 | self.fit_enable_high.SetValue(False) |
---|
1488 | self.power_high_tcl.Enable() |
---|
1489 | else: |
---|
1490 | self.fit_enable_high.SetValue(True) |
---|
1491 | self.power_high_tcl.Disable() |
---|
1492 | self._set_state(event=event) |
---|
1493 | |
---|
1494 | def _enable_high_q_section(self, event=None): |
---|
1495 | """ |
---|
1496 | Disable or enable some button if the user enable high q extrapolation |
---|
1497 | """ |
---|
1498 | if event != None: |
---|
1499 | self._set_bookmark_flag(True) |
---|
1500 | self._set_preview_flag(False) |
---|
1501 | if self.enable_high_cbox.GetValue(): |
---|
1502 | self.npts_high_tcl.Enable() |
---|
1503 | self.power_law_high.Enable() |
---|
1504 | self.power_high_tcl.Enable() |
---|
1505 | self.fix_enable_high.Enable() |
---|
1506 | self.fit_enable_high.Enable() |
---|
1507 | else: |
---|
1508 | self.npts_high_tcl.Disable() |
---|
1509 | self.power_law_high.Disable() |
---|
1510 | self.power_high_tcl.Disable() |
---|
1511 | self.fix_enable_high.Disable() |
---|
1512 | self.fit_enable_high.Disable() |
---|
1513 | self._enable_fit_power_law_high() |
---|
1514 | self._set_state(event=event) |
---|
1515 | self.button_calculate.SetFocus() |
---|
1516 | |
---|
1517 | def _layout_extrapolation_high(self): |
---|
1518 | """ |
---|
1519 | Draw widgets related to extrapolation at high q range |
---|
1520 | """ |
---|
1521 | self.enable_high_cbox = wx.CheckBox(self, -1, |
---|
1522 | "Enable Extrapolate high-Q", |
---|
1523 | name='enable_high_cbox') |
---|
1524 | wx.EVT_CHECKBOX(self, self.enable_high_cbox.GetId(), |
---|
1525 | self._enable_high_q_section) |
---|
1526 | self.fix_enable_high = wx.RadioButton(self, -1, 'Fix', |
---|
1527 | (10, 10), style=wx.RB_GROUP, |
---|
1528 | name='fix_enable_high') |
---|
1529 | self.Bind(wx.EVT_RADIOBUTTON, self._enable_fit_power_law_high, |
---|
1530 | id=self.fix_enable_high.GetId()) |
---|
1531 | self.fit_enable_high = wx.RadioButton(self, -1, 'Fit', (10, 10), |
---|
1532 | name='fit_enable_high') |
---|
1533 | self.Bind(wx.EVT_RADIOBUTTON, self._enable_fit_power_law_high, |
---|
1534 | id=self.fit_enable_high.GetId()) |
---|
1535 | |
---|
1536 | self.power_law_high = wx.StaticText(self, -1, 'Power Law') |
---|
1537 | msg_hint ="Check to extrapolate data at high-Q" |
---|
1538 | self.power_law_high.SetToolTipString(msg_hint) |
---|
1539 | npts_high_txt = wx.StaticText(self, -1, 'Npts') |
---|
1540 | self.npts_high_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1), |
---|
1541 | name='npts_high_tcl') |
---|
1542 | wx.EVT_TEXT(self, self.npts_high_tcl.GetId(), self._on_text) |
---|
1543 | msg_hint = "Number of Q points to consider" |
---|
1544 | msg_hint += "while extrapolating the high-Q region" |
---|
1545 | self.npts_high_tcl.SetToolTipString(msg_hint) |
---|
1546 | power_txt = wx.StaticText(self, -1, 'Power') |
---|
1547 | self.power_high_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1), |
---|
1548 | name='power_high_tcl') |
---|
1549 | wx.EVT_TEXT(self, self.power_high_tcl.GetId(), self._on_text) |
---|
1550 | power_hint_txt = "Exponent to apply to the Power_law function." |
---|
1551 | self.power_high_tcl.SetToolTipString(power_hint_txt) |
---|
1552 | iy = 0 |
---|
1553 | ix = 0 |
---|
1554 | self.high_q_sizer.Add(self.enable_high_cbox, (iy, ix), (1, 5), |
---|
1555 | wx.TOP|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
1556 | iy += 1 |
---|
1557 | ix = 0 |
---|
1558 | self.high_q_sizer.Add(npts_high_txt, (iy, ix), (1, 1), |
---|
1559 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
1560 | ix += 1 |
---|
1561 | self.high_q_sizer.Add(self.npts_high_tcl, (iy, ix), (1, 1), |
---|
1562 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
1563 | iy += 1 |
---|
1564 | ix = 0 |
---|
1565 | self.high_q_sizer.Add(self.power_law_high, (iy, ix),(1, 2), |
---|
1566 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
1567 | |
---|
1568 | # Parameter controls for power law |
---|
1569 | ix = 1 |
---|
1570 | iy += 1 |
---|
1571 | self.high_q_sizer.Add(self.fix_enable_high,(iy, ix), (1, 1), |
---|
1572 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
1573 | ix += 1 |
---|
1574 | self.high_q_sizer.Add(self.fit_enable_high,(iy, ix), (1, 1), |
---|
1575 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
1576 | ix = 1 |
---|
1577 | iy += 1 |
---|
1578 | self.high_q_sizer.Add(power_txt,(iy, ix), (1, 1), |
---|
1579 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
1580 | ix += 1 |
---|
1581 | self.high_q_sizer.Add(self.power_high_tcl, (iy, ix), (1, 1), |
---|
1582 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
1583 | self.high_extrapolation_sizer.Add(self.high_q_sizer, 0, |
---|
1584 | wx.BOTTOM, 20) |
---|
1585 | |
---|
1586 | def _layout_extrapolation(self): |
---|
1587 | """ |
---|
1588 | Draw widgets related to extrapolation |
---|
1589 | """ |
---|
1590 | extra_hint = "Extrapolation \nMaximum Q Range [1/A]:" |
---|
1591 | extra_hint_txt = wx.StaticText(self, -1, extra_hint) |
---|
1592 | #Extrapolation range [string] |
---|
1593 | extrapolation_min_txt = wx.StaticText(self, -1, 'Min:') |
---|
1594 | self.extrapolation_min_tcl = OutputTextCtrl(self, -1, |
---|
1595 | size=(_BOX_WIDTH, 20), style=0, |
---|
1596 | name='extrapolation_min_tcl') |
---|
1597 | self.extrapolation_min_tcl.SetValue(str(Q_MINIMUM)) |
---|
1598 | hint_msg = "The minimum extrapolated q value." |
---|
1599 | self.extrapolation_min_tcl.SetToolTipString(hint_msg) |
---|
1600 | extrapolation_max_txt = wx.StaticText(self, -1, 'Max:') |
---|
1601 | self.extrapolation_max_tcl = OutputTextCtrl(self, -1, |
---|
1602 | size=(_BOX_WIDTH, 20), |
---|
1603 | style=0, |
---|
1604 | name='extrapolation_max_tcl') |
---|
1605 | self.extrapolation_max_tcl.SetValue(str(Q_MAXIMUM)) |
---|
1606 | hint_msg = "The maximum extrapolated q value." |
---|
1607 | self.extrapolation_max_tcl.SetToolTipString(hint_msg) |
---|
1608 | self.extrapolation_range_sizer.AddMany([(extra_hint_txt, 0, |
---|
1609 | wx.LEFT, 5), |
---|
1610 | (extrapolation_min_txt, 0, |
---|
1611 | wx.LEFT, 10), |
---|
1612 | (self.extrapolation_min_tcl, |
---|
1613 | 0, wx.LEFT, 5), |
---|
1614 | (extrapolation_max_txt, 0, |
---|
1615 | wx.LEFT, 20), |
---|
1616 | (self.extrapolation_max_tcl, |
---|
1617 | 0, wx.LEFT, 5)]) |
---|
1618 | self._layout_extrapolation_low() |
---|
1619 | self._layout_extrapolation_high() |
---|
1620 | self.extrapolation_low_high_sizer.AddMany([(self.low_extrapolation_sizer, |
---|
1621 | 0, wx.LEFT|wx.BOTTOM|wx.TOP, 5), |
---|
1622 | (self.high_extrapolation_sizer, |
---|
1623 | 0, wx.LEFT|wx.BOTTOM|wx.TOP, 5)]) |
---|
1624 | self.extrapolation_sizer.AddMany([(self.extrapolation_range_sizer), |
---|
1625 | (self.extrapolation_low_high_sizer)]) |
---|
1626 | |
---|
1627 | def _layout_volume_surface_sizer(self): |
---|
1628 | """ |
---|
1629 | Draw widgets related to volume and surface |
---|
1630 | """ |
---|
1631 | unit_volume = '' |
---|
1632 | unit_surface = '' |
---|
1633 | uncertainty = "+/-" |
---|
1634 | volume_txt = wx.StaticText(self, -1, 'Volume Fraction') |
---|
1635 | self.volume_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, -1), |
---|
1636 | name='volume_tcl') |
---|
1637 | wx.EVT_TEXT(self, self.volume_tcl.GetId(), self._on_out_text) |
---|
1638 | self.volume_tcl.SetToolTipString("Volume fraction.") |
---|
1639 | self.volume_err_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, -1), |
---|
1640 | name='volume_err_tcl') |
---|
1641 | wx.EVT_TEXT(self, self.volume_err_tcl.GetId(), self._on_out_text) |
---|
1642 | hint_msg = "Uncertainty on the volume fraction." |
---|
1643 | self.volume_err_tcl.SetToolTipString(hint_msg) |
---|
1644 | volume_units_txt = wx.StaticText(self, -1, unit_volume) |
---|
1645 | |
---|
1646 | surface_txt = wx.StaticText(self, -1, 'Specific Surface') |
---|
1647 | self.surface_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, -1), |
---|
1648 | name='surface_tcl') |
---|
1649 | wx.EVT_TEXT(self, self.surface_tcl.GetId(), self._on_out_text) |
---|
1650 | self.surface_tcl.SetToolTipString("Specific surface value.") |
---|
1651 | self.surface_err_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, -1), |
---|
1652 | name='surface_err_tcl') |
---|
1653 | wx.EVT_TEXT(self, self.surface_err_tcl.GetId(), self._on_out_text) |
---|
1654 | hint_msg = "Uncertainty on the specific surface." |
---|
1655 | self.surface_err_tcl.SetToolTipString(hint_msg) |
---|
1656 | surface_units_txt = wx.StaticText(self, -1, unit_surface) |
---|
1657 | iy = 0 |
---|
1658 | ix = 0 |
---|
1659 | self.volume_surface_sizer.Add(volume_txt, (iy, ix), (1, 1), |
---|
1660 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
1661 | ix += 1 |
---|
1662 | self.volume_surface_sizer.Add(self.volume_tcl, (iy, ix), (1, 1), |
---|
1663 | wx.EXPAND|wx.ADJUST_MINSIZE, 20) |
---|
1664 | ix += 1 |
---|
1665 | self.volume_surface_sizer.Add(wx.StaticText(self, -1, uncertainty), |
---|
1666 | (iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
1667 | ix += 1 |
---|
1668 | self.volume_surface_sizer.Add(self.volume_err_tcl, (iy, ix), (1, 1), |
---|
1669 | wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
1670 | ix += 1 |
---|
1671 | self.volume_surface_sizer.Add(volume_units_txt, (iy, ix), (1, 1), |
---|
1672 | wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
1673 | iy += 1 |
---|
1674 | ix = 0 |
---|
1675 | self.volume_surface_sizer.Add(surface_txt, (iy, ix), (1, 1), |
---|
1676 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
1677 | ix += 1 |
---|
1678 | self.volume_surface_sizer.Add(self.surface_tcl, (iy, ix), (1, 1), |
---|
1679 | wx.EXPAND|wx.ADJUST_MINSIZE, 20) |
---|
1680 | ix += 1 |
---|
1681 | self.volume_surface_sizer.Add(wx.StaticText(self, -1, uncertainty), |
---|
1682 | (iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
1683 | ix += 1 |
---|
1684 | self.volume_surface_sizer.Add(self.surface_err_tcl, (iy, ix), (1, 1), |
---|
1685 | wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
1686 | ix += 1 |
---|
1687 | self.volume_surface_sizer.Add(surface_units_txt, (iy, ix), (1, 1), |
---|
1688 | wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
1689 | static_line = wx.StaticLine(self, -1) |
---|
1690 | iy += 1 |
---|
1691 | ix = 0 |
---|
1692 | |
---|
1693 | def _layout_invariant_sizer(self): |
---|
1694 | """ |
---|
1695 | Draw widgets related to invariant |
---|
1696 | """ |
---|
1697 | uncertainty = "+/-" |
---|
1698 | unit_invariant = '[1/(cm * A)]' |
---|
1699 | invariant_total_txt = wx.StaticText(self, -1, 'Invariant Total [Q*]') |
---|
1700 | self.invariant_total_tcl = OutputTextCtrl(self, -1, |
---|
1701 | size=(_BOX_WIDTH,-1), |
---|
1702 | name='invariant_total_tcl') |
---|
1703 | msg_hint = "Total invariant [Q*], including extrapolated regions." |
---|
1704 | self.invariant_total_tcl.SetToolTipString(msg_hint) |
---|
1705 | self.invariant_total_err_tcl = OutputTextCtrl(self, -1, |
---|
1706 | size=(_BOX_WIDTH,-1), |
---|
1707 | name='invariant_total_err_tcl') |
---|
1708 | hint_msg = "Uncertainty on invariant." |
---|
1709 | self.invariant_total_err_tcl.SetToolTipString(hint_msg) |
---|
1710 | invariant_total_units_txt = wx.StaticText(self, -1, unit_invariant) |
---|
1711 | |
---|
1712 | #Invariant total |
---|
1713 | iy = 0 |
---|
1714 | ix = 0 |
---|
1715 | self.invariant_sizer.Add(invariant_total_txt, (iy, ix), (1, 1), |
---|
1716 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
1717 | ix += 1 |
---|
1718 | self.invariant_sizer.Add(self.invariant_total_tcl, (iy, ix), (1, 1), |
---|
1719 | wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
1720 | ix += 1 |
---|
1721 | self.invariant_sizer.Add( wx.StaticText(self, -1, uncertainty), |
---|
1722 | (iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
1723 | ix += 1 |
---|
1724 | self.invariant_sizer.Add(self.invariant_total_err_tcl, (iy, ix), (1, 1), |
---|
1725 | wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
1726 | ix += 1 |
---|
1727 | self.invariant_sizer.Add(invariant_total_units_txt,(iy, ix), (1, 1), |
---|
1728 | wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
1729 | |
---|
1730 | def _layout_inputs_sizer(self): |
---|
1731 | """ |
---|
1732 | Draw widgets related to inputs |
---|
1733 | """ |
---|
1734 | contrast_txt = wx.StaticText(self, -1, 'Contrast :') |
---|
1735 | self.contrast_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH, 20), |
---|
1736 | style=0,name='contrast_tcl') |
---|
1737 | wx.EVT_TEXT(self, self.contrast_tcl.GetId(), self._on_text) |
---|
1738 | contrast_hint_txt = "Contrast" |
---|
1739 | self.contrast_tcl.SetToolTipString(contrast_hint_txt) |
---|
1740 | contrast_unit_txt = wx.StaticText(self, -1, '[1/A^(2)]') |
---|
1741 | porod_const_txt = wx.StaticText(self, -1, 'Porod Constant:\n(optional)\n') |
---|
1742 | self.porod_constant_tcl = InvTextCtrl(self, -1, |
---|
1743 | size=(_BOX_WIDTH, 20), style=0, |
---|
1744 | name='porod_constant_tcl') |
---|
1745 | wx.EVT_TEXT(self, self.porod_constant_tcl.GetId(), self._on_text) |
---|
1746 | porod_const_hint_txt = "Porod Constant" |
---|
1747 | self.porod_constant_tcl.SetToolTipString(porod_const_hint_txt) |
---|
1748 | |
---|
1749 | background_txt = wx.StaticText(self, -1, 'Background : ') |
---|
1750 | self.background_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH, 20), |
---|
1751 | style=0, name='background_tcl') |
---|
1752 | wx.EVT_TEXT(self, self.background_tcl.GetId(), self._on_text) |
---|
1753 | background_hint_txt = "Background" |
---|
1754 | self.background_tcl.SetToolTipString(background_hint_txt) |
---|
1755 | background_unit_txt = wx.StaticText(self, -1, '[1/cm]') |
---|
1756 | scale_txt = wx.StaticText(self, -1, 'Scale : ') |
---|
1757 | self.scale_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0, |
---|
1758 | name='scale_tcl') |
---|
1759 | wx.EVT_TEXT(self, self.scale_tcl.GetId(), self._on_text) |
---|
1760 | scale_hint_txt = "Scale" |
---|
1761 | self.scale_tcl.SetToolTipString(scale_hint_txt) |
---|
1762 | self.sizer_input.AddMany([(background_txt, 0, wx.LEFT|wx.BOTTOM, 5), |
---|
1763 | (self.background_tcl, 0, wx.LEFT|wx.BOTTOM, 5), |
---|
1764 | (background_unit_txt, 0, wx.LEFT|wx.BOTTOM, 5), |
---|
1765 | (scale_txt, 0, wx.LEFT|wx.BOTTOM, 20), |
---|
1766 | (self.scale_tcl, 0, wx.LEFT|wx.BOTTOM|wx.RIGHT, 5), |
---|
1767 | (contrast_txt, 0, wx.LEFT|wx.BOTTOM, 5), |
---|
1768 | (self.contrast_tcl, 0, wx.LEFT|wx.BOTTOM, 5), |
---|
1769 | (contrast_unit_txt, 0, wx.LEFT|wx.BOTTOM, 5), |
---|
1770 | (porod_const_txt, 0, wx.LEFT, 20), |
---|
1771 | (self.porod_constant_tcl, 0, wx.LEFT|wx.BOTTOM|wx.RIGHT, 5)]) |
---|
1772 | self.inputs_sizer.Add(self.sizer_input) |
---|
1773 | |
---|
1774 | def _layout_outputs_sizer(self): |
---|
1775 | """ |
---|
1776 | Draw widgets related to outputs |
---|
1777 | """ |
---|
1778 | self._layout_volume_surface_sizer() |
---|
1779 | self._layout_invariant_sizer() |
---|
1780 | static_line = wx.StaticLine(self, -1) |
---|
1781 | self.outputs_sizer.AddMany([(self.volume_surface_sizer, |
---|
1782 | 0, wx.TOP|wx.BOTTOM, 10), |
---|
1783 | (static_line, 0, wx.EXPAND, 0), |
---|
1784 | (self.invariant_sizer, 0, wx.TOP|wx.BOTTOM, 10)]) |
---|
1785 | def _layout_button(self): |
---|
1786 | """ |
---|
1787 | Do the layout for the button widgets |
---|
1788 | """ |
---|
1789 | #compute button |
---|
1790 | id = wx.NewId() |
---|
1791 | self.button_calculate = wx.Button(self, id, "Compute", |
---|
1792 | name='compute_invariant') |
---|
1793 | self.button_calculate.SetToolTipString("Compute invariant") |
---|
1794 | self.Bind(wx.EVT_BUTTON, self.compute_invariant, id=id) |
---|
1795 | #detail button |
---|
1796 | id = wx.NewId() |
---|
1797 | self.button_details = wx.Button(self, id, "Details?") |
---|
1798 | hint_msg = "Details about the results of the computation" |
---|
1799 | self.button_details.SetToolTipString(hint_msg) |
---|
1800 | self.Bind(wx.EVT_BUTTON, self.display_details, id=id) |
---|
1801 | details = "Details on Invariant Total Calculations" |
---|
1802 | details_txt = wx.StaticText(self, -1, details) |
---|
1803 | self.button_sizer.AddMany([(details_txt, 0 , |
---|
1804 | wx.RIGHT|wx.BOTTOM|wx.TOP, 10), |
---|
1805 | (self.button_details, 0 , wx.ALL, 10), |
---|
1806 | (self.button_calculate, 0 , |
---|
1807 | wx.RIGHT|wx.TOP|wx.BOTTOM, 10)]) |
---|
1808 | def _do_layout(self): |
---|
1809 | """ |
---|
1810 | Draw window content |
---|
1811 | """ |
---|
1812 | self._define_structure() |
---|
1813 | self._layout_data_name() |
---|
1814 | self._layout_extrapolation() |
---|
1815 | self._layout_inputs_sizer() |
---|
1816 | self._layout_outputs_sizer() |
---|
1817 | self._layout_button() |
---|
1818 | self.main_sizer.AddMany([(self.data_name_boxsizer,0, wx.ALL, 10), |
---|
1819 | (self.outputs_sizer, 0, |
---|
1820 | wx.LEFT|wx.RIGHT|wx.BOTTOM, 10), |
---|
1821 | (self.button_sizer, 0, wx.LEFT|wx.RIGHT, 15), |
---|
1822 | (self.inputs_sizer, 0, |
---|
1823 | wx.LEFT|wx.RIGHT|wx.BOTTOM, 10), |
---|
1824 | (self.extrapolation_sizer, 0, |
---|
1825 | wx.LEFT|wx.RIGHT|wx.BOTTOM, 10)]) |
---|
1826 | self.SetSizer(self.main_sizer) |
---|
1827 | self.SetAutoLayout(True) |
---|
1828 | |
---|
1829 | |
---|
1830 | class InvariantDialog(wx.Dialog): |
---|
1831 | """ |
---|
1832 | """ |
---|
1833 | def __init__(self, parent=None, id=1,graph=None, |
---|
1834 | data=None, title="Invariant",base=None): |
---|
1835 | wx.Dialog.__init__(self, parent, id, title, size=(PANEL_WIDTH, |
---|
1836 | PANEL_HEIGHT)) |
---|
1837 | self.panel = InvariantPanel(self) |
---|
1838 | self.Centre() |
---|
1839 | self.Show(True) |
---|
1840 | |
---|
1841 | class InvariantWindow(wx.Frame): |
---|
1842 | """ |
---|
1843 | """ |
---|
1844 | def __init__(self, parent=None, id=1, graph=None, |
---|
1845 | data=None, title="Invariant", base=None): |
---|
1846 | |
---|
1847 | wx.Frame.__init__(self, parent, id, title, size=(PANEL_WIDTH +100, |
---|
1848 | PANEL_HEIGHT+100)) |
---|
1849 | from sans.dataloader.loader import Loader |
---|
1850 | self.loader = Loader() |
---|
1851 | import invariant |
---|
1852 | path = "C:/ECLPS/workspace/trunk/sansdataloader/test/ascii_test_3.txt" |
---|
1853 | data= self.loader.load(path) |
---|
1854 | self.panel = InvariantPanel(self) |
---|
1855 | |
---|
1856 | data.name = data.filename |
---|
1857 | self.panel.set_data(data) |
---|
1858 | self.Centre() |
---|
1859 | self.Show(True) |
---|
1860 | |
---|
1861 | class MyApp(wx.App): |
---|
1862 | def OnInit(self): |
---|
1863 | wx.InitAllImageHandlers() |
---|
1864 | frame = InvariantWindow() |
---|
1865 | frame.Show(True) |
---|
1866 | self.SetTopWindow(frame) |
---|
1867 | |
---|
1868 | return True |
---|
1869 | |
---|
1870 | # end of class MyApp |
---|
1871 | |
---|
1872 | if __name__ == "__main__": |
---|
1873 | app = MyApp(0) |
---|
1874 | app.MainLoop() |
---|