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 | |
---|
11 | from sans.guiframe.utils import format_number, check_float |
---|
12 | from sans.guicomm.events import NewPlotEvent, StatusEvent |
---|
13 | |
---|
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 | #Invariant panel size |
---|
27 | _BOX_WIDTH = 76 |
---|
28 | _SCALE = 1e-6 |
---|
29 | |
---|
30 | if sys.platform.count("win32")>0: |
---|
31 | _STATICBOX_WIDTH = 450 |
---|
32 | PANEL_WIDTH = 500 |
---|
33 | PANEL_HEIGHT = 700 |
---|
34 | FONT_VARIANT = 0 |
---|
35 | else: |
---|
36 | _STATICBOX_WIDTH = 480 |
---|
37 | PANEL_WIDTH = 530 |
---|
38 | PANEL_HEIGHT = 700 |
---|
39 | FONT_VARIANT = 1 |
---|
40 | |
---|
41 | class InvariantPanel(wx.ScrolledWindow): |
---|
42 | """ |
---|
43 | Provides the Invariant GUI. |
---|
44 | """ |
---|
45 | ## Internal nickname for the window, used by the AUI manager |
---|
46 | window_name = "Invariant" |
---|
47 | ## Name to appear on the window title bar |
---|
48 | window_caption = "Invariant" |
---|
49 | ## Flag to tell the AUI manager to put this panel in the center pane |
---|
50 | CENTER_PANE = True |
---|
51 | def __init__(self, parent, data=None, manager=None): |
---|
52 | wx.ScrolledWindow.__init__(self, parent, style= wx.FULL_REPAINT_ON_RESIZE ) |
---|
53 | #Font size |
---|
54 | self.SetWindowVariant(variant=FONT_VARIANT) |
---|
55 | #Object that receive status event |
---|
56 | self.parent = parent |
---|
57 | #plug-in using this panel |
---|
58 | self._manager = manager |
---|
59 | #Default power value |
---|
60 | self.power_law_exponant = 4 |
---|
61 | #Data uses for computation |
---|
62 | self._data = data |
---|
63 | #Draw the panel |
---|
64 | self._do_layout() |
---|
65 | self.SetScrollbars(20,20,25,65) |
---|
66 | self.SetAutoLayout(True) |
---|
67 | self.Layout() |
---|
68 | |
---|
69 | def set_data(self, data): |
---|
70 | """ |
---|
71 | Set the data |
---|
72 | """ |
---|
73 | self._data = data |
---|
74 | #edit the panel |
---|
75 | if self._data is not None: |
---|
76 | data_name = self._data.name |
---|
77 | data_qmin = min (self._data.x) |
---|
78 | data_qmax = max (self._data.x) |
---|
79 | data_range = "[%s - %s]"%(str(data_qmin), str(data_qmax)) |
---|
80 | |
---|
81 | self.data_name_txt.SetLabel('Data : '+str(data_name)) |
---|
82 | self.data_range_value_txt.SetLabel(str(data_range)) |
---|
83 | |
---|
84 | def set_manager(self, manager): |
---|
85 | """ |
---|
86 | set value for the manager |
---|
87 | """ |
---|
88 | self._manager = manager |
---|
89 | |
---|
90 | def compute_invariant(self, event): |
---|
91 | """ |
---|
92 | compute invariant |
---|
93 | """ |
---|
94 | #clear outputs textctrl |
---|
95 | self._reset_output() |
---|
96 | background = self.background_ctl.GetValue().lstrip().rstrip() |
---|
97 | scale = self.scale_ctl.GetValue().lstrip().rstrip() |
---|
98 | if background == "": |
---|
99 | background = 0 |
---|
100 | if scale == "": |
---|
101 | scale = 1 |
---|
102 | if check_float(self.background_ctl) and check_float(self.scale_ctl): |
---|
103 | inv = invariant.InvariantCalculator(data=self._data, |
---|
104 | background=float(background), |
---|
105 | scale=float(scale)) |
---|
106 | |
---|
107 | #Get the number of points to extrapolated |
---|
108 | npts_low = self.npts_low_ctl.GetValue() |
---|
109 | if check_float(self.npts_low_ctl): |
---|
110 | npts_low = float(npts_low) |
---|
111 | power_low = self.power_low_ctl.GetValue() |
---|
112 | if check_float(self.power_low_ctl): |
---|
113 | power_low = float(power_low) |
---|
114 | npts_high = self.npts_high_ctl.GetValue() |
---|
115 | if check_float(self.npts_high_ctl): |
---|
116 | npts_high = float(npts_high) |
---|
117 | power_high = self.power_high_ctl.GetValue() |
---|
118 | if check_float(self.power_high_ctl): |
---|
119 | power_high = float(power_high) |
---|
120 | # get the function |
---|
121 | if self.power_law_low.GetValue(): |
---|
122 | function_low = "power_law" |
---|
123 | if self.guinier.GetValue(): |
---|
124 | function_low = "guinier" |
---|
125 | #power_low = None |
---|
126 | |
---|
127 | function_high = "power_law" |
---|
128 | if self.power_law_high.GetValue(): |
---|
129 | function_high = "power_law" |
---|
130 | #check the type of extrapolation |
---|
131 | extrapolation = None |
---|
132 | low_q = self.enable_low_cbox.GetValue() |
---|
133 | high_q = self.enable_high_cbox.GetValue() |
---|
134 | if low_q and not high_q: |
---|
135 | extrapolation = "low" |
---|
136 | elif not low_q and high_q: |
---|
137 | extrapolation = "high" |
---|
138 | elif low_q and high_q: |
---|
139 | extrapolation = "both" |
---|
140 | |
---|
141 | #Set the invariant calculator |
---|
142 | inv.set_extrapolation(range="low", npts=npts_low, |
---|
143 | function=function_low, power=power_low) |
---|
144 | inv.set_extrapolation(range="high", npts=npts_high, |
---|
145 | function=function_high, power=power_high) |
---|
146 | #Compute invariant |
---|
147 | try: |
---|
148 | qstar, qstar_err = inv.get_qstar_with_error() |
---|
149 | self.invariant_ctl.SetValue(format_number(qstar)) |
---|
150 | self.invariant_err_ctl.SetValue(format_number(qstar)) |
---|
151 | except: |
---|
152 | msg= "Error occurred computing invariant: %s"%sys.exc_value |
---|
153 | wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) |
---|
154 | return |
---|
155 | #Compute qstar extrapolated to low q range |
---|
156 | #Clear the previous extrapolated plot |
---|
157 | if low_q: |
---|
158 | try: |
---|
159 | qstar_low, qstar_low_err = inv.get_qstar_low() |
---|
160 | self.invariant_low_ctl.SetValue(format_number(qstar_low)) |
---|
161 | extrapolated_data = inv.get_extra_data_low(npts_in=npts_low) |
---|
162 | self._manager.plot_theory(data=extrapolated_data, |
---|
163 | name="Low-Q extrapolation") |
---|
164 | except: |
---|
165 | msg= "Error occurred computing low-Q invariant: %s"%sys.exc_value |
---|
166 | wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) |
---|
167 | else: |
---|
168 | self._manager.plot_theory(name="Low-Q extrapolation") |
---|
169 | |
---|
170 | if high_q: |
---|
171 | try: |
---|
172 | qstar_high, qstar_high_err = inv.get_qstar_high() |
---|
173 | self.invariant_high_ctl.SetValue(format_number(qstar_high)) |
---|
174 | high_out_data = inv.get_extra_data_high(q_end=Q_MAXIMUM_PLOT) |
---|
175 | self._manager.plot_theory(data=high_out_data, |
---|
176 | name="High-Q extrapolation") |
---|
177 | except: |
---|
178 | msg= "Error occurred computing high-Q invariant: %s"%sys.exc_value |
---|
179 | wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) |
---|
180 | else: |
---|
181 | self._manager.plot_theory(name="High-Q extrapolation") |
---|
182 | |
---|
183 | try: |
---|
184 | qstar_total, qstar_total_err = inv.get_qstar_with_error(extrapolation) |
---|
185 | self.invariant_total_ctl.SetValue(format_number(qstar_total)) |
---|
186 | self.invariant_total_err_ctl.SetValue(format_number(qstar_total)) |
---|
187 | check_float(self.invariant_total_ctl) |
---|
188 | check_float(self.invariant_total_err_ctl) |
---|
189 | except: |
---|
190 | msg= "Error occurred computing invariant using extrapolation: %s"%sys.exc_value |
---|
191 | wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) |
---|
192 | |
---|
193 | # Parse additional parameters |
---|
194 | par_str = self.porod_const_ctl.GetValue().strip() |
---|
195 | porod_const = None |
---|
196 | if len(par_str)>0 and check_float(self.porod_const_ctl): |
---|
197 | porod_const = float(par_str) |
---|
198 | |
---|
199 | par_str = self.contrast_ctl.GetValue().strip() |
---|
200 | contrast = None |
---|
201 | if len(par_str)>0 and check_float(self.contrast_ctl): |
---|
202 | contrast = float(par_str) |
---|
203 | |
---|
204 | if contrast is not None: |
---|
205 | try: |
---|
206 | v, dv = inv.get_volume_fraction_with_error(contrast=contrast, |
---|
207 | extrapolation=extrapolation) |
---|
208 | self.volume_ctl.SetValue(format_number(v)) |
---|
209 | self.volume_err_ctl.SetValue(format_number(dv)) |
---|
210 | except: |
---|
211 | msg= "Error occurred computing volume fraction: %s"%sys.exc_value |
---|
212 | wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) |
---|
213 | |
---|
214 | if contrast is not None and porod_const is not None: |
---|
215 | try: |
---|
216 | s, ds = inv.get_surface_with_error(contrast=contrast, |
---|
217 | porod_const=porod_const, |
---|
218 | extrapolation=extrapolation) |
---|
219 | self.surface_ctl.SetValue(format_number(s)) |
---|
220 | self.surface_err_ctl.SetValue(format_number(ds)) |
---|
221 | except: |
---|
222 | msg= "Error occurred computing specific surface: %s"%sys.exc_value |
---|
223 | wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) |
---|
224 | |
---|
225 | else: |
---|
226 | msg= "A float value is required for background and scale" |
---|
227 | wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) |
---|
228 | return |
---|
229 | |
---|
230 | def _reset_output(self): |
---|
231 | """ |
---|
232 | clear outputs textcrtl |
---|
233 | """ |
---|
234 | self.invariant_ctl.Clear() |
---|
235 | self.invariant_err_ctl.Clear() |
---|
236 | self.invariant_low_ctl.Clear() |
---|
237 | self.invariant_high_ctl.Clear() |
---|
238 | self.invariant_total_ctl.Clear() |
---|
239 | self.invariant_total_err_ctl.Clear() |
---|
240 | self.volume_ctl.Clear() |
---|
241 | self.volume_err_ctl.Clear() |
---|
242 | self.surface_ctl.Clear() |
---|
243 | self.surface_err_ctl.Clear() |
---|
244 | |
---|
245 | def _do_layout(self): |
---|
246 | """ |
---|
247 | Draw window content |
---|
248 | """ |
---|
249 | unit_invariant = '[1/cm][1/A]' |
---|
250 | unit_volume = '' |
---|
251 | unit_surface = '' |
---|
252 | uncertainty = "+/-" |
---|
253 | npts_hint_txt = "Number of points to consider during extrapolation." |
---|
254 | power_hint_txt = "Exponent to apply to the Power_law function." |
---|
255 | |
---|
256 | sizer_input = wx.FlexGridSizer(5,4)#wx.GridBagSizer(5,5) |
---|
257 | sizer_output = wx.GridBagSizer(5,5) |
---|
258 | sizer_button = wx.BoxSizer(wx.HORIZONTAL) |
---|
259 | |
---|
260 | sizer1 = wx.BoxSizer(wx.VERTICAL) |
---|
261 | sizer2 = wx.BoxSizer(wx.VERTICAL) |
---|
262 | sizer3 = wx.BoxSizer(wx.HORIZONTAL) |
---|
263 | |
---|
264 | sizer1.SetMinSize((_STATICBOX_WIDTH, -1)) |
---|
265 | sizer2.SetMinSize((_STATICBOX_WIDTH, -1)) |
---|
266 | sizer3.SetMinSize((_STATICBOX_WIDTH, -1)) |
---|
267 | |
---|
268 | ## Box sizers must be defined first before defining buttons/textctrls (MAC). |
---|
269 | vbox = wx.BoxSizer(wx.VERTICAL) |
---|
270 | inputbox = wx.StaticBox(self, -1, "Input") |
---|
271 | extrapolation_box = wx.StaticBox(self, -1, "Extrapolation") |
---|
272 | boxsizer1 = wx.StaticBoxSizer(inputbox, wx.VERTICAL) |
---|
273 | high_q_box = wx.StaticBox(self, -1, "High Q") |
---|
274 | boxsizer_high_q = wx.StaticBoxSizer(high_q_box, wx.VERTICAL) |
---|
275 | low_q_box = wx.StaticBox(self, -1, "Low Q") |
---|
276 | boxsizer_low_q = wx.StaticBoxSizer(low_q_box, wx.VERTICAL) |
---|
277 | |
---|
278 | #---------inputs---------------- |
---|
279 | data_name = "" |
---|
280 | data_range = "[? - ?]" |
---|
281 | if self._data is not None: |
---|
282 | data_name = self._data.name |
---|
283 | data_qmin = min (self._data.x) |
---|
284 | data_qmax = max (self._data.x) |
---|
285 | data_range = "[%s - %s]"%(str(data_qmin), str(data_qmax)) |
---|
286 | |
---|
287 | self.data_name_txt = wx.StaticText(self, -1, 'Data : '+str(data_name)) |
---|
288 | data_range_txt = wx.StaticText(self, -1, "Range : ") |
---|
289 | self.data_range_value_txt = wx.StaticText(self, -1, str(data_range)) |
---|
290 | |
---|
291 | background_txt = wx.StaticText(self, -1, 'Background') |
---|
292 | self.background_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
293 | self.background_ctl.SetValue(str(BACKGROUND)) |
---|
294 | self.background_ctl.SetToolTipString("Background to be subtracted from data.") |
---|
295 | scale_txt = wx.StaticText(self, -1, 'Scale') |
---|
296 | self.scale_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
297 | self.scale_ctl.SetValue(str(SCALE)) |
---|
298 | self.scale_ctl.SetToolTipString("Scaling factor to be applied to data.") |
---|
299 | contrast_txt = wx.StaticText(self, -1, 'Contrast (Optional)') |
---|
300 | self.contrast_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
301 | msg_hint = "Enter a value for the contrast to compute the volume fraction" |
---|
302 | self.contrast_ctl.SetToolTipString(str(msg_hint)) |
---|
303 | porod_const_txt = wx.StaticText(self, -1, 'Porod Constant (Optional)') |
---|
304 | self.porod_const_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
305 | msg_hint ="Enter a Porod constant value to compute the specific surface" |
---|
306 | self.porod_const_ctl.SetToolTipString(str(msg_hint)) |
---|
307 | |
---|
308 | sizer_input.Add(self.data_name_txt, 0, wx.LEFT, 5) |
---|
309 | sizer_input.Add((10,10), 0, wx.LEFT, 5) |
---|
310 | sizer_input.Add(data_range_txt, 0, wx.LEFT, 10) |
---|
311 | sizer_input.Add(self.data_range_value_txt) |
---|
312 | sizer_input.Add(background_txt, 0, wx.ALL, 5) |
---|
313 | sizer_input.Add(self.background_ctl, 0, wx.ALL, 5) |
---|
314 | sizer_input.Add((10,10)) |
---|
315 | sizer_input.Add((10,10)) |
---|
316 | sizer_input.Add(scale_txt, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM, 5) |
---|
317 | sizer_input.Add(self.scale_ctl, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM, 5) |
---|
318 | sizer_input.Add((10,10)) |
---|
319 | sizer_input.Add((10,10)) |
---|
320 | sizer_input.Add(contrast_txt, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM, 5) |
---|
321 | sizer_input.Add(self.contrast_ctl, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM, 5) |
---|
322 | sizer_input.Add((10,10)) |
---|
323 | sizer_input.Add((10,10)) |
---|
324 | sizer_input.Add(porod_const_txt, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM, 5) |
---|
325 | sizer_input.Add(self.porod_const_ctl, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM, 5) |
---|
326 | #-------------Extrapolation sizer---------------- |
---|
327 | sizer_low_q = wx.GridBagSizer(5,5) |
---|
328 | |
---|
329 | self.enable_low_cbox = wx.CheckBox(self, -1, "Extrapolate low-Q") |
---|
330 | self.enable_low_cbox.SetValue(False) |
---|
331 | self.enable_high_cbox = wx.CheckBox(self, -1, "Extrapolate high-Q") |
---|
332 | self.enable_high_cbox.SetValue(False) |
---|
333 | |
---|
334 | self.guinier = wx.RadioButton(self, -1, 'Guinier', |
---|
335 | (10, 10),style=wx.RB_GROUP) |
---|
336 | self.power_law_low = wx.RadioButton(self, -1, 'Power Law', (10, 10)) |
---|
337 | self.guinier.SetValue(True) |
---|
338 | |
---|
339 | npts_low_txt = wx.StaticText(self, -1, 'Npts') |
---|
340 | self.npts_low_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/3, -1)) |
---|
341 | self.npts_low_ctl.SetValue(str(NPTS)) |
---|
342 | msg_hint = "Number of Q points to consider" |
---|
343 | msg_hint +="while extrapolating the low-Q region" |
---|
344 | self.npts_low_ctl.SetToolTipString(msg_hint) |
---|
345 | npts_exp_txt = wx.StaticText(self, -1, 'Power') |
---|
346 | self.power_low_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/3, -1)) |
---|
347 | self.power_low_ctl.SetValue(str(self.power_law_exponant)) |
---|
348 | self.power_low_ctl.SetToolTipString(power_hint_txt) |
---|
349 | iy = 0 |
---|
350 | ix = 0 |
---|
351 | sizer_low_q.Add(self.guinier,(iy, ix),(1,2), |
---|
352 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
353 | iy += 1 |
---|
354 | ix = 0 |
---|
355 | |
---|
356 | sizer_low_q.Add(self.power_law_low,(iy, ix),(1,2), |
---|
357 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
358 | |
---|
359 | # Parameter controls for power law |
---|
360 | ix = 1 |
---|
361 | iy += 1 |
---|
362 | sizer_low_q.Add(npts_exp_txt,(iy, ix),(1,1), |
---|
363 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
364 | |
---|
365 | ix += 1 |
---|
366 | sizer_low_q.Add(self.power_low_ctl, (iy, ix), (1,1), |
---|
367 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
368 | iy += 1 |
---|
369 | ix = 1 |
---|
370 | sizer_low_q.Add(npts_low_txt,(iy, ix),(1,1), |
---|
371 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
372 | ix += 1 |
---|
373 | sizer_low_q.Add(self.npts_low_ctl, (iy, ix), (1,1), |
---|
374 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
375 | iy += 1 |
---|
376 | ix = 0 |
---|
377 | sizer_low_q.Add(self.enable_low_cbox,(iy, ix),(1,5), |
---|
378 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
379 | sizer_high_q = wx.GridBagSizer(5,5) |
---|
380 | self.power_law_high = wx.RadioButton(self, -1, 'Power Law', |
---|
381 | (10, 10), style=wx.RB_GROUP) |
---|
382 | msg_hint ="Check to extrapolate data at high-Q" |
---|
383 | self.power_law_high.SetToolTipString(msg_hint) |
---|
384 | |
---|
385 | #MAC needs SetValue |
---|
386 | self.power_law_high.SetValue(True) |
---|
387 | npts_high_txt = wx.StaticText(self, -1, 'Npts') |
---|
388 | npts_high_exp_txt = wx.StaticText(self, -1, 'Power') |
---|
389 | self.npts_high_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/3, -1)) |
---|
390 | msg_hint = "Number of Q points to consider" |
---|
391 | msg_hint += "while extrapolating the high-Q region" |
---|
392 | self.npts_high_ctl.SetToolTipString(msg_hint) |
---|
393 | self.npts_high_ctl.SetValue(str(NPTS)) |
---|
394 | self.power_high_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/3, -1)) |
---|
395 | self.power_high_ctl.SetValue(str(self.power_law_exponant)) |
---|
396 | self.power_high_ctl.SetToolTipString(power_hint_txt) |
---|
397 | |
---|
398 | iy = 1 |
---|
399 | ix = 0 |
---|
400 | sizer_high_q.Add(self.power_law_high,(iy, ix),(1,2), |
---|
401 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
402 | ix = 1 |
---|
403 | iy += 1 |
---|
404 | sizer_high_q.Add(npts_high_exp_txt,(iy, ix),(1,1), |
---|
405 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
406 | |
---|
407 | ix += 1 |
---|
408 | sizer_high_q.Add(self.power_high_ctl, (iy, ix), (1,1), |
---|
409 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
410 | iy += 1 |
---|
411 | ix = 1 |
---|
412 | sizer_high_q.Add(npts_high_txt,(iy, ix),(1,1), |
---|
413 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
414 | ix += 1 |
---|
415 | sizer_high_q.Add(self.npts_high_ctl, (iy, ix), (1,1), |
---|
416 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
417 | iy += 1 |
---|
418 | ix = 0 |
---|
419 | sizer_high_q.Add(self.enable_high_cbox,(iy, ix),(1,5), |
---|
420 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
421 | |
---|
422 | boxsizer_high_q.Add(sizer_high_q) |
---|
423 | boxsizer_low_q.Add(sizer_low_q) |
---|
424 | |
---|
425 | #-------------Enable extrapolation------- |
---|
426 | extra_hint = "Extrapolation Maximum Range: " |
---|
427 | extra_hint_txt= wx.StaticText(self, -1,extra_hint ) |
---|
428 | extra_range = "[%s - %s]"%(str(Q_MINIMUM), str(Q_MAXIMUM)) |
---|
429 | extra_range_value_txt = wx.StaticText(self, -1, str(extra_range)) |
---|
430 | extra_enable_hint = "Hint: Check any box to enable a specific extrapolation !" |
---|
431 | extra_enable_hint_txt= wx.StaticText(self, -1, extra_enable_hint ) |
---|
432 | |
---|
433 | enable_sizer = wx.GridBagSizer(5,5) |
---|
434 | |
---|
435 | iy = 0 |
---|
436 | ix = 0 |
---|
437 | enable_sizer.Add(extra_hint_txt,(iy, ix),(1,1), |
---|
438 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
439 | ix += 1 |
---|
440 | enable_sizer.Add(extra_range_value_txt, (iy, ix), (1,1), |
---|
441 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
442 | ix = 0 |
---|
443 | iy += 1 |
---|
444 | enable_sizer.Add(extra_enable_hint_txt,(iy, ix),(1,1), |
---|
445 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
446 | |
---|
447 | type_extrapolation_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
448 | type_extrapolation_sizer.Add((10,10)) |
---|
449 | type_extrapolation_sizer.Add(boxsizer_low_q, 0, wx.ALL, 10) |
---|
450 | type_extrapolation_sizer.Add((20,20)) |
---|
451 | type_extrapolation_sizer.Add(boxsizer_high_q, 0, wx.ALL, 10) |
---|
452 | type_extrapolation_sizer.Add((10,10)) |
---|
453 | |
---|
454 | boxsizer_extra = wx.StaticBoxSizer(extrapolation_box, wx.VERTICAL) |
---|
455 | boxsizer_extra.Add(enable_sizer, 0, wx.ALL, 10) |
---|
456 | boxsizer_extra.Add(type_extrapolation_sizer) |
---|
457 | |
---|
458 | boxsizer1.SetMinSize((_STATICBOX_WIDTH,-1)) |
---|
459 | boxsizer1.Add(sizer_input) |
---|
460 | boxsizer1.Add(boxsizer_extra, 0, wx.ALL, 10) |
---|
461 | sizer1.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
462 | |
---|
463 | #---------Outputs sizer-------- |
---|
464 | invariant_txt = wx.StaticText(self, -1, 'Invariant') |
---|
465 | self.invariant_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
466 | self.invariant_ctl.SetEditable(False) |
---|
467 | self.invariant_ctl.SetToolTipString("Invariant in the data set's Q range.") |
---|
468 | self.invariant_err_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
469 | self.invariant_err_ctl.SetEditable(False) |
---|
470 | self.invariant_err_ctl.SetToolTipString("Uncertainty on the invariant.") |
---|
471 | invariant_units_txt = wx.StaticText(self, -1, unit_invariant) |
---|
472 | |
---|
473 | invariant_total_txt = wx.StaticText(self, -1, 'Invariant Total') |
---|
474 | self.invariant_total_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
475 | self.invariant_total_ctl.SetEditable(False) |
---|
476 | msg_hint = "Total invariant, including extrapolated regions." |
---|
477 | self.invariant_total_ctl.SetToolTipString(msg_hint) |
---|
478 | self.invariant_total_err_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
479 | self.invariant_total_err_ctl.SetEditable(False) |
---|
480 | self.invariant_total_err_ctl.SetToolTipString("Uncertainty on invariant.") |
---|
481 | invariant_total_units_txt = wx.StaticText(self, -1, unit_invariant) |
---|
482 | |
---|
483 | volume_txt = wx.StaticText(self, -1, 'Volume Fraction') |
---|
484 | self.volume_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
485 | self.volume_ctl.SetEditable(False) |
---|
486 | self.volume_ctl.SetToolTipString("Volume fraction.") |
---|
487 | self.volume_err_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
488 | self.volume_err_ctl.SetEditable(False) |
---|
489 | self.volume_err_ctl.SetToolTipString("Uncertainty on the volume fraction.") |
---|
490 | volume_units_txt = wx.StaticText(self, -1, unit_volume) |
---|
491 | |
---|
492 | surface_txt = wx.StaticText(self, -1, 'Specific surface') |
---|
493 | self.surface_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
494 | self.surface_ctl.SetEditable(False) |
---|
495 | self.surface_ctl.SetToolTipString("Specific surface value.") |
---|
496 | self.surface_err_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
497 | self.surface_err_ctl.SetEditable(False) |
---|
498 | self.surface_err_ctl.SetToolTipString("Uncertainty on the specific surface.") |
---|
499 | surface_units_txt = wx.StaticText(self, -1, unit_surface) |
---|
500 | |
---|
501 | invariant_low_txt = wx.StaticText(self, -1, 'Invariant in low-Q region') |
---|
502 | self.invariant_low_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
503 | self.invariant_low_ctl.SetEditable(False) |
---|
504 | self.invariant_low_ctl.SetToolTipString("Invariant computed with the extrapolated low-Q data.") |
---|
505 | invariant_low_units_txt = wx.StaticText(self, -1, unit_invariant) |
---|
506 | |
---|
507 | invariant_high_txt = wx.StaticText(self, -1, 'Invariant in high-Q region') |
---|
508 | self.invariant_high_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
509 | self.invariant_high_ctl.SetEditable(False) |
---|
510 | self.invariant_high_ctl.SetToolTipString("Invariant computed with the extrapolated high-Q data") |
---|
511 | invariant_high_units_txt = wx.StaticText(self, -1, unit_invariant) |
---|
512 | |
---|
513 | iy = 0 |
---|
514 | ix = 0 |
---|
515 | sizer_output.Add(invariant_low_txt, (iy, ix), (1,1), |
---|
516 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
517 | ix +=1 |
---|
518 | sizer_output.Add(self.invariant_low_ctl, (iy, ix), (1,1), |
---|
519 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
520 | ix += 2 |
---|
521 | sizer_output.Add(invariant_low_units_txt, (iy, ix), (1,1), |
---|
522 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
523 | iy += 1 |
---|
524 | ix = 0 |
---|
525 | sizer_output.Add(invariant_high_txt, (iy, ix), (1,1), |
---|
526 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
527 | ix +=1 |
---|
528 | sizer_output.Add(self.invariant_high_ctl, (iy, ix), (1,1), |
---|
529 | wx.EXPAND|wx.ADJUST_MINSIZE, ) |
---|
530 | ix += 2 |
---|
531 | sizer_output.Add(invariant_high_units_txt, (iy, ix), (1,1), |
---|
532 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
533 | iy += 1 |
---|
534 | ix = 0 |
---|
535 | sizer_output.Add(invariant_txt,(iy, ix),(1,1), |
---|
536 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
537 | ix += 1 |
---|
538 | sizer_output.Add(self.invariant_ctl,(iy, ix),(1,1), |
---|
539 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
540 | ix += 1 |
---|
541 | sizer_output.Add( wx.StaticText(self, -1, uncertainty), |
---|
542 | (iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
543 | ix +=1 |
---|
544 | sizer_output.Add(self.invariant_err_ctl |
---|
545 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
546 | ix +=1 |
---|
547 | sizer_output.Add(invariant_units_txt |
---|
548 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
549 | iy += 1 |
---|
550 | ix = 0 |
---|
551 | sizer_output.Add(invariant_total_txt,(iy, ix),(1,1), |
---|
552 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
553 | ix += 1 |
---|
554 | sizer_output.Add(self.invariant_total_ctl,(iy, ix),(1,1), |
---|
555 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
556 | ix += 1 |
---|
557 | sizer_output.Add( wx.StaticText(self, -1, uncertainty), |
---|
558 | (iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
559 | ix +=1 |
---|
560 | sizer_output.Add(self.invariant_total_err_ctl |
---|
561 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
562 | ix +=1 |
---|
563 | sizer_output.Add(invariant_total_units_txt,(iy, ix), |
---|
564 | (1,1),wx.RIGHT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
565 | iy += 1 |
---|
566 | ix = 0 |
---|
567 | sizer_output.Add(volume_txt,(iy, ix),(1,1), |
---|
568 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
569 | ix +=1 |
---|
570 | sizer_output.Add(self.volume_ctl,(iy, ix),(1,1), |
---|
571 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
572 | ix +=1 |
---|
573 | sizer_output.Add(wx.StaticText(self, -1, uncertainty) |
---|
574 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
575 | ix += 1 |
---|
576 | sizer_output.Add(self.volume_err_ctl |
---|
577 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
578 | ix += 1 |
---|
579 | sizer_output.Add(volume_units_txt |
---|
580 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
581 | iy += 1 |
---|
582 | ix = 0 |
---|
583 | sizer_output.Add(surface_txt,(iy, ix),(1,1), |
---|
584 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
585 | ix +=1 |
---|
586 | sizer_output.Add(self.surface_ctl,(iy, ix),(1,1), |
---|
587 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
588 | ix +=1 |
---|
589 | sizer_output.Add(wx.StaticText(self, -1, uncertainty) |
---|
590 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
591 | ix += 1 |
---|
592 | sizer_output.Add(self.surface_err_ctl |
---|
593 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
594 | ix +=1 |
---|
595 | sizer_output.Add(surface_units_txt |
---|
596 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
597 | |
---|
598 | outputbox = wx.StaticBox(self, -1, "Output") |
---|
599 | boxsizer2 = wx.StaticBoxSizer(outputbox, wx.VERTICAL) |
---|
600 | boxsizer2.SetMinSize((_STATICBOX_WIDTH,-1)) |
---|
601 | boxsizer2.Add( sizer_output ) |
---|
602 | sizer2.Add(boxsizer2,0, wx.EXPAND|wx.ALL, 10) |
---|
603 | #-----Button sizer------------ |
---|
604 | id = wx.NewId() |
---|
605 | button_calculate = wx.Button(self, id, "Compute") |
---|
606 | button_calculate.SetToolTipString("Compute invariant") |
---|
607 | self.Bind(wx.EVT_BUTTON, self.compute_invariant, id = id) |
---|
608 | |
---|
609 | sizer_button.Add((250, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
610 | sizer_button.Add(button_calculate, 0, wx.RIGHT|wx.ADJUST_MINSIZE,20) |
---|
611 | sizer3.Add(sizer_button) |
---|
612 | #---------layout---------------- |
---|
613 | |
---|
614 | vbox.Add(sizer1) |
---|
615 | vbox.Add(sizer2) |
---|
616 | vbox.Add(sizer3) |
---|
617 | vbox.Fit(self) |
---|
618 | self.SetSizer(vbox) |
---|
619 | |
---|
620 | class InvariantDialog(wx.Dialog): |
---|
621 | def __init__(self, parent=None, id=1,graph=None, |
---|
622 | data=None, title="Invariant",base=None): |
---|
623 | wx.Dialog.__init__(self, parent, id, title, size=(PANEL_WIDTH, |
---|
624 | PANEL_HEIGHT)) |
---|
625 | self.panel = InvariantPanel(self) |
---|
626 | self.Centre() |
---|
627 | self.Show(True) |
---|
628 | |
---|
629 | class InvariantWindow(wx.Frame): |
---|
630 | def __init__(self, parent=None, id=1,graph=None, |
---|
631 | data=None, title="Invariant",base=None): |
---|
632 | |
---|
633 | wx.Frame.__init__(self, parent, id, title, size=(PANEL_WIDTH, |
---|
634 | PANEL_HEIGHT)) |
---|
635 | |
---|
636 | self.panel = InvariantPanel(self) |
---|
637 | self.Centre() |
---|
638 | self.Show(True) |
---|
639 | |
---|
640 | class MyApp(wx.App): |
---|
641 | def OnInit(self): |
---|
642 | wx.InitAllImageHandlers() |
---|
643 | frame = InvariantWindow() |
---|
644 | frame.Show(True) |
---|
645 | self.SetTopWindow(frame) |
---|
646 | |
---|
647 | return True |
---|
648 | |
---|
649 | # end of class MyApp |
---|
650 | |
---|
651 | if __name__ == "__main__": |
---|
652 | app = MyApp(0) |
---|
653 | app.MainLoop() |
---|