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