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