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_output(self): |
---|
425 | """ |
---|
426 | clear outputs textcrtl |
---|
427 | """ |
---|
428 | self.invariant_total_tcl.Clear() |
---|
429 | self.invariant_total_err_tcl.Clear() |
---|
430 | self.volume_tcl.Clear() |
---|
431 | self.volume_err_tcl.Clear() |
---|
432 | self.surface_tcl.Clear() |
---|
433 | self.surface_err_tcl.Clear() |
---|
434 | #prepare a new container to put result of invariant |
---|
435 | self.inv_container = InvariantContainer() |
---|
436 | |
---|
437 | def _define_structure(self): |
---|
438 | """ |
---|
439 | Define main sizers needed for this panel |
---|
440 | """ |
---|
441 | ## Box sizers must be defined first before defining buttons/textctrls (MAC). |
---|
442 | self.main_sizer = wx.BoxSizer(wx.VERTICAL) |
---|
443 | #Sizer related to outputs |
---|
444 | outputs_box = wx.StaticBox(self, -1, "Outputs") |
---|
445 | self.outputs_sizer = wx.StaticBoxSizer(outputs_box, wx.VERTICAL) |
---|
446 | self.outputs_sizer.SetMinSize((PANEL_WIDTH,-1)) |
---|
447 | #Sizer related to data |
---|
448 | data_name_box = wx.StaticBox(self, -1, "I(q) Data Source") |
---|
449 | self.data_name_boxsizer = wx.StaticBoxSizer(data_name_box, wx.VERTICAL) |
---|
450 | self.data_name_boxsizer.SetMinSize((PANEL_WIDTH,-1)) |
---|
451 | self.hint_msg_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
452 | self.data_name_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
453 | self.data_range_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
454 | #Sizer related to background |
---|
455 | self.background_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
456 | #Sizer related to scale |
---|
457 | self.scale_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
458 | #Sizer related to contrast |
---|
459 | self.contrast_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
460 | #Sizer related to Porod Constant |
---|
461 | self.porod_constant_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
462 | extrapolation_box = wx.StaticBox(self, -1, "Extrapolation") |
---|
463 | self.extrapolation_sizer = wx.StaticBoxSizer(extrapolation_box, |
---|
464 | wx.VERTICAL) |
---|
465 | self.extrapolation_sizer.SetMinSize((PANEL_WIDTH,-1)) |
---|
466 | self.extrapolation_hint_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
467 | self.extrapolation_range_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
468 | self.extrapolation_low_high_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
469 | #Sizer related to extrapolation at low q range |
---|
470 | low_q_box = wx.StaticBox(self, -1, "Low Q") |
---|
471 | self.low_extrapolation_sizer = wx.StaticBoxSizer(low_q_box, wx.VERTICAL) |
---|
472 | self.low_q_sizer = wx.GridBagSizer(5,5) |
---|
473 | #Sizer related to extrapolation at low q range |
---|
474 | high_q_box = wx.StaticBox(self, -1, "High Q") |
---|
475 | self.high_extrapolation_sizer = wx.StaticBoxSizer(high_q_box, wx.VERTICAL) |
---|
476 | self.high_q_sizer = wx.GridBagSizer(5,5) |
---|
477 | #sizer to define outputs |
---|
478 | self.volume_surface_sizer = wx.GridBagSizer(5,5) |
---|
479 | #Sizer related to invariant output |
---|
480 | self.invariant_sizer = wx.GridBagSizer(5, 5) |
---|
481 | #Sizer related to button |
---|
482 | self.button_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
483 | |
---|
484 | def _layout_data_name(self): |
---|
485 | """ |
---|
486 | Draw widgets related to data's name |
---|
487 | """ |
---|
488 | #Sizer hint |
---|
489 | hint_msg = "Load Data then right click to add the data on this panel! " |
---|
490 | self.hint_msg_txt = wx.StaticText(self, -1, hint_msg) |
---|
491 | self.hint_msg_txt.SetForegroundColour("red") |
---|
492 | self.hint_msg_sizer.Add(self.hint_msg_txt) |
---|
493 | #Data name [string] |
---|
494 | data_name_txt = wx.StaticText(self, -1, 'Data : ') |
---|
495 | |
---|
496 | self.data_name_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH*5, 20), style=0) |
---|
497 | self.data_name_tcl.SetToolTipString("Data's name.") |
---|
498 | self.data_name_sizer.AddMany([(data_name_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
499 | (self.data_name_tcl, 0, wx.EXPAND)]) |
---|
500 | #Data range [string] |
---|
501 | data_range_txt = wx.StaticText(self, -1, 'Total Q Range (1/A): ') |
---|
502 | data_min_txt = wx.StaticText(self, -1, 'Min : ') |
---|
503 | self.data_min_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) |
---|
504 | self.data_min_tcl.SetToolTipString("The minimum value of q range.") |
---|
505 | data_max_txt = wx.StaticText(self, -1, 'Max : ') |
---|
506 | self.data_max_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) |
---|
507 | self.data_max_tcl.SetToolTipString("The maximum value of q range.") |
---|
508 | self.data_range_sizer.AddMany([(data_range_txt, 0, wx.RIGHT, 10), |
---|
509 | (data_min_txt, 0, wx.RIGHT, 10), |
---|
510 | (self.data_min_tcl, 0, wx.RIGHT, 10), |
---|
511 | (data_max_txt, 0, wx.RIGHT, 10), |
---|
512 | (self.data_max_tcl, 0, wx.RIGHT, 10)]) |
---|
513 | self.data_name_boxsizer.AddMany([(self.hint_msg_sizer, 0 , wx.ALL, 10), |
---|
514 | (self.data_name_sizer, 0 , wx.RIGHT, 10), |
---|
515 | (self.data_range_sizer, 0 , wx.ALL, 10)]) |
---|
516 | |
---|
517 | def _layout_background(self): |
---|
518 | """ |
---|
519 | Draw widgets related to background |
---|
520 | """ |
---|
521 | background_txt = wx.StaticText(self, -1, 'Background : ') |
---|
522 | self.background_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) |
---|
523 | self.background_tcl.SetValue(str(BACKGROUND)) |
---|
524 | background_hint_txt = "background" |
---|
525 | self.background_tcl.SetToolTipString(background_hint_txt) |
---|
526 | background_unit_txt = wx.StaticText(self, -1, '[1/cm]') |
---|
527 | self.background_sizer.AddMany([(background_txt, 0, wx.LEFT, 10), |
---|
528 | (self.background_tcl, 0, wx.LEFT, 15), |
---|
529 | (background_unit_txt, 0, wx.LEFT, 10)]) |
---|
530 | def _layout_scale(self): |
---|
531 | """ |
---|
532 | Draw widgets related to scale |
---|
533 | """ |
---|
534 | scale_txt = wx.StaticText(self, -1, 'Scale : ') |
---|
535 | self.scale_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) |
---|
536 | scale_hint_txt = "Scale" |
---|
537 | self.scale_tcl.SetToolTipString(scale_hint_txt) |
---|
538 | self.scale_tcl.SetValue(str(SCALE)) |
---|
539 | self.scale_sizer.AddMany([(scale_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
540 | (self.scale_tcl, 0, wx.LEFT, 35)]) |
---|
541 | |
---|
542 | def _layout_contrast(self): |
---|
543 | """ |
---|
544 | Draw widgets related to contrast |
---|
545 | """ |
---|
546 | contrast_txt = wx.StaticText(self, -1, 'Contrast : ') |
---|
547 | self.contrast_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) |
---|
548 | self.contrast_tcl.SetValue(str(CONTRAST)) |
---|
549 | contrast_hint_txt = "Contrast" |
---|
550 | self.contrast_tcl.SetToolTipString(contrast_hint_txt) |
---|
551 | contrast_unit_txt = wx.StaticText(self, -1, '[1/A^(2)]') |
---|
552 | self.contrast_sizer.AddMany([(contrast_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
553 | (self.contrast_tcl, 0, wx.LEFT, 18), |
---|
554 | (contrast_unit_txt, 0, wx.LEFT, 10)]) |
---|
555 | |
---|
556 | def _layout_porod_constant(self): |
---|
557 | """ |
---|
558 | Draw widgets related to porod constant |
---|
559 | """ |
---|
560 | porod_const_txt = wx.StaticText(self, -1, 'Porod Constant:') |
---|
561 | self.porod_constant_tcl = InvTextCtrl(self, -1, |
---|
562 | size=(_BOX_WIDTH, 20), style=0) |
---|
563 | porod_const_hint_txt = "Porod Constant" |
---|
564 | self.porod_constant_tcl.SetToolTipString(porod_const_hint_txt) |
---|
565 | optional_txt = wx.StaticText(self, -1, '(Optional)') |
---|
566 | self.porod_constant_sizer.AddMany([(porod_const_txt, 0, wx.LEFT, 10), |
---|
567 | (self.porod_constant_tcl, 0, wx.LEFT, 0), |
---|
568 | (optional_txt, 0, wx.LEFT, 10)]) |
---|
569 | |
---|
570 | def _enable_fit_power_law_low(self, event=None): |
---|
571 | """ |
---|
572 | Enable and disable the power value editing |
---|
573 | """ |
---|
574 | if self.fix_enable_low.IsEnabled(): |
---|
575 | if self.fix_enable_low.GetValue(): |
---|
576 | self.power_low_tcl.Enable() |
---|
577 | else: |
---|
578 | self.power_low_tcl.Disable() |
---|
579 | |
---|
580 | def _enable_low_q_section(self, event=None): |
---|
581 | """ |
---|
582 | Disable or enable some button if the user enable low q extrapolation |
---|
583 | """ |
---|
584 | if self.enable_low_cbox.GetValue(): |
---|
585 | self.npts_low_tcl.Enable() |
---|
586 | self.fix_enable_low.Enable() |
---|
587 | self.fit_enable_low.Enable() |
---|
588 | self.guinier.Enable() |
---|
589 | self.power_law_low.Enable() |
---|
590 | |
---|
591 | else: |
---|
592 | self.npts_low_tcl.Disable() |
---|
593 | self.fix_enable_low.Disable() |
---|
594 | self.fit_enable_low.Disable() |
---|
595 | self.guinier.Disable() |
---|
596 | self.power_law_low.Disable() |
---|
597 | self._enable_power_law_low() |
---|
598 | self._enable_fit_power_law_low() |
---|
599 | |
---|
600 | def _enable_power_law_low(self, event=None): |
---|
601 | """ |
---|
602 | Enable editing power law section at low q range |
---|
603 | """ |
---|
604 | if self.guinier.GetValue(): |
---|
605 | self.fix_enable_low.Disable() |
---|
606 | self.fit_enable_low.Disable() |
---|
607 | self.power_low_tcl.Disable() |
---|
608 | else: |
---|
609 | self.fix_enable_low.Enable() |
---|
610 | self.fit_enable_low.Enable() |
---|
611 | self.power_low_tcl.Enable() |
---|
612 | self._enable_fit_power_law_low() |
---|
613 | |
---|
614 | def _layout_extrapolation_low(self): |
---|
615 | """ |
---|
616 | Draw widgets related to extrapolation at low q range |
---|
617 | """ |
---|
618 | self.enable_low_cbox = wx.CheckBox(self, -1, "Enable Extrapolate Low Q") |
---|
619 | self.enable_low_cbox.SetValue(False) |
---|
620 | wx.EVT_CHECKBOX(self, self.enable_low_cbox.GetId(), |
---|
621 | self._enable_low_q_section) |
---|
622 | self.fix_enable_low = wx.RadioButton(self, -1, 'Fix', |
---|
623 | (10, 10),style=wx.RB_GROUP) |
---|
624 | self.fix_enable_low.SetValue(True) |
---|
625 | self.fit_enable_low = wx.RadioButton(self, -1, 'Fit', (10, 10)) |
---|
626 | self.Bind(wx.EVT_RADIOBUTTON, self._enable_fit_power_law_low, |
---|
627 | id=self.fix_enable_low.GetId()) |
---|
628 | self.Bind(wx.EVT_RADIOBUTTON, self._enable_fit_power_law_low, |
---|
629 | id=self.fit_enable_low.GetId()) |
---|
630 | self.guinier = wx.RadioButton(self, -1, 'Guinier', |
---|
631 | (10, 10),style=wx.RB_GROUP) |
---|
632 | self.guinier.SetValue(True) |
---|
633 | self.power_law_low = wx.RadioButton(self, -1, 'Power Law', (10, 10)) |
---|
634 | self.Bind(wx.EVT_RADIOBUTTON, self._enable_power_law_low, |
---|
635 | id=self.guinier.GetId()) |
---|
636 | self.Bind(wx.EVT_RADIOBUTTON, self._enable_power_law_low, |
---|
637 | id=self.power_law_low.GetId()) |
---|
638 | |
---|
639 | npts_low_txt = wx.StaticText(self, -1, 'Npts') |
---|
640 | self.npts_low_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1)) |
---|
641 | self.npts_low_tcl.SetValue(str(NPTS)) |
---|
642 | msg_hint = "Number of Q points to consider" |
---|
643 | msg_hint +="while extrapolating the low-Q region" |
---|
644 | self.npts_low_tcl.SetToolTipString(msg_hint) |
---|
645 | power_txt = wx.StaticText(self, -1, 'Power') |
---|
646 | self.power_low_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1)) |
---|
647 | self.power_low_tcl.SetValue(str(self.power_law_exponant)) |
---|
648 | self.power_low_tcl.Disable() |
---|
649 | power_hint_txt = "Exponent to apply to the Power_law function." |
---|
650 | self.power_low_tcl.SetToolTipString(power_hint_txt) |
---|
651 | iy = 0 |
---|
652 | ix = 0 |
---|
653 | self.low_q_sizer.Add(self.enable_low_cbox,(iy, ix),(1,5), |
---|
654 | wx.TOP|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
655 | iy += 1 |
---|
656 | ix = 0 |
---|
657 | self.low_q_sizer.Add(npts_low_txt,(iy, ix),(1,1), |
---|
658 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
659 | ix += 1 |
---|
660 | self.low_q_sizer.Add(self.npts_low_tcl, (iy, ix), (1,1), |
---|
661 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
662 | iy += 1 |
---|
663 | ix = 0 |
---|
664 | self.low_q_sizer.Add(self.guinier,(iy, ix),(1,2), |
---|
665 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
666 | iy += 1 |
---|
667 | ix = 0 |
---|
668 | self.low_q_sizer.Add(self.power_law_low,(iy, ix),(1,2), |
---|
669 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
670 | |
---|
671 | # Parameter controls for power law |
---|
672 | ix = 1 |
---|
673 | iy += 1 |
---|
674 | self.low_q_sizer.Add(self.fix_enable_low,(iy, ix),(1,1), |
---|
675 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
676 | ix += 1 |
---|
677 | self.low_q_sizer.Add(self.fit_enable_low,(iy, ix),(1,1), |
---|
678 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
679 | ix = 1 |
---|
680 | iy += 1 |
---|
681 | self.low_q_sizer.Add(power_txt,(iy, ix),(1,1), |
---|
682 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
683 | ix += 1 |
---|
684 | self.low_q_sizer.Add(self.power_low_tcl, (iy, ix), (1,1), |
---|
685 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
686 | #Change the state of txtcrtl to enable/disable |
---|
687 | self._enable_low_q_section() |
---|
688 | self.low_extrapolation_sizer.AddMany([(self.low_q_sizer, 0, |
---|
689 | wx.BOTTOM|wx.RIGHT, 10)]) |
---|
690 | def _enable_fit_power_law_high(self, event=None): |
---|
691 | """ |
---|
692 | Enable and disable the power value editing |
---|
693 | """ |
---|
694 | if self.fix_enable_high.IsEnabled(): |
---|
695 | if self.fix_enable_high.GetValue(): |
---|
696 | self.power_high_tcl.Enable() |
---|
697 | else: |
---|
698 | self.power_high_tcl.Disable() |
---|
699 | |
---|
700 | def _enable_high_q_section(self, event=None): |
---|
701 | """ |
---|
702 | Disable or enable some button if the user enable high q extrapolation |
---|
703 | """ |
---|
704 | if self.enable_high_cbox.GetValue(): |
---|
705 | self.npts_high_tcl.Enable() |
---|
706 | self.power_law_high.Enable() |
---|
707 | self.power_high_tcl.Enable() |
---|
708 | self.fix_enable_high.Enable() |
---|
709 | self.fit_enable_high.Enable() |
---|
710 | else: |
---|
711 | self.npts_high_tcl.Disable() |
---|
712 | self.power_law_high.Disable() |
---|
713 | self.power_high_tcl.Disable() |
---|
714 | self.fix_enable_high.Disable() |
---|
715 | self.fit_enable_high.Disable() |
---|
716 | self._enable_fit_power_law_high() |
---|
717 | |
---|
718 | def _layout_extrapolation_high(self): |
---|
719 | """ |
---|
720 | Draw widgets related to extrapolation at high q range |
---|
721 | """ |
---|
722 | self.enable_high_cbox = wx.CheckBox(self, -1, "Enable Extrapolate high-Q") |
---|
723 | self.enable_high_cbox.SetValue(False) |
---|
724 | wx.EVT_CHECKBOX(self, self.enable_high_cbox.GetId(), |
---|
725 | self._enable_high_q_section) |
---|
726 | |
---|
727 | self.fix_enable_high = wx.RadioButton(self, -1, 'Fix', |
---|
728 | (10, 10),style=wx.RB_GROUP) |
---|
729 | self.fix_enable_high.SetValue(True) |
---|
730 | self.fit_enable_high = wx.RadioButton(self, -1, 'Fit', (10, 10)) |
---|
731 | self.Bind(wx.EVT_RADIOBUTTON, self._enable_fit_power_law_high, |
---|
732 | id=self.fix_enable_high.GetId()) |
---|
733 | self.Bind(wx.EVT_RADIOBUTTON, self._enable_fit_power_law_high, |
---|
734 | id=self.fit_enable_high.GetId()) |
---|
735 | |
---|
736 | self.power_law_high = wx.StaticText(self, -1, 'Power Law') |
---|
737 | #msg_hint ="Check to extrapolate data at high-Q" |
---|
738 | #self.power_law_high.SetToolTipString(msg_hint) |
---|
739 | npts_high_txt = wx.StaticText(self, -1, 'Npts') |
---|
740 | self.npts_high_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1)) |
---|
741 | msg_hint = "Number of Q points to consider" |
---|
742 | msg_hint += "while extrapolating the high-Q region" |
---|
743 | self.npts_high_tcl.SetToolTipString(msg_hint) |
---|
744 | self.npts_high_tcl.SetValue(str(NPTS)) |
---|
745 | power_txt = wx.StaticText(self, -1, 'Power') |
---|
746 | self.power_high_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1)) |
---|
747 | self.power_high_tcl.SetValue(str(self.power_law_exponant)) |
---|
748 | power_hint_txt = "Exponent to apply to the Power_law function." |
---|
749 | self.power_high_tcl.SetToolTipString(power_hint_txt) |
---|
750 | iy = 0 |
---|
751 | ix = 0 |
---|
752 | self.high_q_sizer.Add(self.enable_high_cbox,(iy, ix),(1,5), |
---|
753 | wx.TOP|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
754 | iy += 1 |
---|
755 | ix = 0 |
---|
756 | self.high_q_sizer.Add(npts_high_txt,(iy, ix),(1,1), |
---|
757 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
758 | ix += 1 |
---|
759 | self.high_q_sizer.Add(self.npts_high_tcl, (iy, ix), (1,1), |
---|
760 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
761 | iy += 2 |
---|
762 | ix = 0 |
---|
763 | self.high_q_sizer.Add(self.power_law_high,(iy, ix),(1,2), |
---|
764 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
765 | |
---|
766 | # Parameter controls for power law |
---|
767 | ix = 1 |
---|
768 | iy += 1 |
---|
769 | self.high_q_sizer.Add(self.fix_enable_high,(iy, ix),(1,1), |
---|
770 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
771 | ix += 1 |
---|
772 | self.high_q_sizer.Add(self.fit_enable_high,(iy, ix),(1,1), |
---|
773 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
774 | ix = 1 |
---|
775 | iy += 1 |
---|
776 | self.high_q_sizer.Add(power_txt,(iy, ix),(1,1), |
---|
777 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
778 | ix += 1 |
---|
779 | self.high_q_sizer.Add(self.power_high_tcl, (iy, ix), (1,1), |
---|
780 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
781 | #Change the state of txtcrtl to enable/disable |
---|
782 | self._enable_high_q_section() |
---|
783 | self.high_extrapolation_sizer.AddMany([(self.high_q_sizer, 0, wx.RIGHT, 10)]) |
---|
784 | |
---|
785 | def _layout_extrapolation(self): |
---|
786 | """ |
---|
787 | Draw widgets related to extrapolation |
---|
788 | """ |
---|
789 | extra_hint = "Extrapolation Maximum Q Range [1/A]: " |
---|
790 | extra_hint_txt = wx.StaticText(self, -1, extra_hint) |
---|
791 | #Extrapolation range [string] |
---|
792 | extrapolation_min_txt = wx.StaticText(self, -1, 'Min : ') |
---|
793 | self.extrapolation_min_tcl = OutputTextCtrl(self, -1, |
---|
794 | size=(_BOX_WIDTH, 20), style=0) |
---|
795 | self.extrapolation_min_tcl.SetValue(str(Q_MINIMUM)) |
---|
796 | self.extrapolation_min_tcl.SetToolTipString("The minimum extrapolated q value.") |
---|
797 | extrapolation_max_txt = wx.StaticText(self, -1, 'Max : ') |
---|
798 | self.extrapolation_max_tcl = OutputTextCtrl(self, -1, |
---|
799 | size=(_BOX_WIDTH, 20), style=0) |
---|
800 | self.extrapolation_max_tcl.SetValue(str(Q_MAXIMUM)) |
---|
801 | self.extrapolation_max_tcl.SetToolTipString("The maximum extrapolated q value.") |
---|
802 | self.extrapolation_range_sizer.AddMany([(extra_hint_txt, 0, wx.LEFT, 10), |
---|
803 | (extrapolation_min_txt, 0, wx.LEFT, 10), |
---|
804 | (self.extrapolation_min_tcl, |
---|
805 | 0, wx.LEFT, 10), |
---|
806 | (extrapolation_max_txt, 0, wx.LEFT, 10), |
---|
807 | (self.extrapolation_max_tcl, |
---|
808 | 0, wx.LEFT, 10), |
---|
809 | ]) |
---|
810 | extra_enable_hint = "Hint: Check any box to enable a specific extrapolation !" |
---|
811 | extra_enable_hint_txt = wx.StaticText(self, -1, extra_enable_hint ) |
---|
812 | self.extrapolation_hint_sizer.AddMany([(extra_enable_hint_txt, 0, wx.LEFT, 0) |
---|
813 | ]) |
---|
814 | self._layout_extrapolation_low() |
---|
815 | self._layout_extrapolation_high() |
---|
816 | self.extrapolation_low_high_sizer.AddMany([(self.low_extrapolation_sizer, |
---|
817 | 0, wx.ALL, 10), |
---|
818 | (self.high_extrapolation_sizer, |
---|
819 | 0, wx.ALL, 10)]) |
---|
820 | self.extrapolation_sizer.AddMany([(self.extrapolation_range_sizer, 0, |
---|
821 | wx.RIGHT, 10), |
---|
822 | (self.extrapolation_hint_sizer, 0, |
---|
823 | wx.ALL, 10), |
---|
824 | (self.extrapolation_low_high_sizer, 0, |
---|
825 | wx.ALL, 10)]) |
---|
826 | |
---|
827 | def _layout_volume_surface_sizer(self): |
---|
828 | """ |
---|
829 | Draw widgets related to volume and surface |
---|
830 | """ |
---|
831 | unit_volume = '' |
---|
832 | unit_surface = '' |
---|
833 | uncertainty = "+/-" |
---|
834 | volume_txt = wx.StaticText(self, -1, 'Volume Fraction') |
---|
835 | self.volume_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
836 | self.volume_tcl.SetToolTipString("Volume fraction.") |
---|
837 | self.volume_err_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
838 | self.volume_err_tcl.SetToolTipString("Uncertainty on the volume fraction.") |
---|
839 | volume_units_txt = wx.StaticText(self, -1, unit_volume) |
---|
840 | |
---|
841 | surface_txt = wx.StaticText(self, -1, 'Specific Surface') |
---|
842 | self.surface_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
843 | self.surface_tcl.SetToolTipString("Specific surface value.") |
---|
844 | self.surface_err_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
845 | self.surface_err_tcl.SetToolTipString("Uncertainty on the specific surface.") |
---|
846 | surface_units_txt = wx.StaticText(self, -1, unit_surface) |
---|
847 | iy = 0 |
---|
848 | ix = 0 |
---|
849 | self.volume_surface_sizer.Add(volume_txt, (iy, ix), (1,1), |
---|
850 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
851 | ix += 1 |
---|
852 | self.volume_surface_sizer.Add(self.volume_tcl, (iy, ix), (1,1), |
---|
853 | wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
854 | ix += 1 |
---|
855 | self.volume_surface_sizer.Add(wx.StaticText(self, -1, uncertainty), |
---|
856 | (iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
857 | ix += 1 |
---|
858 | self.volume_surface_sizer.Add(self.volume_err_tcl, (iy, ix), (1,1), |
---|
859 | wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
860 | ix += 1 |
---|
861 | self.volume_surface_sizer.Add(volume_units_txt, (iy, ix), (1,1), |
---|
862 | wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
863 | iy += 1 |
---|
864 | ix = 0 |
---|
865 | self.volume_surface_sizer.Add(surface_txt, (iy, ix), (1,1), |
---|
866 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
867 | ix += 1 |
---|
868 | self.volume_surface_sizer.Add(self.surface_tcl, (iy, ix), (1,1), |
---|
869 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
870 | ix += 1 |
---|
871 | self.volume_surface_sizer.Add(wx.StaticText(self, -1, uncertainty), |
---|
872 | (iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
873 | ix += 1 |
---|
874 | self.volume_surface_sizer.Add(self.surface_err_tcl, (iy, ix), (1,1), |
---|
875 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
876 | ix += 1 |
---|
877 | self.volume_surface_sizer.Add(surface_units_txt, (iy, ix), (1,1), |
---|
878 | wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
879 | |
---|
880 | def _layout_invariant_sizer(self): |
---|
881 | """ |
---|
882 | Draw widgets related to invariant |
---|
883 | """ |
---|
884 | uncertainty = "+/-" |
---|
885 | unit_invariant = '[1/(cm * A)]' |
---|
886 | invariant_total_txt = wx.StaticText(self, -1, 'Invariant Total') |
---|
887 | self.invariant_total_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
888 | msg_hint = "Total invariant, including extrapolated regions." |
---|
889 | self.invariant_total_tcl.SetToolTipString(msg_hint) |
---|
890 | self.invariant_total_err_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
891 | self.invariant_total_err_tcl.SetToolTipString("Uncertainty on invariant.") |
---|
892 | invariant_total_units_txt = wx.StaticText(self, -1, unit_invariant) |
---|
893 | |
---|
894 | #Invariant total |
---|
895 | iy = 0 |
---|
896 | ix = 0 |
---|
897 | self.invariant_sizer.Add(invariant_total_txt, (iy, ix), (1,1), |
---|
898 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
899 | ix += 1 |
---|
900 | self.invariant_sizer.Add(self.invariant_total_tcl, (iy, ix), (1,1), |
---|
901 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) |
---|
902 | ix += 1 |
---|
903 | self.invariant_sizer.Add( wx.StaticText(self, -1, uncertainty), |
---|
904 | (iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
905 | ix += 1 |
---|
906 | self.invariant_sizer.Add(self.invariant_total_err_tcl, (iy, ix), (1,1), |
---|
907 | wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
908 | ix += 1 |
---|
909 | self.invariant_sizer.Add(invariant_total_units_txt,(iy, ix), (1,1), |
---|
910 | wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
911 | |
---|
912 | def _layout_outputs_sizer(self): |
---|
913 | """ |
---|
914 | Draw widgets related to outputs |
---|
915 | """ |
---|
916 | self._layout_volume_surface_sizer() |
---|
917 | self._layout_invariant_sizer() |
---|
918 | static_line = wx.StaticLine(self, -1) |
---|
919 | self.outputs_sizer.AddMany([(self.volume_surface_sizer, 0, wx.ALL, 10), |
---|
920 | (static_line, 0, wx.EXPAND, 0), |
---|
921 | (self.invariant_sizer, 0, wx.ALL, 10)]) |
---|
922 | def _layout_button(self): |
---|
923 | """ |
---|
924 | Do the layout for the button widgets |
---|
925 | """ |
---|
926 | #compute button |
---|
927 | id = wx.NewId() |
---|
928 | button_calculate = wx.Button(self, id, "Compute") |
---|
929 | button_calculate.SetToolTipString("Compute invariant") |
---|
930 | self.Bind(wx.EVT_BUTTON, self.compute_invariant, id=id) |
---|
931 | #detail button |
---|
932 | id = wx.NewId() |
---|
933 | self.button_ok = wx.Button(self, id, "Details?") |
---|
934 | self.button_ok.SetToolTipString("Give Details on Computation") |
---|
935 | self.Bind(wx.EVT_BUTTON, self.display_details, id=id) |
---|
936 | self.button_ok.Disable() |
---|
937 | details = "Details on Invariant Total Calculations" |
---|
938 | details_txt = wx.StaticText(self, -1, details) |
---|
939 | self.button_sizer.AddMany([((20,20), 0 , wx.LEFT, 100), |
---|
940 | (details_txt, 0 , wx.ALL, 10), |
---|
941 | (self.button_ok, 0 , wx.ALL, 10), |
---|
942 | (button_calculate, 0 , wx.RIGHT|wx.TOP|wx.BOTTOM, 10)]) |
---|
943 | |
---|
944 | def _do_layout(self): |
---|
945 | """ |
---|
946 | Draw window content |
---|
947 | """ |
---|
948 | self._define_structure() |
---|
949 | self._layout_data_name() |
---|
950 | self._layout_background() |
---|
951 | self._layout_scale() |
---|
952 | self._layout_contrast() |
---|
953 | self._layout_porod_constant() |
---|
954 | self._layout_extrapolation() |
---|
955 | self._layout_outputs_sizer() |
---|
956 | self._layout_button() |
---|
957 | self.main_sizer.AddMany([(self.data_name_boxsizer, 0, wx.ALL, 10), |
---|
958 | (self.background_sizer, 0, |
---|
959 | wx.LEFT|wx.RIGHT|wx.BOTTOM, 10), |
---|
960 | (self.scale_sizer, 0, |
---|
961 | wx.LEFT|wx.RIGHT|wx.BOTTOM, 10), |
---|
962 | (self.contrast_sizer, 0, |
---|
963 | wx.LEFT|wx.RIGHT|wx.BOTTOM, 10), |
---|
964 | (self.porod_constant_sizer, 0, |
---|
965 | wx.LEFT|wx.RIGHT|wx.BOTTOM, 10), |
---|
966 | (self.extrapolation_sizer, 0, |
---|
967 | wx.LEFT|wx.RIGHT|wx.BOTTOM, 10), |
---|
968 | (self.outputs_sizer, 0, |
---|
969 | wx.LEFT|wx.RIGHT|wx.BOTTOM, 10), |
---|
970 | (self.button_sizer, 0, |
---|
971 | wx.LEFT|wx.RIGHT|wx.BOTTOM, 10)]) |
---|
972 | self.SetSizer(self.main_sizer) |
---|
973 | self.SetScrollbars(20,20,25,65) |
---|
974 | self.SetAutoLayout(True) |
---|
975 | |
---|
976 | class InvariantDialog(wx.Dialog): |
---|
977 | def __init__(self, parent=None, id=1,graph=None, |
---|
978 | data=None, title="Invariant",base=None): |
---|
979 | wx.Dialog.__init__(self, parent, id, title, size=(PANEL_WIDTH, |
---|
980 | PANEL_HEIGHT)) |
---|
981 | self.panel = InvariantPanel(self) |
---|
982 | self.Centre() |
---|
983 | self.Show(True) |
---|
984 | |
---|
985 | class InvariantWindow(wx.Frame): |
---|
986 | def __init__(self, parent=None, id=1,graph=None, |
---|
987 | data=None, title="Invariant",base=None): |
---|
988 | |
---|
989 | wx.Frame.__init__(self, parent, id, title, size=(PANEL_WIDTH +100, |
---|
990 | PANEL_HEIGHT+100)) |
---|
991 | |
---|
992 | self.panel = InvariantPanel(self) |
---|
993 | self.Centre() |
---|
994 | self.Show(True) |
---|
995 | |
---|
996 | class MyApp(wx.App): |
---|
997 | def OnInit(self): |
---|
998 | wx.InitAllImageHandlers() |
---|
999 | frame = InvariantWindow() |
---|
1000 | frame.Show(True) |
---|
1001 | self.SetTopWindow(frame) |
---|
1002 | |
---|
1003 | return True |
---|
1004 | |
---|
1005 | # end of class MyApp |
---|
1006 | |
---|
1007 | if __name__ == "__main__": |
---|
1008 | app = MyApp(0) |
---|
1009 | app.MainLoop() |
---|