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