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