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