1 | """ |
---|
2 | This module provide GUI for the neutron scattering length density calculator |
---|
3 | @author: Gervaise B. Alina |
---|
4 | """ |
---|
5 | |
---|
6 | import wx |
---|
7 | import sys |
---|
8 | |
---|
9 | from sans.invariant import invariant |
---|
10 | from sans.guiframe.utils import format_number, check_float |
---|
11 | from sans.guicomm.events import NewPlotEvent, StatusEvent |
---|
12 | from invariant_details import InvariantDetailsPanel |
---|
13 | from invariant_widgets import OutputTextCtrl, InvTextCtrl |
---|
14 | # The minimum q-value to be used when extrapolating |
---|
15 | Q_MINIMUM = 1e-5 |
---|
16 | # The maximum q-value to be used when extrapolating |
---|
17 | Q_MAXIMUM = 10 |
---|
18 | # the maximum value to plot the theory data |
---|
19 | Q_MAXIMUM_PLOT = 2 |
---|
20 | # the number of points to consider during fit |
---|
21 | NPTS = 10 |
---|
22 | #Default value for background |
---|
23 | BACKGROUND = 0.0 |
---|
24 | #default value for the scale |
---|
25 | SCALE = 1.0 |
---|
26 | #default value of the contrast |
---|
27 | CONTRAST = 1.0 |
---|
28 | #Invariant panel size |
---|
29 | _BOX_WIDTH = 76 |
---|
30 | #scale to use for a bar of value zero |
---|
31 | RECTANGLE_SCALE = 0.0001 |
---|
32 | |
---|
33 | if sys.platform.count("win32")>0: |
---|
34 | _STATICBOX_WIDTH = 450 |
---|
35 | PANEL_WIDTH = 500 |
---|
36 | PANEL_HEIGHT = 700 |
---|
37 | FONT_VARIANT = 0 |
---|
38 | else: |
---|
39 | _STATICBOX_WIDTH = 480 |
---|
40 | PANEL_WIDTH = 530 |
---|
41 | PANEL_HEIGHT = 700 |
---|
42 | FONT_VARIANT = 1 |
---|
43 | |
---|
44 | class InvariantContainer(wx.Object): |
---|
45 | def __init__(self): |
---|
46 | #invariant at low range |
---|
47 | self.qstar_low = None |
---|
48 | #invariant at low range error |
---|
49 | self.qstar_low_err = None |
---|
50 | #invariant |
---|
51 | self.qstar = None |
---|
52 | #invariant error |
---|
53 | self.qstar_err = None |
---|
54 | #invariant at high range |
---|
55 | self.qstar_high = None |
---|
56 | #invariant at high range error |
---|
57 | self.qstar_high_err = None |
---|
58 | #invariant total |
---|
59 | self.qstar_total = None |
---|
60 | #invariant error |
---|
61 | self.qstar_total_err = None |
---|
62 | #scale |
---|
63 | self.qstar_low_scale = RECTANGLE_SCALE |
---|
64 | self.qstar_scale = RECTANGLE_SCALE |
---|
65 | self.qstar_high_scale = RECTANGLE_SCALE |
---|
66 | |
---|
67 | class InvariantPanel(wx.ScrolledWindow): |
---|
68 | """ |
---|
69 | Provides the Invariant GUI. |
---|
70 | """ |
---|
71 | ## Internal nickname for the window, used by the AUI manager |
---|
72 | window_name = "Invariant" |
---|
73 | ## Name to appear on the window title bar |
---|
74 | window_caption = "Invariant" |
---|
75 | ## Flag to tell the AUI manager to put this panel in the center pane |
---|
76 | CENTER_PANE = True |
---|
77 | def __init__(self, parent, data=None, manager=None): |
---|
78 | wx.ScrolledWindow.__init__(self, parent, style= wx.FULL_REPAINT_ON_RESIZE ) |
---|
79 | #Font size |
---|
80 | self.SetWindowVariant(variant=FONT_VARIANT) |
---|
81 | #Object that receive status event |
---|
82 | self.parent = parent |
---|
83 | #plug-in using this panel |
---|
84 | self._manager = manager |
---|
85 | #Default power value |
---|
86 | self.power_law_exponant = 4 |
---|
87 | #Data uses for computation |
---|
88 | self._data = data |
---|
89 | #container of invariant value |
---|
90 | self.inv_container = None |
---|
91 | #Draw the panel |
---|
92 | self._do_layout() |
---|
93 | if self.parent is not None: |
---|
94 | msg = "" |
---|
95 | wx.PostEvent(self.parent, StatusEvent(status= msg)) |
---|
96 | |
---|
97 | def err_check_on_data(self): |
---|
98 | """ |
---|
99 | Check if data is valid for further computation |
---|
100 | """ |
---|
101 | flag = False |
---|
102 | #edit the panel |
---|
103 | if self._data is not None: |
---|
104 | if len(self._data.x[self._data.x==0]) > 0: |
---|
105 | flag = True |
---|
106 | msg = "Invariant: one of your q-values is zero. Delete that entry before proceeding" |
---|
107 | wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) |
---|
108 | return flag |
---|
109 | |
---|
110 | def set_data(self, data): |
---|
111 | """ |
---|
112 | Set the data |
---|
113 | """ |
---|
114 | self._data = data |
---|
115 | #edit the panel |
---|
116 | if self._data is not None: |
---|
117 | self.err_check_on_data() |
---|
118 | data_name = self._data.name |
---|
119 | data_qmin = min (self._data.x) |
---|
120 | data_qmax = max (self._data.x) |
---|
121 | self.data_name_tcl.SetValue(str(data_name)) |
---|
122 | self.data_min_tcl.SetLabel(str(data_qmin)) |
---|
123 | self.data_max_tcl.SetLabel(str(data_qmax)) |
---|
124 | self.hint_msg_txt.SetLabel('') |
---|
125 | |
---|
126 | def set_manager(self, manager): |
---|
127 | """ |
---|
128 | set value for the manager |
---|
129 | """ |
---|
130 | self._manager = manager |
---|
131 | |
---|
132 | def get_background(self): |
---|
133 | """ |
---|
134 | @return the background textcrtl value as a float |
---|
135 | """ |
---|
136 | background = self.background_tcl.GetValue().lstrip().rstrip() |
---|
137 | if background == "": |
---|
138 | raise ValueError, "Need a background" |
---|
139 | if check_float(self.background_tcl): |
---|
140 | return float(background) |
---|
141 | else: |
---|
142 | raise ValueError, "Receive invalid value for background : %s"%(background) |
---|
143 | |
---|
144 | def get_scale(self): |
---|
145 | """ |
---|
146 | @return the scale textcrtl value as a float |
---|
147 | """ |
---|
148 | scale = self.scale_tcl.GetValue().lstrip().rstrip() |
---|
149 | if scale == "": |
---|
150 | raise ValueError, "Need a background" |
---|
151 | if check_float(self.scale_tcl): |
---|
152 | return float(scale) |
---|
153 | else: |
---|
154 | raise ValueError, "Receive invalid value for background : %s"%(scale) |
---|
155 | |
---|
156 | def get_contrast(self): |
---|
157 | """ |
---|
158 | @return the contrast textcrtl value as a float |
---|
159 | """ |
---|
160 | par_str = self.contrast_tcl.GetValue().strip() |
---|
161 | contrast = None |
---|
162 | if par_str !="" and check_float(self.contrast_tcl): |
---|
163 | contrast = float(par_str) |
---|
164 | return contrast |
---|
165 | |
---|
166 | def get_extrapolation_type(self, low_q, high_q): |
---|
167 | """ |
---|
168 | """ |
---|
169 | extrapolation = None |
---|
170 | if low_q and not high_q: |
---|
171 | extrapolation = "low" |
---|
172 | elif not low_q and high_q: |
---|
173 | extrapolation = "high" |
---|
174 | elif low_q and high_q: |
---|
175 | extrapolation = "both" |
---|
176 | return extrapolation |
---|
177 | |
---|
178 | def get_porod_const(self): |
---|
179 | """ |
---|
180 | @return the porod constant textcrtl value as a float |
---|
181 | """ |
---|
182 | par_str = self.porod_constant_tcl.GetValue().strip() |
---|
183 | porod_const = None |
---|
184 | if par_str !="" and check_float(self.porod_constant_tcl): |
---|
185 | porod_const = float(par_str) |
---|
186 | return porod_const |
---|
187 | |
---|
188 | def get_volume(self, inv, contrast, extrapolation): |
---|
189 | """ |
---|
190 | """ |
---|
191 | if contrast is not None: |
---|
192 | try: |
---|
193 | v, dv = inv.get_volume_fraction_with_error(contrast=contrast, |
---|
194 | extrapolation=extrapolation) |
---|
195 | self.volume_tcl.SetValue(format_number(v)) |
---|
196 | self.volume_err_tcl.SetValue(format_number(dv)) |
---|
197 | except: |
---|
198 | raise |
---|
199 | msg= "Error occurred computing volume fraction: %s"%sys.exc_value |
---|
200 | wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) |
---|
201 | |
---|
202 | def get_surface(self, inv, contrast, porod_const, extrapolation): |
---|
203 | """ |
---|
204 | """ |
---|
205 | if contrast is not None and porod_const is not None: |
---|
206 | try: |
---|
207 | s, ds = inv.get_surface_with_error(contrast=contrast, |
---|
208 | porod_const=porod_const, |
---|
209 | extrapolation=extrapolation) |
---|
210 | self.surface_tcl.SetValue(format_number(s)) |
---|
211 | self.surface_err_tcl.SetValue(format_number(ds)) |
---|
212 | except: |
---|
213 | msg= "Error occurred computing specific surface: %s"%sys.exc_value |
---|
214 | wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) |
---|
215 | |
---|
216 | def get_total_qstar(self, inv, extrapolation): |
---|
217 | """ |
---|
218 | """ |
---|
219 | try: |
---|
220 | qstar_total, qstar_total_err = inv.get_qstar_with_error(extrapolation) |
---|
221 | self.invariant_total_tcl.SetValue(format_number(qstar_total)) |
---|
222 | self.invariant_total_err_tcl.SetValue(format_number(qstar_total_err)) |
---|
223 | self.inv_container.qstar_total = qstar_total |
---|
224 | self.inv_container.qstar_total_err = qstar_total_err |
---|
225 | |
---|
226 | except: |
---|
227 | msg= "Error occurred computing invariant using extrapolation: %s"%sys.exc_value |
---|
228 | wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) |
---|
229 | |
---|
230 | def get_low_qstar(self, inv, npts_low, low_q=False): |
---|
231 | """ |
---|
232 | """ |
---|
233 | if low_q: |
---|
234 | try: |
---|
235 | qstar_low, qstar_low_err = inv.get_qstar_low() |
---|
236 | self.inv_container.qstar_low = qstar_low |
---|
237 | self.inv_container.qstar_low_err = qstar_low_err |
---|
238 | extrapolated_data = inv.get_extra_data_low(npts_in=npts_low) |
---|
239 | power_low = inv.get_extrapolation_power(range='low') |
---|
240 | if self.power_law_low.GetValue(): |
---|
241 | self.power_low_tcl.SetValue(str(power_low)) |
---|
242 | self._manager.plot_theory(data=extrapolated_data, |
---|
243 | name="Low-Q extrapolation") |
---|
244 | except: |
---|
245 | msg= "Error occurred computing low-Q invariant: %s"%sys.exc_value |
---|
246 | wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) |
---|
247 | else: |
---|
248 | self._manager.plot_theory(name="Low-Q extrapolation") |
---|
249 | |
---|
250 | def get_high_qstar(self, inv, high_q=False): |
---|
251 | """ |
---|
252 | """ |
---|
253 | if high_q: |
---|
254 | try: |
---|
255 | qstar_high, qstar_high_err = inv.get_qstar_high() |
---|
256 | self.inv_container.qstar_high = qstar_high |
---|
257 | self.inv_container.qstar_high_err = qstar_high_err |
---|
258 | power_high = inv.get_extrapolation_power(range='high') |
---|
259 | self.power_high_tcl.SetValue(str(power_high)) |
---|
260 | high_out_data = inv.get_extra_data_high(q_end=Q_MAXIMUM_PLOT) |
---|
261 | self._manager.plot_theory(data=high_out_data, |
---|
262 | name="High-Q extrapolation") |
---|
263 | except: |
---|
264 | msg= "Error occurred computing high-Q invariant: %s"%sys.exc_value |
---|
265 | wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) |
---|
266 | else: |
---|
267 | self._manager.plot_theory(name="High-Q extrapolation") |
---|
268 | |
---|
269 | def get_qstar(self, inv): |
---|
270 | """ |
---|
271 | """ |
---|
272 | qstar, qstar_err = inv.get_qstar_with_error() |
---|
273 | self.inv_container.qstar = qstar |
---|
274 | self.inv_container.qstar_err = qstar_err |
---|
275 | |
---|
276 | def set_extrapolation_low(self, inv, low_q=False): |
---|
277 | """ |
---|
278 | @return float value necessary to compute invariant a low q |
---|
279 | """ |
---|
280 | #get funtion |
---|
281 | if self.guinier.GetValue(): |
---|
282 | function_low = "guinier" |
---|
283 | # get the function |
---|
284 | power_low = None #2.0/3.0 |
---|
285 | if self.power_law_low.GetValue(): |
---|
286 | function_low = "power_law" |
---|
287 | if self.fit_enable_low.GetValue(): |
---|
288 | #set value of power_low to none to allow fitting |
---|
289 | power_low = None |
---|
290 | else: |
---|
291 | power_low = self.power_low_tcl.GetValue().lstrip().rstrip() |
---|
292 | if check_float(self.power_low_tcl): |
---|
293 | power_low = float(power_low) |
---|
294 | else: |
---|
295 | if low_q : |
---|
296 | #Raise error only when qstar at low q is requested |
---|
297 | msg = "Expect float for power at low q , got %s"%(power_low) |
---|
298 | raise ValueError, msg |
---|
299 | |
---|
300 | #Get the number of points to extrapolated |
---|
301 | npts_low = self.npts_low_tcl.GetValue().lstrip().rstrip() |
---|
302 | if check_float(self.npts_low_tcl): |
---|
303 | npts_low = float(npts_low) |
---|
304 | else: |
---|
305 | if low_q: |
---|
306 | msg = "Expect float for number of points at low q , got %s"%(npts_low) |
---|
307 | raise ValueError, msg |
---|
308 | #Set the invariant calculator |
---|
309 | inv.set_extrapolation(range="low", npts=npts_low, |
---|
310 | function=function_low, power=power_low) |
---|
311 | return inv, npts_low |
---|
312 | |
---|
313 | def set_extrapolation_high(self, inv, high_q=False): |
---|
314 | """ |
---|
315 | @return float value necessary to compute invariant a high q |
---|
316 | """ |
---|
317 | power_high = None |
---|
318 | #if self.power_law_high.GetValue(): |
---|
319 | function_high = "power_law" |
---|
320 | if self.fit_enable_high.GetValue(): |
---|
321 | #set value of power_high to none to allow fitting |
---|
322 | power_high = None |
---|
323 | else: |
---|
324 | power_high = self.power_high_tcl.GetValue().lstrip().rstrip() |
---|
325 | if check_float(self.power_high_tcl): |
---|
326 | power_high = float(power_high) |
---|
327 | else: |
---|
328 | if high_q : |
---|
329 | #Raise error only when qstar at high q is requested |
---|
330 | msg = "Expect float for power at high q , got %s"%(power_high) |
---|
331 | raise ValueError, msg |
---|
332 | |
---|
333 | npts_high = self.npts_high_tcl.GetValue().lstrip().rstrip() |
---|
334 | if check_float(self.npts_high_tcl): |
---|
335 | npts_high = float(npts_high) |
---|
336 | else: |
---|
337 | if high_q: |
---|
338 | msg = "Expect float for number of points at high q , got %s"%(npts_high) |
---|
339 | raise ValueError, msg |
---|
340 | inv.set_extrapolation(range="high", npts=npts_high, |
---|
341 | function=function_high, power=power_high) |
---|
342 | return inv, npts_high |
---|
343 | |
---|
344 | def display_details(self, event): |
---|
345 | """ |
---|
346 | open another panel for more details on invariant calculation |
---|
347 | """ |
---|
348 | #panel = InvariantDetailsWindow(parent=self.parent, |
---|
349 | # qstar_container=self.inv_container) |
---|
350 | panel = InvariantDetailsPanel(parent=self, |
---|
351 | qstar_container=self.inv_container) |
---|
352 | panel.ShowModal() |
---|
353 | panel.Destroy() |
---|
354 | |
---|
355 | def compute_invariant(self, event): |
---|
356 | """ |
---|
357 | compute invariant |
---|
358 | """ |
---|
359 | msg= "" |
---|
360 | wx.PostEvent(self.parent, StatusEvent(status= msg)) |
---|
361 | if self._data is None or self.err_check_on_data(): |
---|
362 | return |
---|
363 | |
---|
364 | #clear outputs textctrl |
---|
365 | self._reset_output() |
---|
366 | try: |
---|
367 | background = self.get_background() |
---|
368 | scale = self.get_scale() |
---|
369 | except: |
---|
370 | msg= "Invariant Error: %s"%(sys.exc_value) |
---|
371 | wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) |
---|
372 | return |
---|
373 | |
---|
374 | low_q = self.enable_low_cbox.GetValue() |
---|
375 | high_q = self.enable_high_cbox.GetValue() |
---|
376 | #set invariant calculator |
---|
377 | inv = invariant.InvariantCalculator(data=self._data, |
---|
378 | background=background, |
---|
379 | scale=scale) |
---|
380 | try: |
---|
381 | inv, npts_low = self.set_extrapolation_low(inv=inv, low_q=low_q) |
---|
382 | inv, npts_high = self.set_extrapolation_high(inv=inv, high_q=high_q) |
---|
383 | except: |
---|
384 | raise |
---|
385 | #msg= "Error occurred computing invariant: %s"%sys.exc_value |
---|
386 | #wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) |
---|
387 | return |
---|
388 | #check the type of extrapolation |
---|
389 | extrapolation = self.get_extrapolation_type(low_q=low_q, high_q=high_q) |
---|
390 | |
---|
391 | #Compute invariant |
---|
392 | try: |
---|
393 | self.get_qstar(inv=inv) |
---|
394 | except: |
---|
395 | msg= "Error occurred computing invariant: %s"%sys.exc_value |
---|
396 | wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) |
---|
397 | return |
---|
398 | #Compute qstar extrapolated to low q range |
---|
399 | self.get_low_qstar(inv=inv, npts_low=npts_low, low_q=low_q) |
---|
400 | #Compute qstar extrapolated to high q range |
---|
401 | self.get_high_qstar(inv=inv, high_q=high_q) |
---|
402 | #Compute qstar extrapolated to total q range and set value to txtcrtl |
---|
403 | self.get_total_qstar(inv=inv, extrapolation=extrapolation) |
---|
404 | # Parse additional parameters |
---|
405 | porod_const = self.get_porod_const() |
---|
406 | contrast = self.get_contrast() |
---|
407 | try: |
---|
408 | #Compute volume and set value to txtcrtl |
---|
409 | self.get_volume(inv=inv, contrast=contrast, extrapolation=extrapolation) |
---|
410 | #compute surface and set value to txtcrtl |
---|
411 | except: |
---|
412 | msg= "Error occurred computing invariant: %s"%sys.exc_value |
---|
413 | wx.PostEvent(self.parent, StatusEvent(status= msg)) |
---|
414 | try: |
---|
415 | self.get_surface(inv=inv, contrast=contrast, porod_const=porod_const, |
---|
416 | extrapolation=extrapolation) |
---|
417 | except: |
---|
418 | msg= "Error occurred computing invariant: %s"%sys.exc_value |
---|
419 | wx.PostEvent(self.parent, StatusEvent(status= msg)) |
---|
420 | |
---|
421 | #enable the button_ok for more details |
---|
422 | self.button_ok.Enable() |
---|
423 | |
---|
424 | def reset_panel(self): |
---|
425 | """ |
---|
426 | set the panel at its initial state. |
---|
427 | """ |
---|
428 | |
---|
429 | def _reset_output(self): |
---|
430 | """ |
---|
431 | clear outputs textcrtl |
---|
432 | """ |
---|
433 | self.invariant_total_tcl.Clear() |
---|
434 | self.invariant_total_err_tcl.Clear() |
---|
435 | self.volume_tcl.Clear() |
---|
436 | self.volume_err_tcl.Clear() |
---|
437 | self.surface_tcl.Clear() |
---|
438 | self.surface_err_tcl.Clear() |
---|
439 | #prepare a new container to put result of invariant |
---|
440 | self.inv_container = InvariantContainer() |
---|
441 | |
---|
442 | def _define_structure(self): |
---|
443 | """ |
---|
444 | Define main sizers needed for this panel |
---|
445 | """ |
---|
446 | ## Box sizers must be defined first before defining buttons/textctrls (MAC). |
---|
447 | self.main_sizer = wx.BoxSizer(wx.VERTICAL) |
---|
448 | #Sizer related to outputs |
---|
449 | outputs_box = wx.StaticBox(self, -1, "Outputs") |
---|
450 | self.outputs_sizer = wx.StaticBoxSizer(outputs_box, wx.VERTICAL) |
---|
451 | self.outputs_sizer.SetMinSize((PANEL_WIDTH,-1)) |
---|
452 | #Sizer related to data |
---|
453 | data_name_box = wx.StaticBox(self, -1, "I(q) Data Source") |
---|
454 | self.data_name_boxsizer = wx.StaticBoxSizer(data_name_box, wx.VERTICAL) |
---|
455 | self.data_name_boxsizer.SetMinSize((PANEL_WIDTH,-1)) |
---|
456 | self.hint_msg_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
457 | self.data_name_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
458 | self.data_range_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
459 | #Sizer related to background |
---|
460 | self.background_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
461 | #Sizer related to scale |
---|
462 | self.scale_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
463 | #Sizer related to contrast |
---|
464 | self.contrast_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
465 | #Sizer related to Porod Constant |
---|
466 | self.porod_constant_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
467 | extrapolation_box = wx.StaticBox(self, -1, "Extrapolation") |
---|
468 | self.extrapolation_sizer = wx.StaticBoxSizer(extrapolation_box, |
---|
469 | wx.VERTICAL) |
---|
470 | self.extrapolation_sizer.SetMinSize((PANEL_WIDTH,-1)) |
---|
471 | self.extrapolation_hint_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
472 | self.extrapolation_range_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
473 | self.extrapolation_low_high_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
474 | #Sizer related to extrapolation at low q range |
---|
475 | low_q_box = wx.StaticBox(self, -1, "Low Q") |
---|
476 | self.low_extrapolation_sizer = wx.StaticBoxSizer(low_q_box, wx.VERTICAL) |
---|
477 | self.low_q_sizer = wx.GridBagSizer(5,5) |
---|
478 | #Sizer related to extrapolation at low q range |
---|
479 | high_q_box = wx.StaticBox(self, -1, "High Q") |
---|
480 | self.high_extrapolation_sizer = wx.StaticBoxSizer(high_q_box, wx.VERTICAL) |
---|
481 | self.high_q_sizer = wx.GridBagSizer(5,5) |
---|
482 | #sizer to define outputs |
---|
483 | self.volume_surface_sizer = wx.GridBagSizer(5,5) |
---|
484 | #Sizer related to invariant output |
---|
485 | self.invariant_sizer = wx.GridBagSizer(5, 5) |
---|
486 | #Sizer related to button |
---|
487 | self.button_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
488 | |
---|
489 | def _layout_data_name(self): |
---|
490 | """ |
---|
491 | Draw widgets related to data's name |
---|
492 | """ |
---|
493 | #Sizer hint |
---|
494 | hint_msg = "Load Data then right click to add the data on this panel! " |
---|
495 | self.hint_msg_txt = wx.StaticText(self, -1, hint_msg) |
---|
496 | self.hint_msg_txt.SetForegroundColour("red") |
---|
497 | self.hint_msg_sizer.Add(self.hint_msg_txt) |
---|
498 | #Data name [string] |
---|
499 | data_name_txt = wx.StaticText(self, -1, 'Data : ') |
---|
500 | |
---|
501 | self.data_name_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH*5, 20), style=0) |
---|
502 | self.data_name_tcl.SetToolTipString("Data's name.") |
---|
503 | self.data_name_sizer.AddMany([(data_name_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
504 | (self.data_name_tcl, 0, wx.EXPAND)]) |
---|
505 | #Data range [string] |
---|
506 | data_range_txt = wx.StaticText(self, -1, 'Total Q Range (1/A): ') |
---|
507 | data_min_txt = wx.StaticText(self, -1, 'Min : ') |
---|
508 | self.data_min_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) |
---|
509 | self.data_min_tcl.SetToolTipString("The minimum value of q range.") |
---|
510 | data_max_txt = wx.StaticText(self, -1, 'Max : ') |
---|
511 | self.data_max_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) |
---|
512 | self.data_max_tcl.SetToolTipString("The maximum value of q range.") |
---|
513 | self.data_range_sizer.AddMany([(data_range_txt, 0, wx.RIGHT, 10), |
---|
514 | (data_min_txt, 0, wx.RIGHT, 10), |
---|
515 | (self.data_min_tcl, 0, wx.RIGHT, 10), |
---|
516 | (data_max_txt, 0, wx.RIGHT, 10), |
---|
517 | (self.data_max_tcl, 0, wx.RIGHT, 10)]) |
---|
518 | self.data_name_boxsizer.AddMany([(self.hint_msg_sizer, 0 , wx.ALL, 10), |
---|
519 | (self.data_name_sizer, 0 , wx.RIGHT, 10), |
---|
520 | (self.data_range_sizer, 0 , wx.ALL, 10)]) |
---|
521 | |
---|
522 | def _layout_background(self): |
---|
523 | """ |
---|
524 | Draw widgets related to background |
---|
525 | """ |
---|
526 | background_txt = wx.StaticText(self, -1, 'Background : ') |
---|
527 | self.background_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) |
---|
528 | self.background_tcl.SetValue(str(BACKGROUND)) |
---|
529 | background_hint_txt = "background" |
---|
530 | self.background_tcl.SetToolTipString(background_hint_txt) |
---|
531 | background_unit_txt = wx.StaticText(self, -1, '[1/cm]') |
---|
532 | self.background_sizer.AddMany([(background_txt, 0, wx.LEFT, 10), |
---|
533 | (self.background_tcl, 0, wx.LEFT, 15), |
---|
534 | (background_unit_txt, 0, wx.LEFT, 10)]) |
---|
535 | def _layout_scale(self): |
---|
536 | """ |
---|
537 | Draw widgets related to scale |
---|
538 | """ |
---|
539 | scale_txt = wx.StaticText(self, -1, 'Scale : ') |
---|
540 | self.scale_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) |
---|
541 | scale_hint_txt = "Scale" |
---|
542 | self.scale_tcl.SetToolTipString(scale_hint_txt) |
---|
543 | self.scale_tcl.SetValue(str(SCALE)) |
---|
544 | self.scale_sizer.AddMany([(scale_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
545 | (self.scale_tcl, 0, wx.LEFT, 35)]) |
---|
546 | |
---|
547 | def _layout_contrast(self): |
---|
548 | """ |
---|
549 | Draw widgets related to contrast |
---|
550 | """ |
---|
551 | contrast_txt = wx.StaticText(self, -1, 'Contrast : ') |
---|
552 | self.contrast_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) |
---|
553 | self.contrast_tcl.SetValue(str(CONTRAST)) |
---|
554 | contrast_hint_txt = "Contrast" |
---|
555 | self.contrast_tcl.SetToolTipString(contrast_hint_txt) |
---|
556 | contrast_unit_txt = wx.StaticText(self, -1, '[1/A^(2)]') |
---|
557 | self.contrast_sizer.AddMany([(contrast_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
558 | (self.contrast_tcl, 0, wx.LEFT, 18), |
---|
559 | (contrast_unit_txt, 0, wx.LEFT, 10)]) |
---|
560 | |
---|
561 | def _layout_porod_constant(self): |
---|
562 | """ |
---|
563 | Draw widgets related to porod constant |
---|
564 | """ |
---|
565 | porod_const_txt = wx.StaticText(self, -1, 'Porod Constant:') |
---|
566 | self.porod_constant_tcl = InvTextCtrl(self, -1, |
---|
567 | size=(_BOX_WIDTH, 20), style=0) |
---|
568 | porod_const_hint_txt = "Porod Constant" |
---|
569 | self.porod_constant_tcl.SetToolTipString(porod_const_hint_txt) |
---|
570 | optional_txt = wx.StaticText(self, -1, '(Optional)') |
---|
571 | self.porod_constant_sizer.AddMany([(porod_const_txt, 0, wx.LEFT, 10), |
---|
572 | (self.porod_constant_tcl, 0, wx.LEFT, 0), |
---|
573 | (optional_txt, 0, wx.LEFT, 10)]) |
---|
574 | |
---|
575 | def _enable_fit_power_law_low(self, event=None): |
---|
576 | """ |
---|
577 | Enable and disable the power value editing |
---|
578 | """ |
---|
579 | if self.fix_enable_low.IsEnabled(): |
---|
580 | if self.fix_enable_low.GetValue(): |
---|
581 | self.power_low_tcl.Enable() |
---|
582 | else: |
---|
583 | self.power_low_tcl.Disable() |
---|
584 | |
---|
585 | def _enable_low_q_section(self, event=None): |
---|
586 | """ |
---|
587 | Disable or enable some button if the user enable low q extrapolation |
---|
588 | """ |
---|
589 | if self.enable_low_cbox.GetValue(): |
---|
590 | self.npts_low_tcl.Enable() |
---|
591 | self.fix_enable_low.Enable() |
---|
592 | self.fit_enable_low.Enable() |
---|
593 | self.guinier.Enable() |
---|
594 | self.power_law_low.Enable() |
---|
595 | |
---|
596 | else: |
---|
597 | self.npts_low_tcl.Disable() |
---|
598 | self.fix_enable_low.Disable() |
---|
599 | self.fit_enable_low.Disable() |
---|
600 | self.guinier.Disable() |
---|
601 | self.power_law_low.Disable() |
---|
602 | self._enable_power_law_low() |
---|
603 | self._enable_fit_power_law_low() |
---|
604 | |
---|
605 | def _enable_power_law_low(self, event=None): |
---|
606 | """ |
---|
607 | Enable editing power law section at low q range |
---|
608 | """ |
---|
609 | if self.guinier.GetValue(): |
---|
610 | self.fix_enable_low.Disable() |
---|
611 | self.fit_enable_low.Disable() |
---|
612 | self.power_low_tcl.Disable() |
---|
613 | else: |
---|
614 | self.fix_enable_low.Enable() |
---|
615 | self.fit_enable_low.Enable() |
---|
616 | self.power_low_tcl.Enable() |
---|
617 | self._enable_fit_power_law_low() |
---|
618 | |
---|
619 | def _layout_extrapolation_low(self): |
---|
620 | """ |
---|
621 | Draw widgets related to extrapolation at low q range |
---|
622 | """ |
---|
623 | self.enable_low_cbox = wx.CheckBox(self, -1, "Enable Extrapolate Low Q") |
---|
624 | self.enable_low_cbox.SetValue(False) |
---|
625 | wx.EVT_CHECKBOX(self, self.enable_low_cbox.GetId(), |
---|
626 | self._enable_low_q_section) |
---|
627 | self.fix_enable_low = wx.RadioButton(self, -1, 'Fix', |
---|
628 | (10, 10),style=wx.RB_GROUP) |
---|
629 | self.fix_enable_low.SetValue(True) |
---|
630 | self.fit_enable_low = wx.RadioButton(self, -1, 'Fit', (10, 10)) |
---|
631 | self.Bind(wx.EVT_RADIOBUTTON, self._enable_fit_power_law_low, |
---|
632 | id=self.fix_enable_low.GetId()) |
---|
633 | self.Bind(wx.EVT_RADIOBUTTON, self._enable_fit_power_law_low, |
---|
634 | id=self.fit_enable_low.GetId()) |
---|
635 | self.guinier = wx.RadioButton(self, -1, 'Guinier', |
---|
636 | (10, 10),style=wx.RB_GROUP) |
---|
637 | self.guinier.SetValue(True) |
---|
638 | self.power_law_low = wx.RadioButton(self, -1, 'Power Law', (10, 10)) |
---|
639 | self.Bind(wx.EVT_RADIOBUTTON, self._enable_power_law_low, |
---|
640 | id=self.guinier.GetId()) |
---|
641 | self.Bind(wx.EVT_RADIOBUTTON, self._enable_power_law_low, |
---|
642 | id=self.power_law_low.GetId()) |
---|
643 | |
---|
644 | npts_low_txt = wx.StaticText(self, -1, 'Npts') |
---|
645 | self.npts_low_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1)) |
---|
646 | self.npts_low_tcl.SetValue(str(NPTS)) |
---|
647 | msg_hint = "Number of Q points to consider" |
---|
648 | msg_hint +="while extrapolating the low-Q region" |
---|
649 | self.npts_low_tcl.SetToolTipString(msg_hint) |
---|
650 | power_txt = wx.StaticText(self, -1, 'Power') |
---|
651 | self.power_low_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1)) |
---|
652 | self.power_low_tcl.SetValue(str(self.power_law_exponant)) |
---|
653 | self.power_low_tcl.Disable() |
---|
654 | power_hint_txt = "Exponent to apply to the Power_law function." |
---|
655 | self.power_low_tcl.SetToolTipString(power_hint_txt) |
---|
656 | iy = 0 |
---|
657 | ix = 0 |
---|
658 | self.low_q_sizer.Add(self.enable_low_cbox,(iy, ix),(1,5), |
---|
659 | wx.TOP|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
660 | iy += 1 |
---|
661 | ix = 0 |
---|
662 | self.low_q_sizer.Add(npts_low_txt,(iy, ix),(1,1), |
---|
663 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
664 | ix += 1 |
---|
665 | self.low_q_sizer.Add(self.npts_low_tcl, (iy, ix), (1,1), |
---|
666 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
667 | iy += 1 |
---|
668 | ix = 0 |
---|
669 | self.low_q_sizer.Add(self.guinier,(iy, ix),(1,2), |
---|
670 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
671 | iy += 1 |
---|
672 | ix = 0 |
---|
673 | self.low_q_sizer.Add(self.power_law_low,(iy, ix),(1,2), |
---|
674 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
675 | |
---|
676 | # Parameter controls for power law |
---|
677 | ix = 1 |
---|
678 | iy += 1 |
---|
679 | self.low_q_sizer.Add(self.fix_enable_low,(iy, ix),(1,1), |
---|
680 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
681 | ix += 1 |
---|
682 | self.low_q_sizer.Add(self.fit_enable_low,(iy, ix),(1,1), |
---|
683 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
684 | ix = 1 |
---|
685 | iy += 1 |
---|
686 | self.low_q_sizer.Add(power_txt,(iy, ix),(1,1), |
---|
687 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
688 | ix += 1 |
---|
689 | self.low_q_sizer.Add(self.power_low_tcl, (iy, ix), (1,1), |
---|
690 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
691 | #Change the state of txtcrtl to enable/disable |
---|
692 | self._enable_low_q_section() |
---|
693 | self.low_extrapolation_sizer.AddMany([(self.low_q_sizer, 0, |
---|
694 | wx.BOTTOM|wx.RIGHT, 10)]) |
---|
695 | def _enable_fit_power_law_high(self, event=None): |
---|
696 | """ |
---|
697 | Enable and disable the power value editing |
---|
698 | """ |
---|
699 | if self.fix_enable_high.IsEnabled(): |
---|
700 | if self.fix_enable_high.GetValue(): |
---|
701 | self.power_high_tcl.Enable() |
---|
702 | else: |
---|
703 | self.power_high_tcl.Disable() |
---|
704 | |
---|
705 | def _enable_high_q_section(self, event=None): |
---|
706 | """ |
---|
707 | Disable or enable some button if the user enable high q extrapolation |
---|
708 | """ |
---|
709 | if self.enable_high_cbox.GetValue(): |
---|
710 | self.npts_high_tcl.Enable() |
---|
711 | self.power_law_high.Enable() |
---|
712 | self.power_high_tcl.Enable() |
---|
713 | self.fix_enable_high.Enable() |
---|
714 | self.fit_enable_high.Enable() |
---|
715 | else: |
---|
716 | self.npts_high_tcl.Disable() |
---|
717 | self.power_law_high.Disable() |
---|
718 | self.power_high_tcl.Disable() |
---|
719 | self.fix_enable_high.Disable() |
---|
720 | self.fit_enable_high.Disable() |
---|
721 | self._enable_fit_power_law_high() |
---|
722 | |
---|
723 | def _layout_extrapolation_high(self): |
---|
724 | """ |
---|
725 | Draw widgets related to extrapolation at high q range |
---|
726 | """ |
---|
727 | self.enable_high_cbox = wx.CheckBox(self, -1, "Enable Extrapolate high-Q") |
---|
728 | self.enable_high_cbox.SetValue(False) |
---|
729 | wx.EVT_CHECKBOX(self, self.enable_high_cbox.GetId(), |
---|
730 | self._enable_high_q_section) |
---|
731 | |
---|
732 | self.fix_enable_high = wx.RadioButton(self, -1, 'Fix', |
---|
733 | (10, 10),style=wx.RB_GROUP) |
---|
734 | self.fix_enable_high.SetValue(True) |
---|
735 | self.fit_enable_high = wx.RadioButton(self, -1, 'Fit', (10, 10)) |
---|
736 | self.Bind(wx.EVT_RADIOBUTTON, self._enable_fit_power_law_high, |
---|
737 | id=self.fix_enable_high.GetId()) |
---|
738 | self.Bind(wx.EVT_RADIOBUTTON, self._enable_fit_power_law_high, |
---|
739 | id=self.fit_enable_high.GetId()) |
---|
740 | |
---|
741 | self.power_law_high = wx.StaticText(self, -1, 'Power Law') |
---|
742 | #msg_hint ="Check to extrapolate data at high-Q" |
---|
743 | #self.power_law_high.SetToolTipString(msg_hint) |
---|
744 | npts_high_txt = wx.StaticText(self, -1, 'Npts') |
---|
745 | self.npts_high_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1)) |
---|
746 | msg_hint = "Number of Q points to consider" |
---|
747 | msg_hint += "while extrapolating the high-Q region" |
---|
748 | self.npts_high_tcl.SetToolTipString(msg_hint) |
---|
749 | self.npts_high_tcl.SetValue(str(NPTS)) |
---|
750 | power_txt = wx.StaticText(self, -1, 'Power') |
---|
751 | self.power_high_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1)) |
---|
752 | self.power_high_tcl.SetValue(str(self.power_law_exponant)) |
---|
753 | power_hint_txt = "Exponent to apply to the Power_law function." |
---|
754 | self.power_high_tcl.SetToolTipString(power_hint_txt) |
---|
755 | iy = 0 |
---|
756 | ix = 0 |
---|
757 | self.high_q_sizer.Add(self.enable_high_cbox,(iy, ix),(1,5), |
---|
758 | wx.TOP|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
759 | iy += 1 |
---|
760 | ix = 0 |
---|
761 | self.high_q_sizer.Add(npts_high_txt,(iy, ix),(1,1), |
---|
762 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
763 | ix += 1 |
---|
764 | self.high_q_sizer.Add(self.npts_high_tcl, (iy, ix), (1,1), |
---|
765 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
766 | iy += 2 |
---|
767 | ix = 0 |
---|
768 | self.high_q_sizer.Add(self.power_law_high,(iy, ix),(1,2), |
---|
769 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
770 | |
---|
771 | # Parameter controls for power law |
---|
772 | ix = 1 |
---|
773 | iy += 1 |
---|
774 | self.high_q_sizer.Add(self.fix_enable_high,(iy, ix),(1,1), |
---|
775 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
776 | ix += 1 |
---|
777 | self.high_q_sizer.Add(self.fit_enable_high,(iy, ix),(1,1), |
---|
778 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
779 | ix = 1 |
---|
780 | iy += 1 |
---|
781 | self.high_q_sizer.Add(power_txt,(iy, ix),(1,1), |
---|
782 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
783 | ix += 1 |
---|
784 | self.high_q_sizer.Add(self.power_high_tcl, (iy, ix), (1,1), |
---|
785 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
786 | #Change the state of txtcrtl to enable/disable |
---|
787 | self._enable_high_q_section() |
---|
788 | self.high_extrapolation_sizer.AddMany([(self.high_q_sizer, 0, wx.RIGHT, 10)]) |
---|
789 | |
---|
790 | def _layout_extrapolation(self): |
---|
791 | """ |
---|
792 | Draw widgets related to extrapolation |
---|
793 | """ |
---|
794 | extra_hint = "Extrapolation Maximum Q Range [1/A]: " |
---|
795 | extra_hint_txt = wx.StaticText(self, -1, extra_hint) |
---|
796 | #Extrapolation range [string] |
---|
797 | extrapolation_min_txt = wx.StaticText(self, -1, 'Min : ') |
---|
798 | self.extrapolation_min_tcl = OutputTextCtrl(self, -1, |
---|
799 | size=(_BOX_WIDTH, 20), style=0) |
---|
800 | self.extrapolation_min_tcl.SetValue(str(Q_MINIMUM)) |
---|
801 | self.extrapolation_min_tcl.SetToolTipString("The minimum extrapolated q value.") |
---|
802 | extrapolation_max_txt = wx.StaticText(self, -1, 'Max : ') |
---|
803 | self.extrapolation_max_tcl = OutputTextCtrl(self, -1, |
---|
804 | size=(_BOX_WIDTH, 20), style=0) |
---|
805 | self.extrapolation_max_tcl.SetValue(str(Q_MAXIMUM)) |
---|
806 | self.extrapolation_max_tcl.SetToolTipString("The maximum extrapolated q value.") |
---|
807 | self.extrapolation_range_sizer.AddMany([(extra_hint_txt, 0, wx.LEFT, 10), |
---|
808 | (extrapolation_min_txt, 0, wx.LEFT, 10), |
---|
809 | (self.extrapolation_min_tcl, |
---|
810 | 0, wx.LEFT, 10), |
---|
811 | (extrapolation_max_txt, 0, wx.LEFT, 10), |
---|
812 | (self.extrapolation_max_tcl, |
---|
813 | 0, wx.LEFT, 10), |
---|
814 | ]) |
---|
815 | extra_enable_hint = "Hint: Check any box to enable a specific extrapolation !" |
---|
816 | extra_enable_hint_txt = wx.StaticText(self, -1, extra_enable_hint ) |
---|
817 | self.extrapolation_hint_sizer.AddMany([(extra_enable_hint_txt, 0, wx.LEFT, 0) |
---|
818 | ]) |
---|
819 | self._layout_extrapolation_low() |
---|
820 | self._layout_extrapolation_high() |
---|
821 | self.extrapolation_low_high_sizer.AddMany([(self.low_extrapolation_sizer, |
---|
822 | 0, wx.ALL, 10), |
---|
823 | (self.high_extrapolation_sizer, |
---|
824 | 0, wx.ALL, 10)]) |
---|
825 | self.extrapolation_sizer.AddMany([(self.extrapolation_range_sizer, 0, |
---|
826 | wx.RIGHT, 10), |
---|
827 | (self.extrapolation_hint_sizer, 0, |
---|
828 | wx.ALL, 10), |
---|
829 | (self.extrapolation_low_high_sizer, 0, |
---|
830 | wx.ALL, 10)]) |
---|
831 | |
---|
832 | def _layout_volume_surface_sizer(self): |
---|
833 | """ |
---|
834 | Draw widgets related to volume and surface |
---|
835 | """ |
---|
836 | unit_volume = '' |
---|
837 | unit_surface = '' |
---|
838 | uncertainty = "+/-" |
---|
839 | volume_txt = wx.StaticText(self, -1, 'Volume Fraction') |
---|
840 | self.volume_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
841 | self.volume_tcl.SetToolTipString("Volume fraction.") |
---|
842 | self.volume_err_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
843 | self.volume_err_tcl.SetToolTipString("Uncertainty on the volume fraction.") |
---|
844 | volume_units_txt = wx.StaticText(self, -1, unit_volume) |
---|
845 | |
---|
846 | surface_txt = wx.StaticText(self, -1, 'Specific Surface') |
---|
847 | self.surface_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
848 | self.surface_tcl.SetToolTipString("Specific surface value.") |
---|
849 | self.surface_err_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
850 | self.surface_err_tcl.SetToolTipString("Uncertainty on the specific surface.") |
---|
851 | surface_units_txt = wx.StaticText(self, -1, unit_surface) |
---|
852 | iy = 0 |
---|
853 | ix = 0 |
---|
854 | self.volume_surface_sizer.Add(volume_txt, (iy, ix), (1,1), |
---|
855 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
856 | ix += 1 |
---|
857 | self.volume_surface_sizer.Add(self.volume_tcl, (iy, ix), (1,1), |
---|
858 | wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
859 | ix += 1 |
---|
860 | self.volume_surface_sizer.Add(wx.StaticText(self, -1, uncertainty), |
---|
861 | (iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
862 | ix += 1 |
---|
863 | self.volume_surface_sizer.Add(self.volume_err_tcl, (iy, ix), (1,1), |
---|
864 | wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
865 | ix += 1 |
---|
866 | self.volume_surface_sizer.Add(volume_units_txt, (iy, ix), (1,1), |
---|
867 | wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
868 | iy += 1 |
---|
869 | ix = 0 |
---|
870 | self.volume_surface_sizer.Add(surface_txt, (iy, ix), (1,1), |
---|
871 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
872 | ix += 1 |
---|
873 | self.volume_surface_sizer.Add(self.surface_tcl, (iy, ix), (1,1), |
---|
874 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
875 | ix += 1 |
---|
876 | self.volume_surface_sizer.Add(wx.StaticText(self, -1, uncertainty), |
---|
877 | (iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
878 | ix += 1 |
---|
879 | self.volume_surface_sizer.Add(self.surface_err_tcl, (iy, ix), (1,1), |
---|
880 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
881 | ix += 1 |
---|
882 | self.volume_surface_sizer.Add(surface_units_txt, (iy, ix), (1,1), |
---|
883 | wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
884 | |
---|
885 | def _layout_invariant_sizer(self): |
---|
886 | """ |
---|
887 | Draw widgets related to invariant |
---|
888 | """ |
---|
889 | uncertainty = "+/-" |
---|
890 | unit_invariant = '[1/(cm * A)]' |
---|
891 | invariant_total_txt = wx.StaticText(self, -1, 'Invariant Total') |
---|
892 | self.invariant_total_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
893 | msg_hint = "Total invariant, including extrapolated regions." |
---|
894 | self.invariant_total_tcl.SetToolTipString(msg_hint) |
---|
895 | self.invariant_total_err_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
896 | self.invariant_total_err_tcl.SetToolTipString("Uncertainty on invariant.") |
---|
897 | invariant_total_units_txt = wx.StaticText(self, -1, unit_invariant) |
---|
898 | |
---|
899 | #Invariant total |
---|
900 | iy = 0 |
---|
901 | ix = 0 |
---|
902 | self.invariant_sizer.Add(invariant_total_txt, (iy, ix), (1,1), |
---|
903 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
904 | ix += 1 |
---|
905 | self.invariant_sizer.Add(self.invariant_total_tcl, (iy, ix), (1,1), |
---|
906 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) |
---|
907 | ix += 1 |
---|
908 | self.invariant_sizer.Add( wx.StaticText(self, -1, uncertainty), |
---|
909 | (iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
910 | ix += 1 |
---|
911 | self.invariant_sizer.Add(self.invariant_total_err_tcl, (iy, ix), (1,1), |
---|
912 | wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
913 | ix += 1 |
---|
914 | self.invariant_sizer.Add(invariant_total_units_txt,(iy, ix), (1,1), |
---|
915 | wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
916 | |
---|
917 | def _layout_outputs_sizer(self): |
---|
918 | """ |
---|
919 | Draw widgets related to outputs |
---|
920 | """ |
---|
921 | self._layout_volume_surface_sizer() |
---|
922 | self._layout_invariant_sizer() |
---|
923 | static_line = wx.StaticLine(self, -1) |
---|
924 | self.outputs_sizer.AddMany([(self.volume_surface_sizer, 0, wx.ALL, 10), |
---|
925 | (static_line, 0, wx.EXPAND, 0), |
---|
926 | (self.invariant_sizer, 0, wx.ALL, 10)]) |
---|
927 | def _layout_button(self): |
---|
928 | """ |
---|
929 | Do the layout for the button widgets |
---|
930 | """ |
---|
931 | #compute button |
---|
932 | id = wx.NewId() |
---|
933 | button_calculate = wx.Button(self, id, "Compute") |
---|
934 | button_calculate.SetToolTipString("Compute invariant") |
---|
935 | self.Bind(wx.EVT_BUTTON, self.compute_invariant, id=id) |
---|
936 | #detail button |
---|
937 | id = wx.NewId() |
---|
938 | self.button_ok = wx.Button(self, id, "Details?") |
---|
939 | self.button_ok.SetToolTipString("Give Details on Computation") |
---|
940 | self.Bind(wx.EVT_BUTTON, self.display_details, id=id) |
---|
941 | self.button_ok.Disable() |
---|
942 | details = "Details on Invariant Total Calculations" |
---|
943 | details_txt = wx.StaticText(self, -1, details) |
---|
944 | self.button_sizer.AddMany([((20,20), 0 , wx.LEFT, 100), |
---|
945 | (details_txt, 0 , wx.ALL, 10), |
---|
946 | (self.button_ok, 0 , wx.ALL, 10), |
---|
947 | (button_calculate, 0 , wx.RIGHT|wx.TOP|wx.BOTTOM, 10)]) |
---|
948 | |
---|
949 | def _do_layout(self): |
---|
950 | """ |
---|
951 | Draw window content |
---|
952 | """ |
---|
953 | self._define_structure() |
---|
954 | self._layout_data_name() |
---|
955 | self._layout_background() |
---|
956 | self._layout_scale() |
---|
957 | self._layout_contrast() |
---|
958 | self._layout_porod_constant() |
---|
959 | self._layout_extrapolation() |
---|
960 | self._layout_outputs_sizer() |
---|
961 | self._layout_button() |
---|
962 | self.main_sizer.AddMany([(self.data_name_boxsizer, 0, wx.ALL, 10), |
---|
963 | (self.background_sizer, 0, |
---|
964 | wx.LEFT|wx.RIGHT|wx.BOTTOM, 10), |
---|
965 | (self.scale_sizer, 0, |
---|
966 | wx.LEFT|wx.RIGHT|wx.BOTTOM, 10), |
---|
967 | (self.contrast_sizer, 0, |
---|
968 | wx.LEFT|wx.RIGHT|wx.BOTTOM, 10), |
---|
969 | (self.porod_constant_sizer, 0, |
---|
970 | wx.LEFT|wx.RIGHT|wx.BOTTOM, 10), |
---|
971 | (self.extrapolation_sizer, 0, |
---|
972 | wx.LEFT|wx.RIGHT|wx.BOTTOM, 10), |
---|
973 | (self.outputs_sizer, 0, |
---|
974 | wx.LEFT|wx.RIGHT|wx.BOTTOM, 10), |
---|
975 | (self.button_sizer, 0, |
---|
976 | wx.LEFT|wx.RIGHT|wx.BOTTOM, 10)]) |
---|
977 | self.SetSizer(self.main_sizer) |
---|
978 | self.SetScrollbars(20,20,25,65) |
---|
979 | self.SetAutoLayout(True) |
---|
980 | |
---|
981 | class InvariantDialog(wx.Dialog): |
---|
982 | def __init__(self, parent=None, id=1,graph=None, |
---|
983 | data=None, title="Invariant",base=None): |
---|
984 | wx.Dialog.__init__(self, parent, id, title, size=(PANEL_WIDTH, |
---|
985 | PANEL_HEIGHT)) |
---|
986 | self.panel = InvariantPanel(self) |
---|
987 | self.Centre() |
---|
988 | self.Show(True) |
---|
989 | |
---|
990 | class InvariantWindow(wx.Frame): |
---|
991 | def __init__(self, parent=None, id=1,graph=None, |
---|
992 | data=None, title="Invariant",base=None): |
---|
993 | |
---|
994 | wx.Frame.__init__(self, parent, id, title, size=(PANEL_WIDTH +100, |
---|
995 | PANEL_HEIGHT+100)) |
---|
996 | |
---|
997 | self.panel = InvariantPanel(self) |
---|
998 | self.Centre() |
---|
999 | self.Show(True) |
---|
1000 | |
---|
1001 | class MyApp(wx.App): |
---|
1002 | def OnInit(self): |
---|
1003 | wx.InitAllImageHandlers() |
---|
1004 | frame = InvariantWindow() |
---|
1005 | frame.Show(True) |
---|
1006 | self.SetTopWindow(frame) |
---|
1007 | |
---|
1008 | return True |
---|
1009 | |
---|
1010 | # end of class MyApp |
---|
1011 | |
---|
1012 | if __name__ == "__main__": |
---|
1013 | app = MyApp(0) |
---|
1014 | app.MainLoop() |
---|