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