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