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