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