1 | |
---|
2 | import wx |
---|
3 | import wx.lib.newevent |
---|
4 | import numpy |
---|
5 | import copy |
---|
6 | import math |
---|
7 | from sans.models.dispersion_models import ArrayDispersion, GaussianDispersion |
---|
8 | |
---|
9 | from sans.guicomm.events import StatusEvent |
---|
10 | from sans.guiframe.utils import format_number |
---|
11 | (ModelEventbox, EVT_MODEL_BOX) = wx.lib.newevent.NewEvent() |
---|
12 | _BOX_WIDTH = 80 |
---|
13 | |
---|
14 | import basepage |
---|
15 | from basepage import BasicPage |
---|
16 | |
---|
17 | |
---|
18 | class ModelPage(BasicPage): |
---|
19 | """ |
---|
20 | FitPanel class contains fields allowing to display results when |
---|
21 | fitting a model and one data |
---|
22 | @note: For Fit to be performed the user should check at least one parameter |
---|
23 | on fit Panel window. |
---|
24 | |
---|
25 | """ |
---|
26 | |
---|
27 | def __init__(self,parent, page_info): |
---|
28 | BasicPage.__init__(self, parent, page_info) |
---|
29 | """ |
---|
30 | Initialization of the Panel |
---|
31 | """ |
---|
32 | self._fill_model_sizer( self.sizer1) |
---|
33 | self._fill_range_sizer() |
---|
34 | |
---|
35 | description="" |
---|
36 | if self.model!=None: |
---|
37 | description = self.model.description |
---|
38 | |
---|
39 | self.select_model(self.model, self.model.name) |
---|
40 | self.set_model_description(description,self.sizer2) |
---|
41 | |
---|
42 | |
---|
43 | |
---|
44 | |
---|
45 | def _on_display_description(self, event): |
---|
46 | """ |
---|
47 | Show or Hide description |
---|
48 | @param event: wx.EVT_RADIOBUTTON |
---|
49 | """ |
---|
50 | self._on_display_description_helper() |
---|
51 | |
---|
52 | self.SetScrollbars(20,20,200,100) |
---|
53 | self.Refresh() |
---|
54 | |
---|
55 | |
---|
56 | |
---|
57 | def _on_display_description_helper(self): |
---|
58 | """ |
---|
59 | Show or Hide description |
---|
60 | @param event: wx.EVT_RADIOBUTTON |
---|
61 | """ |
---|
62 | |
---|
63 | ## Show description |
---|
64 | if self.description_hide.GetValue(): |
---|
65 | self.sizer_description.Clear(True) |
---|
66 | |
---|
67 | else: |
---|
68 | description="" |
---|
69 | if self.model!=None: |
---|
70 | description = self.model.description |
---|
71 | |
---|
72 | self.description = wx.StaticText( self,-1,str(description) ) |
---|
73 | self.sizer_description.Add( self.description, 1, wx.EXPAND | wx.ALL, 10 ) |
---|
74 | |
---|
75 | self.Layout() |
---|
76 | |
---|
77 | |
---|
78 | def _fill_range_sizer(self): |
---|
79 | """ |
---|
80 | Fill the sizer containing the plotting range |
---|
81 | add access to npts |
---|
82 | """ |
---|
83 | sizer_npts= wx.GridSizer(1, 1,5, 5) |
---|
84 | |
---|
85 | self.npts = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20)) |
---|
86 | self.npts.SetValue(format_number(self.num_points)) |
---|
87 | self.npts.SetToolTipString("Number of point to plot.") |
---|
88 | self.npts.Bind(wx.EVT_SET_FOCUS, self.onSetFocus) |
---|
89 | self.npts.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
90 | self.npts.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter) |
---|
91 | |
---|
92 | sizer_npts.Add(wx.StaticText(self, -1, 'Npts'),1, wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) |
---|
93 | sizer_npts.Add(self.npts,1, wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) |
---|
94 | self._set_range_sizer( title="Plotted Q Range", object= sizer_npts) |
---|
95 | |
---|
96 | |
---|
97 | def _on_select_model(self, event): |
---|
98 | """ |
---|
99 | call back for model selection |
---|
100 | """ |
---|
101 | self._on_select_model_helper() |
---|
102 | self.select_model(self.model, self.model.name) |
---|
103 | |
---|
104 | |
---|
105 | def _fill_model_sizer(self, sizer): |
---|
106 | """ |
---|
107 | fill sizer containing model info |
---|
108 | """ |
---|
109 | id = wx.NewId() |
---|
110 | self.model_view =wx.Button(self,id,'View 2D') |
---|
111 | self.model_view.Bind(wx.EVT_BUTTON, self._onModel2D,id=id) |
---|
112 | self.model_view.SetToolTipString("View model in 2D") |
---|
113 | |
---|
114 | ## class base method to add view 2d button |
---|
115 | self._set_model_sizer(sizer=sizer, title="Model",object= self.model_view ) |
---|
116 | |
---|
117 | |
---|
118 | def _set_sizer_gaussian(self): |
---|
119 | """ |
---|
120 | draw sizer with gaussian dispersity parameters |
---|
121 | """ |
---|
122 | self.fittable_param=[] |
---|
123 | self.fixed_param=[] |
---|
124 | self.orientation_params_disp=[] |
---|
125 | |
---|
126 | self.sizer4_4.Clear(True) |
---|
127 | if self.model==None: |
---|
128 | ##no model is selected |
---|
129 | return |
---|
130 | if not self.enable_disp.GetValue(): |
---|
131 | ## the user didn't select dispersity display |
---|
132 | return |
---|
133 | self._reset_dispersity() |
---|
134 | # Create the dispersion objects |
---|
135 | for item in self.model.dispersion.keys(): |
---|
136 | disp_model = GaussianDispersion() |
---|
137 | self._disp_obj_dict[item] = disp_model |
---|
138 | self.model.set_dispersion(item, disp_model) |
---|
139 | ix=0 |
---|
140 | iy=1 |
---|
141 | disp = wx.StaticText(self, -1, 'Names') |
---|
142 | self.sizer4_4.Add(disp,( iy, ix),(1,1), |
---|
143 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
144 | ix += 1 |
---|
145 | values = wx.StaticText(self, -1, 'Values') |
---|
146 | self.sizer4_4.Add(values,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
147 | |
---|
148 | ix += 1 |
---|
149 | npts = wx.StaticText(self, -1, 'Npts') |
---|
150 | self.sizer4_4.Add(npts,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
151 | ix += 1 |
---|
152 | nsigmas = wx.StaticText(self, -1, 'Nsigmas') |
---|
153 | self.sizer4_4.Add(nsigmas,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
154 | |
---|
155 | for item in self.model.dispersion.keys(): |
---|
156 | if not item in self.model.orientation_params: |
---|
157 | self.disp_cb_dict[item]= None |
---|
158 | name1=item+".width" |
---|
159 | name2=item+".npts" |
---|
160 | name3=item+".nsigmas" |
---|
161 | iy += 1 |
---|
162 | for p in self.model.dispersion[item].keys(): |
---|
163 | if p=="width": |
---|
164 | ix = 0 |
---|
165 | name = wx.StaticText(self, -1, name1) |
---|
166 | self.sizer4_4.Add( name,( iy, ix),(1,1), |
---|
167 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
168 | ix = 1 |
---|
169 | value= self.model.getParam(name1) |
---|
170 | ctl1 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
171 | style=wx.TE_PROCESS_ENTER) |
---|
172 | ctl1.SetValue(str (format_number(value))) |
---|
173 | ctl1.Bind(wx.EVT_SET_FOCUS, self.onSetFocus) |
---|
174 | ctl1.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
175 | ctl1.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) |
---|
176 | self.sizer4_4.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
177 | self.fittable_param.append([None,name1,ctl1,None, |
---|
178 | None, None, None,None]) |
---|
179 | elif p=="npts": |
---|
180 | ix =2 |
---|
181 | value= self.model.getParam(name2) |
---|
182 | Tctl1 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/2,20), |
---|
183 | style=wx.TE_PROCESS_ENTER) |
---|
184 | Tctl1.SetValue(str (format_number(value))) |
---|
185 | Tctl1.Bind(wx.EVT_SET_FOCUS, self.onSetFocus) |
---|
186 | Tctl1.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
187 | Tctl1.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) |
---|
188 | self.sizer4_4.Add(Tctl1, (iy,ix),(1,1), |
---|
189 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
190 | self.fixed_param.append([None,name2, Tctl1,None,None, |
---|
191 | None, None,None]) |
---|
192 | elif p=="nsigmas": |
---|
193 | ix =3 |
---|
194 | value= self.model.getParam(name3) |
---|
195 | Tctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/2,20), |
---|
196 | style=wx.TE_PROCESS_ENTER) |
---|
197 | Tctl2.SetValue(str (format_number(value))) |
---|
198 | Tctl2.Bind(wx.EVT_SET_FOCUS, self.onSetFocus) |
---|
199 | Tctl2.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
200 | Tctl2.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) |
---|
201 | self.sizer4_4.Add(Tctl2, (iy,ix),(1,1), |
---|
202 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
203 | ix +=1 |
---|
204 | self.sizer4_4.Add((20,20), (iy,ix),(1,1), |
---|
205 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
206 | self.fixed_param.append([None,name3, Tctl2, |
---|
207 | None,None, None, None,None]) |
---|
208 | for item in self.model.dispersion.keys(): |
---|
209 | if item in self.model.orientation_params: |
---|
210 | self.disp_cb_dict[item]= None |
---|
211 | name1=item+".width" |
---|
212 | name2=item+".npts" |
---|
213 | name3=item+".nsigmas" |
---|
214 | iy += 1 |
---|
215 | for p in self.model.dispersion[item].keys(): |
---|
216 | if p=="width": |
---|
217 | ix = 0 |
---|
218 | name = wx.StaticText(self, -1, name1) |
---|
219 | self.sizer4_4.Add( name,( iy, ix),(1,1), |
---|
220 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
221 | ix = 1 |
---|
222 | value= self.model.getParam(name1) |
---|
223 | ctl1 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
224 | style=wx.TE_PROCESS_ENTER) |
---|
225 | ctl1.SetValue(str (format_number(value))) |
---|
226 | ctl1.Bind(wx.EVT_SET_FOCUS, self.onSetFocus) |
---|
227 | ctl1.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
228 | ctl1.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) |
---|
229 | ctl1.Disable() |
---|
230 | self.sizer4_4.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
231 | self.fittable_param.append([None,name1,ctl1,None, |
---|
232 | None, None, None,None]) |
---|
233 | self.orientation_params_disp.append([None,name1,ctl1,None, |
---|
234 | None, None, None,None]) |
---|
235 | elif p=="npts": |
---|
236 | ix =2 |
---|
237 | value= self.model.getParam(name2) |
---|
238 | Tctl1 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/2,20), |
---|
239 | style=wx.TE_PROCESS_ENTER) |
---|
240 | Tctl1.SetValue(str (format_number(value))) |
---|
241 | Tctl1.Bind(wx.EVT_SET_FOCUS, self.onSetFocus) |
---|
242 | Tctl1.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
243 | Tctl1.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) |
---|
244 | Tctl1.Disable() |
---|
245 | self.sizer4_4.Add(Tctl1, (iy,ix),(1,1), |
---|
246 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
247 | self.fixed_param.append([None,name2, Tctl1,None,None, |
---|
248 | None, None,None]) |
---|
249 | self.orientation_params_disp.append([None,name2, Tctl1,None,None, |
---|
250 | None, None,None]) |
---|
251 | elif p=="nsigmas": |
---|
252 | ix =3 |
---|
253 | value= self.model.getParam(name3) |
---|
254 | Tctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/2,20), |
---|
255 | style=wx.TE_PROCESS_ENTER) |
---|
256 | Tctl2.SetValue(str (format_number(value))) |
---|
257 | Tctl2.Bind(wx.EVT_SET_FOCUS, self.onSetFocus) |
---|
258 | Tctl2.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
259 | Tctl2.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) |
---|
260 | Tctl2.Disable() |
---|
261 | self.sizer4_4.Add(Tctl2, (iy,ix),(1,1), |
---|
262 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
263 | ix +=1 |
---|
264 | self.sizer4_4.Add((20,20), (iy,ix),(1,1), |
---|
265 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
266 | self.fixed_param.append([None,name3, Tctl2, |
---|
267 | None,None, None, None,None]) |
---|
268 | self.orientation_params_disp.append([None,name3, Tctl2, |
---|
269 | None,None, None, None,None]) |
---|
270 | |
---|
271 | msg = " Selected Distribution: Gaussian" |
---|
272 | wx.PostEvent(self.parent.parent, StatusEvent( status= msg )) |
---|
273 | ix =0 |
---|
274 | iy +=1 |
---|
275 | self.sizer4_4.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
276 | self.sizer4_4.Layout() |
---|
277 | self.sizer4.Layout() |
---|
278 | self.SetScrollbars(20,20,200,100) |
---|
279 | |
---|
280 | |
---|
281 | def _onModel2D(self, event): |
---|
282 | """ |
---|
283 | call manager to plot model in 2D |
---|
284 | """ |
---|
285 | # If the 2D display is not currently enabled, plot the model in 2D |
---|
286 | # and set the enable2D flag. |
---|
287 | if self.fitrange: |
---|
288 | self.enable2D = True |
---|
289 | |
---|
290 | if self.enable2D: |
---|
291 | self._draw_model() |
---|
292 | self.model_view.Disable() |
---|
293 | |
---|
294 | if len(self.orientation_params)>0: |
---|
295 | for item in self.orientation_params: |
---|
296 | if item[2]!=None: |
---|
297 | item[2].Enable() |
---|
298 | if len(self.orientation_params_disp)>0: |
---|
299 | for item in self.orientation_params_disp: |
---|
300 | if item[2]!=None: |
---|
301 | item[2].Enable() |
---|
302 | |
---|
303 | |
---|
304 | |
---|
305 | def reset_page(self, state): |
---|
306 | """ |
---|
307 | reset the state |
---|
308 | """ |
---|
309 | self.reset_page_helper(state) |
---|
310 | |
---|
311 | |
---|
312 | def select_model(self, model, name): |
---|
313 | """ |
---|
314 | Select a new model |
---|
315 | @param model: model object |
---|
316 | """ |
---|
317 | self.model = model |
---|
318 | self.set_model_param_sizer(self.model) |
---|
319 | self._draw_model() |
---|
320 | ## keep the sizer view consistent with the model menu selecting |
---|
321 | self._set_model_sizer_selection( self.model ) |
---|
322 | self.enable_disp.SetValue(False) |
---|
323 | self.disable_disp.SetValue(True) |
---|
324 | self._set_dipers_Param(event=None) |
---|
325 | self.model_view.SetFocus() |
---|
326 | |
---|
327 | |
---|
328 | def set_model_description(self,description,sizer): |
---|
329 | """ |
---|
330 | fill a sizer with description |
---|
331 | @param description: of type string |
---|
332 | @param sizer: wx.BoxSizer() |
---|
333 | """ |
---|
334 | |
---|
335 | sizer.Clear(True) |
---|
336 | box_description= wx.StaticBox(self, -1, 'Model Description') |
---|
337 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
338 | |
---|
339 | sizer_selection=wx.BoxSizer(wx.HORIZONTAL) |
---|
340 | |
---|
341 | self.description_hide = wx.RadioButton(self, -1, 'Hide', style=wx.RB_GROUP) |
---|
342 | self.description_show = wx.RadioButton(self, -1, 'Show') |
---|
343 | |
---|
344 | |
---|
345 | if description=="": |
---|
346 | self.description_hide.SetValue(True) |
---|
347 | description=" Description unavailable. Click for details" |
---|
348 | |
---|
349 | self.description = wx.StaticText( self,-1,str(description) ) |
---|
350 | |
---|
351 | self.Bind( wx.EVT_RADIOBUTTON, self._on_display_description, |
---|
352 | id=self.description_hide.GetId() ) |
---|
353 | |
---|
354 | self.Bind( wx.EVT_RADIOBUTTON, self._on_display_description, |
---|
355 | id=self.description_show.GetId() ) |
---|
356 | |
---|
357 | self.model_description = wx.Button(self,-1, label="Details") |
---|
358 | self.model_description.Bind(wx.EVT_BUTTON,self.on_button_clicked) |
---|
359 | self.model_description.SetToolTipString("Click Model Functions in HelpWindow...") |
---|
360 | |
---|
361 | sizer_selection.Add( self.description_show ) |
---|
362 | sizer_selection.Add( (20,20)) |
---|
363 | sizer_selection.Add( self.description_hide ) |
---|
364 | #sizer_selection.Add( (20,20)) |
---|
365 | sizer_selection.Add((20,20),0, wx.LEFT|wx.RIGHT|wx.EXPAND,67) |
---|
366 | sizer_selection.Add( self.model_description ) |
---|
367 | |
---|
368 | |
---|
369 | self.sizer_description=wx.BoxSizer(wx.HORIZONTAL) |
---|
370 | self.sizer_description.Add( self.description, 1, wx.EXPAND | wx.ALL, 10 ) |
---|
371 | boxsizer1.Add( sizer_selection) |
---|
372 | boxsizer1.Add( (20,20)) |
---|
373 | boxsizer1.Add( self.sizer_description) |
---|
374 | |
---|
375 | self._on_display_description(event=None) |
---|
376 | sizer.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
377 | sizer.Layout() |
---|
378 | |
---|
379 | def on_button_clicked(self,event): |
---|
380 | """ |
---|
381 | #On 'More details' button |
---|
382 | """ |
---|
383 | from helpPanel import HelpWindow |
---|
384 | |
---|
385 | name = self.model.name |
---|
386 | if name == None: |
---|
387 | name = 'FuncHelp' |
---|
388 | frame = HelpWindow(None, -1, name) |
---|
389 | frame.Show(True) |
---|
390 | |
---|
391 | def set_range(self, qmin_x, qmax_x, npts): |
---|
392 | """ |
---|
393 | Set the range for the plotted models |
---|
394 | @param qmin: minimum Q |
---|
395 | @param qmax: maximum Q |
---|
396 | @param npts: number of Q bins |
---|
397 | """ |
---|
398 | # Set the data members |
---|
399 | self.qmin_x = qmin_x |
---|
400 | self.qmax_x = qmax_x |
---|
401 | self.num_points = npts |
---|
402 | |
---|
403 | # Set the controls |
---|
404 | #For qmin and qmax, do not use format_number.(If do, qmin and max could be different from what is in the data.) |
---|
405 | """ |
---|
406 | self.qmin.SetValue(format_number(self.qmin_x)) |
---|
407 | self.qmax.SetValue(format_number(self.qmax_x)) |
---|
408 | self.npts.SetValue(format_number(self.num_points)) |
---|
409 | """ |
---|
410 | self.qmin.SetValue(str(self.qmin_x)) |
---|
411 | self.qmax.SetValue(str(self.qmax_x)) |
---|
412 | self.npts.SetValue(format_number(self.num_points)) |
---|
413 | |
---|
414 | |
---|
415 | def set_model_param_sizer(self, model): |
---|
416 | """ |
---|
417 | Build the panel from the model content |
---|
418 | @param model: the model selected in combo box for fitting purpose |
---|
419 | """ |
---|
420 | self.sizer3.Clear(True) |
---|
421 | self.parameters = [] |
---|
422 | self.param_toFit=[] |
---|
423 | self.fixed_param=[] |
---|
424 | self.orientation_params=[] |
---|
425 | self.orientation_params_disp=[] |
---|
426 | if model ==None: |
---|
427 | ##no model avaiable to draw sizer |
---|
428 | return |
---|
429 | box_description= wx.StaticBox(self, -1,str("Model Parameters")) |
---|
430 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
431 | sizer = wx.GridBagSizer(5,5) |
---|
432 | |
---|
433 | self.model = model |
---|
434 | self.set_model_description(self.model.description,self.sizer2) |
---|
435 | |
---|
436 | keys = self.model.getParamList() |
---|
437 | ##list of dispersion parameters |
---|
438 | self.disp_list=self.model.getDispParamList() |
---|
439 | |
---|
440 | keys.sort() |
---|
441 | |
---|
442 | iy = 1 |
---|
443 | ix = 0 |
---|
444 | self.text1_2 = wx.StaticText(self, -1, 'Names') |
---|
445 | sizer.Add(self.text1_2,(iy, ix),(1,1),\ |
---|
446 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
447 | ix +=1 |
---|
448 | self.text2_4 = wx.StaticText(self, -1, '[Units]') |
---|
449 | sizer.Add(self.text2_4,(iy, ix),(1,1),\ |
---|
450 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
451 | #self.text2_4.Hide() |
---|
452 | ix +=1 |
---|
453 | self.text2_2 = wx.StaticText(self, -1, 'Values') |
---|
454 | sizer.Add(self.text2_2,(iy, ix),(1,1),\ |
---|
455 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
456 | |
---|
457 | for item in keys: |
---|
458 | if not item in self.disp_list and not item in self.model.orientation_params: |
---|
459 | iy += 1 |
---|
460 | ix = 0 |
---|
461 | name = wx.StaticText(self, -1,item) |
---|
462 | sizer.Add( name,( iy, ix),(1,1), |
---|
463 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
464 | ix +=1 |
---|
465 | # Units |
---|
466 | try: |
---|
467 | units = wx.StaticText(self, -1, self.model.details[item][0], style=wx.ALIGN_LEFT) |
---|
468 | except: |
---|
469 | units = wx.StaticText(self, -1, "", style=wx.ALIGN_LEFT) |
---|
470 | sizer.Add(units, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
471 | |
---|
472 | ix += 1 |
---|
473 | value= self.model.getParam(item) |
---|
474 | ctl1 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
475 | style=wx.TE_PROCESS_ENTER) |
---|
476 | |
---|
477 | ctl1.SetValue(str (format_number(value))) |
---|
478 | ctl1.Bind(wx.EVT_SET_FOCUS, self.onSetFocus) |
---|
479 | ctl1.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
480 | ctl1.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) |
---|
481 | |
---|
482 | sizer.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
483 | ##[cb state, name, value, "+/-", error of fit, min, max , units] |
---|
484 | self.parameters.append([None,item, ctl1, |
---|
485 | None,None, None, None,None]) |
---|
486 | iy+=1 |
---|
487 | sizer.Add((10,10),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
488 | for item in self.model.orientation_params: |
---|
489 | if not item in self.disp_list : |
---|
490 | iy += 1 |
---|
491 | ix = 0 |
---|
492 | name = wx.StaticText(self, -1,item) |
---|
493 | sizer.Add( name,( iy, ix),(1,1), |
---|
494 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
495 | ix +=1 |
---|
496 | # Units |
---|
497 | try: |
---|
498 | units = wx.StaticText(self, -1, self.model.details[item][0], style=wx.ALIGN_LEFT) |
---|
499 | except: |
---|
500 | units = wx.StaticText(self, -1, "", style=wx.ALIGN_LEFT) |
---|
501 | sizer.Add(units, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
502 | |
---|
503 | ix += 1 |
---|
504 | value= self.model.getParam(item) |
---|
505 | ctl1 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
506 | style=wx.TE_PROCESS_ENTER) |
---|
507 | |
---|
508 | ctl1.SetValue(str (format_number(value))) |
---|
509 | ctl1.Disable() |
---|
510 | ctl1.Bind(wx.EVT_SET_FOCUS, self.onSetFocus) |
---|
511 | ctl1.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
512 | ctl1.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) |
---|
513 | |
---|
514 | sizer.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
515 | |
---|
516 | ##[cb state, name, value, "+/-", error of fit, min, max , units] |
---|
517 | self.parameters.append([None,item, ctl1, |
---|
518 | None,None, None, None,None]) |
---|
519 | self.orientation_params.append([None,item, ctl1, |
---|
520 | None,None, None, None,None]) |
---|
521 | |
---|
522 | iy+=1 |
---|
523 | sizer.Add((10,10),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
524 | |
---|
525 | #Display units text on panel |
---|
526 | for item in keys: |
---|
527 | if self.model.details[item][0]!='': |
---|
528 | self.text2_4.Show() |
---|
529 | break |
---|
530 | else: |
---|
531 | self.text2_4.Hide() |
---|
532 | |
---|
533 | boxsizer1.Add(sizer) |
---|
534 | self.sizer3.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
535 | self.sizer3.Layout() |
---|
536 | self.SetScrollbars(20,20,200,100) |
---|
537 | |
---|
538 | |
---|
539 | |
---|
540 | |
---|
541 | class HelpWindow(wx.Frame): |
---|
542 | def __init__(self, parent, id, title): |
---|
543 | wx.Frame.__init__(self, parent, id, title, size=(570, 400)) |
---|
544 | |
---|
545 | from sans.models.CylinderModel import CylinderModel |
---|
546 | model = CylinderModel() |
---|
547 | #from sans.models.LineModel import LineModel |
---|
548 | #model = LineModel() |
---|
549 | from fitpanel import PageInfo |
---|
550 | myinfo = PageInfo(self,model) |
---|
551 | from models import ModelList |
---|
552 | mylist= ModelList() |
---|
553 | |
---|
554 | from sans.models.SphereModel import SphereModel |
---|
555 | from sans.models.SquareWellStructure import SquareWellStructure |
---|
556 | from sans.models.DebyeModel import DebyeModel |
---|
557 | from sans.models.LineModel import LineModel |
---|
558 | name= "shapes" |
---|
559 | list1= [SphereModel] |
---|
560 | mylist.set_list( name, list1) |
---|
561 | |
---|
562 | name= "Shape-independent" |
---|
563 | list1= [DebyeModel] |
---|
564 | mylist.set_list( name, list1) |
---|
565 | |
---|
566 | name= "Structure Factors" |
---|
567 | list1= [SquareWellStructure] |
---|
568 | mylist.set_list( name, list1) |
---|
569 | |
---|
570 | name= "Added models" |
---|
571 | list1= [LineModel] |
---|
572 | mylist.set_list( name, list1) |
---|
573 | |
---|
574 | myinfo.model_list_box = mylist.get_list() |
---|
575 | |
---|
576 | self.page = ModelPage(self, myinfo) |
---|
577 | |
---|
578 | |
---|
579 | |
---|
580 | self.Centre() |
---|
581 | self.Show(True) |
---|
582 | |
---|
583 | |
---|
584 | |
---|
585 | if __name__=="__main__": |
---|
586 | app = wx.App() |
---|
587 | HelpWindow(None, -1, 'HelpWindow') |
---|
588 | app.MainLoop() |
---|
589 | |
---|