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 StatusEvent |
---|
11 | |
---|
12 | |
---|
13 | _BOX_WIDTH = 76 |
---|
14 | _STATICBOX_WIDTH = 350 |
---|
15 | _SCALE = 1e-6 |
---|
16 | |
---|
17 | #SLD panel size |
---|
18 | if sys.platform.count("win32")>0: |
---|
19 | _STATICBOX_WIDTH = 350 |
---|
20 | PANEL_WIDTH = 500 |
---|
21 | PANEL_HEIGHT = 600 |
---|
22 | FONT_VARIANT = 0 |
---|
23 | else: |
---|
24 | _STATICBOX_WIDTH = 380 |
---|
25 | PANEL_WIDTH = 530 |
---|
26 | PANEL_HEIGHT = 600 |
---|
27 | FONT_VARIANT = 1 |
---|
28 | |
---|
29 | class InvariantPanel(wx.Panel): |
---|
30 | """ |
---|
31 | Provides the SLD calculator GUI. |
---|
32 | """ |
---|
33 | ## Internal nickname for the window, used by the AUI manager |
---|
34 | window_name = "SLD Calculator" |
---|
35 | ## Name to appear on the window title bar |
---|
36 | window_caption = "SLD Calculator" |
---|
37 | ## Flag to tell the AUI manager to put this panel in the center pane |
---|
38 | CENTER_PANE = True |
---|
39 | def __init__(self, parent, base=None): |
---|
40 | wx.Panel.__init__(self, parent) |
---|
41 | #Font size |
---|
42 | self.SetWindowVariant(variant=FONT_VARIANT) |
---|
43 | #Object that receive status event |
---|
44 | self.base = base |
---|
45 | self._do_layout() |
---|
46 | self.SetAutoLayout(True) |
---|
47 | self.Layout() |
---|
48 | |
---|
49 | def _do_layout(self): |
---|
50 | """ |
---|
51 | Draw window content |
---|
52 | """ |
---|
53 | unit_invariant = '[1/cm][1/A]' |
---|
54 | unit_volume = '' |
---|
55 | unit_surface = '' |
---|
56 | uncertainty = "+/-" |
---|
57 | sizer_input = wx.GridBagSizer(5,5) |
---|
58 | sizer_output = wx.GridBagSizer(5,5) |
---|
59 | sizer_button = wx.BoxSizer(wx.HORIZONTAL) |
---|
60 | sizer1 = wx.BoxSizer(wx.HORIZONTAL) |
---|
61 | sizer2 = wx.BoxSizer(wx.HORIZONTAL) |
---|
62 | sizer3 = wx.BoxSizer(wx.HORIZONTAL) |
---|
63 | |
---|
64 | #---------inputs---------------- |
---|
65 | background_txt = wx.StaticText(self, -1, 'Background') |
---|
66 | self.background_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
67 | self.background_ctl.SetToolTipString("Background to subtract to data.") |
---|
68 | scale_txt = wx.StaticText(self, -1, 'Scale') |
---|
69 | self.scale_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
70 | self.scale_ctl.SetToolTipString("Scale to apply to data.") |
---|
71 | contrast_txt = wx.StaticText(self, -1, 'Contrast') |
---|
72 | self.contrast_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
73 | self.contrast_ctl.SetToolTipString("Contrast in q range.") |
---|
74 | porod_const_txt = wx.StaticText(self, -1, 'Porod Constant') |
---|
75 | self.porod_const_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
76 | self.porod_const_ctl.SetToolTipString("Invariant in q range.") |
---|
77 | |
---|
78 | iy = 0 |
---|
79 | ix = 0 |
---|
80 | sizer_input.Add(background_txt,(iy, ix),(1,1),\ |
---|
81 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
82 | ix +=1 |
---|
83 | sizer_input.Add(self.background_ctl,(iy, ix),(1,1),\ |
---|
84 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
85 | iy += 1 |
---|
86 | ix = 0 |
---|
87 | sizer_input.Add(scale_txt,(iy, ix),(1,1),\ |
---|
88 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
89 | ix += 1 |
---|
90 | sizer_input.Add(self.scale_ctl, (iy, ix), (1,1),\ |
---|
91 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
92 | iy += 1 |
---|
93 | ix = 0 |
---|
94 | sizer_input.Add(contrast_txt, (iy, ix),(1,1),\ |
---|
95 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
96 | ix += 1 |
---|
97 | sizer_input.Add(self.contrast_ctl,(iy, ix),(1,1),\ |
---|
98 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
99 | iy += 1 |
---|
100 | ix = 0 |
---|
101 | sizer_input.Add(porod_const_txt, (iy, ix),(1,1),\ |
---|
102 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
103 | ix += 1 |
---|
104 | sizer_input.Add(self.porod_const_ctl,(iy, ix),(1,1),\ |
---|
105 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
106 | |
---|
107 | sizer_low_q = wx.GridBagSizer(5,5) |
---|
108 | self.guinier = wx.RadioButton(self, -1, 'Guinier', |
---|
109 | (10, 10), style=wx.RB_GROUP) |
---|
110 | self.power_law_low = wx.RadioButton(self, -1, 'Power_law', (10, 10)) |
---|
111 | #self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, |
---|
112 | # id=self.guinier.GetId()) |
---|
113 | #self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, |
---|
114 | # id=self.power_law_law.GetId()) |
---|
115 | #MAC needs SetValue |
---|
116 | self.guinier.SetValue(True) |
---|
117 | power_low_txt = wx.StaticText(self, -1, 'Power') |
---|
118 | self.power_low_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
119 | self.power_low_ctl.SetToolTipString("Power to apply to the\ |
---|
120 | Power_law function.") |
---|
121 | iy = 0 |
---|
122 | ix = 0 |
---|
123 | sizer_low_q.Add(self.power_law_low,(iy, ix),(1,1), |
---|
124 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
125 | iy += 1 |
---|
126 | ix = 0 |
---|
127 | sizer_low_q.Add(power_low_txt,(iy, ix),(1,1), |
---|
128 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
129 | ix += 1 |
---|
130 | sizer_low_q.Add(self.power_low_ctl, (iy, ix), (1,1), |
---|
131 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
132 | iy += 1 |
---|
133 | ix = 0 |
---|
134 | sizer_low_q.Add(self.guinier,(iy, ix),(1,1), |
---|
135 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
136 | |
---|
137 | sizer_high_q = wx.GridBagSizer(5,5) |
---|
138 | self.power_law_high = wx.RadioButton(self, -1, 'Power_law', (10, 10)) |
---|
139 | #self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, |
---|
140 | # id=self.power_law_high.GetId()) |
---|
141 | #MAC needs SetValue |
---|
142 | self.power_law_high.SetValue(True) |
---|
143 | power_high_txt = wx.StaticText(self, -1, 'Power') |
---|
144 | self.power_high_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
145 | self.power_high_ctl.SetToolTipString("Power to apply to the\ |
---|
146 | Power_law function.") |
---|
147 | iy = 0 |
---|
148 | ix = 0 |
---|
149 | sizer_high_q.Add(self.power_law_high,(iy, ix),(1,1), |
---|
150 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
151 | iy += 1 |
---|
152 | ix = 0 |
---|
153 | sizer_high_q.Add(power_high_txt,(iy, ix),(1,1), |
---|
154 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
155 | ix += 1 |
---|
156 | sizer_high_q.Add(self.power_high_ctl, (iy, ix), (1,1), |
---|
157 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
158 | |
---|
159 | high_q_box = wx.StaticBox(self, -1, "High Q") |
---|
160 | boxsizer_high_q = wx.StaticBoxSizer(high_q_box, wx.VERTICAL) |
---|
161 | boxsizer_high_q.Add(sizer_high_q) |
---|
162 | |
---|
163 | low_q_box = wx.StaticBox(self, -1, "Low Q") |
---|
164 | boxsizer_low_q = wx.StaticBoxSizer(low_q_box, wx.VERTICAL) |
---|
165 | boxsizer_low_q.Add(sizer_low_q) |
---|
166 | |
---|
167 | sizer_extrapolation = wx.BoxSizer(wx.HORIZONTAL) |
---|
168 | extrapolation_box = wx.StaticBox(self, -1, "Extrapolation") |
---|
169 | boxsizer_extra = wx.StaticBoxSizer(extrapolation_box, wx.HORIZONTAL) |
---|
170 | boxsizer_extra.Add(boxsizer_low_q) |
---|
171 | boxsizer_extra.Add((10,10)) |
---|
172 | boxsizer_extra.Add(boxsizer_high_q) |
---|
173 | |
---|
174 | inputbox = wx.StaticBox(self, -1, "Input") |
---|
175 | boxsizer1 = wx.StaticBoxSizer(inputbox, wx.VERTICAL) |
---|
176 | boxsizer1.SetMinSize((_STATICBOX_WIDTH,-1)) |
---|
177 | boxsizer1.Add(sizer_input) |
---|
178 | boxsizer1.Add(boxsizer_extra) |
---|
179 | |
---|
180 | sizer1.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
181 | #---------Outputs sizer-------- |
---|
182 | invariant_txt = wx.StaticText(self, -1, 'Invariant') |
---|
183 | self.invariant_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
184 | self.invariant_ctl.SetEditable(False) |
---|
185 | self.invariant_ctl.SetToolTipString("Invariant in q range.") |
---|
186 | self.invariant_err_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
187 | self.invariant_err_ctl.SetEditable(False) |
---|
188 | self.invariant_err_ctl.SetToolTipString("Uncertainty on invariant.") |
---|
189 | invariant_units_txt = wx.StaticText(self, -1, unit_invariant) |
---|
190 | |
---|
191 | invariant_total_txt = wx.StaticText(self, -1, 'Invariant Total') |
---|
192 | self.invariant_total_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
193 | self.invariant_total_ctl.SetEditable(False) |
---|
194 | self.invariant_total_ctl.SetToolTipString("Invariant in q range and extra\ |
---|
195 | polated range.") |
---|
196 | self.invariant_total_err_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
197 | self.invariant_total_err_ctl.SetEditable(False) |
---|
198 | self.invariant_total_err_ctl.SetToolTipString("Uncertainty on invariant.") |
---|
199 | invariant_total_units_txt = wx.StaticText(self, -1, unit_invariant) |
---|
200 | |
---|
201 | volume_txt = wx.StaticText(self, -1, 'Volume Fraction') |
---|
202 | self.volume_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
203 | self.volume_ctl.SetEditable(False) |
---|
204 | self.volume_ctl.SetToolTipString("volume fraction.") |
---|
205 | self.volume_err_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
206 | self.volume_err_ctl.SetEditable(False) |
---|
207 | self.volume_err_ctl.SetToolTipString("Uncertainty of volume fraction.") |
---|
208 | volume_units_txt = wx.StaticText(self, -1, unit_volume) |
---|
209 | |
---|
210 | surface_txt = wx.StaticText(self, -1, 'Surface') |
---|
211 | self.surface_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
212 | self.surface_ctl.SetEditable(False) |
---|
213 | self.surface_ctl.SetToolTipString("Surface.") |
---|
214 | self.surface_err_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
215 | self.surface_err_ctl.SetEditable(False) |
---|
216 | self.surface_err_ctl.SetToolTipString("Uncertainty of surface.") |
---|
217 | surface_units_txt = wx.StaticText(self, -1, unit_surface) |
---|
218 | |
---|
219 | invariant_low_txt = wx.StaticText(self, -1, 'Invariant in low Q') |
---|
220 | self.invariant_low_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
221 | self.invariant_low_ctl.SetEditable(False) |
---|
222 | self.invariant_low_ctl.SetToolTipString("Invariant compute in low Q") |
---|
223 | invariant_low_units_txt = wx.StaticText(self, -1, unit_invariant) |
---|
224 | |
---|
225 | invariant_high_txt = wx.StaticText(self, -1, 'Invariant in high Q') |
---|
226 | self.invariant_high_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
227 | self.invariant_high_ctl.SetEditable(False) |
---|
228 | self.invariant_high_ctl.SetToolTipString("Invariant compute in high Q") |
---|
229 | invariant_high_units_txt = wx.StaticText(self, -1, unit_invariant) |
---|
230 | |
---|
231 | iy = 0 |
---|
232 | ix = 0 |
---|
233 | sizer_output.Add(invariant_low_txt, (iy, ix), (1,1), |
---|
234 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
235 | ix +=1 |
---|
236 | sizer_output.Add(self.invariant_low_ctl, (iy, ix), (1,1), |
---|
237 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
238 | ix += 2 |
---|
239 | sizer_output.Add(invariant_low_units_txt, (iy, ix), (1,1), |
---|
240 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
241 | iy += 1 |
---|
242 | ix = 0 |
---|
243 | sizer_output.Add(invariant_high_txt, (iy, ix), (1,1), |
---|
244 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
245 | ix +=1 |
---|
246 | sizer_output.Add(self.invariant_high_ctl, (iy, ix), (1,1), |
---|
247 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
248 | ix += 2 |
---|
249 | sizer_output.Add(invariant_high_units_txt, (iy, ix), (1,1), |
---|
250 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
251 | iy += 1 |
---|
252 | ix = 0 |
---|
253 | sizer_output.Add(invariant_txt,(iy, ix),(1,1), |
---|
254 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
255 | ix += 1 |
---|
256 | sizer_output.Add(self.invariant_ctl,(iy, ix),(1,1), |
---|
257 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
258 | ix += 1 |
---|
259 | sizer_output.Add( wx.StaticText(self, -1, uncertainty), |
---|
260 | (iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
261 | ix +=1 |
---|
262 | sizer_output.Add(self.invariant_err_ctl |
---|
263 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
264 | ix +=1 |
---|
265 | sizer_output.Add(invariant_units_txt |
---|
266 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
267 | iy += 1 |
---|
268 | ix = 0 |
---|
269 | sizer_output.Add(invariant_total_txt,(iy, ix),(1,1), |
---|
270 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
271 | ix += 1 |
---|
272 | sizer_output.Add(self.invariant_total_ctl,(iy, ix),(1,1), |
---|
273 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
274 | ix += 1 |
---|
275 | sizer_output.Add( wx.StaticText(self, -1, uncertainty), |
---|
276 | (iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
277 | ix +=1 |
---|
278 | sizer_output.Add(self.invariant_total_err_ctl |
---|
279 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
280 | ix +=1 |
---|
281 | sizer_output.Add(invariant_total_units_txt |
---|
282 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
283 | iy += 1 |
---|
284 | ix = 0 |
---|
285 | sizer_output.Add(volume_txt,(iy, ix),(1,1), |
---|
286 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
287 | ix +=1 |
---|
288 | sizer_output.Add(self.volume_ctl,(iy, ix),(1,1), |
---|
289 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
290 | ix +=1 |
---|
291 | sizer_output.Add(wx.StaticText(self, -1, uncertainty) |
---|
292 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
293 | ix += 1 |
---|
294 | sizer_output.Add(self.volume_err_ctl |
---|
295 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
296 | ix += 1 |
---|
297 | sizer_output.Add(volume_units_txt |
---|
298 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
299 | iy += 1 |
---|
300 | ix = 0 |
---|
301 | sizer_output.Add(surface_txt,(iy, ix),(1,1), |
---|
302 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
303 | ix +=1 |
---|
304 | sizer_output.Add(self.surface_ctl,(iy, ix),(1,1), |
---|
305 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
306 | ix +=1 |
---|
307 | sizer_output.Add(wx.StaticText(self, -1, uncertainty) |
---|
308 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
309 | ix += 1 |
---|
310 | sizer_output.Add(self.surface_err_ctl |
---|
311 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
312 | ix +=1 |
---|
313 | sizer_output.Add(surface_units_txt |
---|
314 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
315 | |
---|
316 | outputbox = wx.StaticBox(self, -1, "Output") |
---|
317 | boxsizer2 = wx.StaticBoxSizer(outputbox, wx.VERTICAL) |
---|
318 | boxsizer2.SetMinSize((_STATICBOX_WIDTH,-1)) |
---|
319 | boxsizer2.Add( sizer_output ) |
---|
320 | sizer2.Add(boxsizer2,0, wx.EXPAND|wx.ALL, 10) |
---|
321 | #-----Button sizer------------ |
---|
322 | |
---|
323 | id = wx.NewId() |
---|
324 | button_calculate = wx.Button(self, id, "Compute") |
---|
325 | button_calculate.SetToolTipString("Compute SlD of neutrons.") |
---|
326 | self.Bind(wx.EVT_BUTTON, self.compute_invariant, id = id) |
---|
327 | |
---|
328 | sizer_button.Add((250, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
329 | sizer_button.Add(button_calculate, 0, wx.RIGHT|wx.ADJUST_MINSIZE,20) |
---|
330 | sizer3.Add(sizer_button) |
---|
331 | #---------layout---------------- |
---|
332 | vbox = wx.BoxSizer(wx.VERTICAL) |
---|
333 | vbox.Add(sizer1) |
---|
334 | vbox.Add(sizer2) |
---|
335 | vbox.Add(sizer3) |
---|
336 | vbox.Fit(self) |
---|
337 | self.SetSizer(vbox) |
---|
338 | |
---|
339 | def compute_invariant(self, event): |
---|
340 | """ |
---|
341 | compute invariant |
---|
342 | """ |
---|
343 | |
---|
344 | class InvariantDialog(wx.Dialog): |
---|
345 | def __init__(self, parent=None, id=1, title="Invariant",base=None): |
---|
346 | wx.Dialog.__init__(self, parent, id, title, size=( PANEL_WIDTH, |
---|
347 | PANEL_HEIGHT)) |
---|
348 | |
---|
349 | self.panel = InvariantPanel(self, base=base) |
---|
350 | self.Centre() |
---|
351 | self.Show(True) |
---|
352 | |
---|
353 | class MyApp(wx.App): |
---|
354 | def OnInit(self): |
---|
355 | wx.InitAllImageHandlers() |
---|
356 | |
---|
357 | dialog = InvariantDialog(None) |
---|
358 | if dialog.ShowModal() == wx.ID_OK: |
---|
359 | pass |
---|
360 | dialog.Destroy() |
---|
361 | |
---|
362 | return 1 |
---|
363 | |
---|
364 | # end of class MyApp |
---|
365 | |
---|
366 | if __name__ == "__main__": |
---|
367 | app = MyApp(0) |
---|
368 | app.MainLoop() |
---|