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 | """ |
---|
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 | self.state._disp_obj_dict[item]= disp_model |
---|
140 | |
---|
141 | |
---|
142 | ix=0 |
---|
143 | iy=1 |
---|
144 | disp = wx.StaticText(self, -1, 'Names') |
---|
145 | self.sizer4_4.Add(disp,( iy, ix),(1,1), |
---|
146 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
147 | ix += 1 |
---|
148 | values = wx.StaticText(self, -1, 'Values') |
---|
149 | self.sizer4_4.Add(values,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
150 | |
---|
151 | ix += 1 |
---|
152 | npts = wx.StaticText(self, -1, 'Npts') |
---|
153 | self.sizer4_4.Add(npts,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
154 | ix += 1 |
---|
155 | nsigmas = wx.StaticText(self, -1, 'Nsigmas') |
---|
156 | self.sizer4_4.Add(nsigmas,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
157 | |
---|
158 | for item in self.model.dispersion.keys(): |
---|
159 | if not item in self.model.orientation_params: |
---|
160 | self.disp_cb_dict[item]= None |
---|
161 | name1=item+".width" |
---|
162 | name2=item+".npts" |
---|
163 | name3=item+".nsigmas" |
---|
164 | iy += 1 |
---|
165 | for p in self.model.dispersion[item].keys(): |
---|
166 | if p=="width": |
---|
167 | ix = 0 |
---|
168 | name = wx.StaticText(self, -1, name1) |
---|
169 | self.sizer4_4.Add( name,( iy, ix),(1,1), |
---|
170 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
171 | ix = 1 |
---|
172 | value= self.model.getParam(name1) |
---|
173 | ctl1 = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
174 | style=wx.TE_PROCESS_ENTER) |
---|
175 | ctl1.SetValue(str (format_number(value))) |
---|
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 = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), |
---|
183 | style=wx.TE_PROCESS_ENTER) |
---|
184 | Tctl1.SetValue(str (format_number(value))) |
---|
185 | self.sizer4_4.Add(Tctl1, (iy,ix),(1,1), |
---|
186 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
187 | self.fixed_param.append([None,name2, Tctl1,None,None, |
---|
188 | None, None,None]) |
---|
189 | elif p=="nsigmas": |
---|
190 | ix =3 |
---|
191 | value= self.model.getParam(name3) |
---|
192 | Tctl2 = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), |
---|
193 | style=wx.TE_PROCESS_ENTER) |
---|
194 | Tctl2.SetValue(str (format_number(value))) |
---|
195 | self.sizer4_4.Add(Tctl2, (iy,ix),(1,1), |
---|
196 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
197 | ix +=1 |
---|
198 | self.sizer4_4.Add((20,20), (iy,ix),(1,1), |
---|
199 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
200 | self.fixed_param.append([None,name3, Tctl2, |
---|
201 | None,None, None, None,None]) |
---|
202 | for item in self.model.dispersion.keys(): |
---|
203 | if item in self.model.orientation_params: |
---|
204 | self.disp_cb_dict[item]= None |
---|
205 | name1=item+".width" |
---|
206 | name2=item+".npts" |
---|
207 | name3=item+".nsigmas" |
---|
208 | iy += 1 |
---|
209 | for p in self.model.dispersion[item].keys(): |
---|
210 | if p=="width": |
---|
211 | ix = 0 |
---|
212 | name = wx.StaticText(self, -1, name1) |
---|
213 | self.sizer4_4.Add( name,( iy, ix),(1,1), |
---|
214 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
215 | if not self.enable2D: |
---|
216 | name.Hide() |
---|
217 | else: |
---|
218 | name.Show(True) |
---|
219 | ix = 1 |
---|
220 | value= self.model.getParam(name1) |
---|
221 | ctl1 = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
222 | style=wx.TE_PROCESS_ENTER) |
---|
223 | ctl1.SetValue(str (format_number(value))) |
---|
224 | if not self.enable2D: |
---|
225 | ctl1.Hide() |
---|
226 | ctl1.Disable() |
---|
227 | else: |
---|
228 | ctl1.Show(True) |
---|
229 | ctl1.Enable() |
---|
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 = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), |
---|
239 | style=wx.TE_PROCESS_ENTER) |
---|
240 | Tctl1.SetValue(str (format_number(value))) |
---|
241 | if not self.enable2D: |
---|
242 | Tctl1.Hide() |
---|
243 | Tctl1.Disable() |
---|
244 | else: |
---|
245 | Tctl1.Show(True) |
---|
246 | Tctl1.Enable() |
---|
247 | self.sizer4_4.Add(Tctl1, (iy,ix),(1,1), |
---|
248 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
249 | self.fixed_param.append([None,name2, Tctl1,None,None, |
---|
250 | None, None,None]) |
---|
251 | self.orientation_params_disp.append([None,name2, Tctl1,None,None, |
---|
252 | None, None,None]) |
---|
253 | elif p=="nsigmas": |
---|
254 | ix =3 |
---|
255 | value= self.model.getParam(name3) |
---|
256 | Tctl2 = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), |
---|
257 | style=wx.TE_PROCESS_ENTER) |
---|
258 | Tctl2.SetValue(str (format_number(value))) |
---|
259 | if not self.enable2D: |
---|
260 | Tctl2.Hide() |
---|
261 | Tctl2.Disable() |
---|
262 | else: |
---|
263 | Tctl2.Show(True) |
---|
264 | Tctl2.Enable() |
---|
265 | self.sizer4_4.Add(Tctl2, (iy,ix),(1,1), |
---|
266 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
267 | ix +=1 |
---|
268 | self.sizer4_4.Add((20,20), (iy,ix),(1,1), |
---|
269 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
270 | self.fixed_param.append([None,name3, Tctl2, |
---|
271 | None,None, None, None,None]) |
---|
272 | self.orientation_params_disp.append([None,name3, Tctl2, |
---|
273 | None,None, None, None,None]) |
---|
274 | |
---|
275 | msg = " Selected Distribution: Gaussian" |
---|
276 | wx.PostEvent(self.parent.parent, StatusEvent( status= msg )) |
---|
277 | self.state.disp_cb_dict = copy.deepcopy(self.disp_cb_dict) |
---|
278 | ix =0 |
---|
279 | iy +=1 |
---|
280 | self.sizer4_4.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
281 | self.sizer4_4.Layout() |
---|
282 | self.sizer4.Layout() |
---|
283 | self.SetScrollbars(20,20,200,100) |
---|
284 | |
---|
285 | |
---|
286 | def _onModel2D(self, event): |
---|
287 | """ |
---|
288 | call manager to plot model in 2D |
---|
289 | """ |
---|
290 | # If the 2D display is not currently enabled, plot the model in 2D |
---|
291 | # and set the enable2D flag. |
---|
292 | |
---|
293 | if self.fitrange: |
---|
294 | self.enable2D = True |
---|
295 | |
---|
296 | if self.enable2D: |
---|
297 | self._draw_model() |
---|
298 | self.model_view.Disable() |
---|
299 | |
---|
300 | self.set_model_param_sizer(self.model) |
---|
301 | self._set_sizer_gaussian() |
---|
302 | |
---|
303 | if len(self.orientation_params)>0: |
---|
304 | for item in self.orientation_params: |
---|
305 | if item[2]!=None: |
---|
306 | item[2].Enable() |
---|
307 | if self.disp_name == "ArrayDispersion": |
---|
308 | self._set_sizer_arraydispersion() |
---|
309 | else: |
---|
310 | if len(self.orientation_params_disp)>0: |
---|
311 | for item in self.orientation_params_disp: |
---|
312 | if item[2]!=None: |
---|
313 | item[2].Enable() |
---|
314 | self.state.enable2D = copy.deepcopy(self.enable2D) |
---|
315 | ## post state to fit panel |
---|
316 | self._undo.Enable(True) |
---|
317 | event = PageInfoEvent(page = self) |
---|
318 | wx.PostEvent(self.parent, event) |
---|
319 | |
---|
320 | |
---|
321 | def reset_page(self, state): |
---|
322 | """ |
---|
323 | reset the state |
---|
324 | """ |
---|
325 | self.reset_page_helper(state) |
---|
326 | |
---|
327 | |
---|
328 | def select_model(self, model): |
---|
329 | """ |
---|
330 | Select a new model |
---|
331 | @param model: model object |
---|
332 | """ |
---|
333 | self.model = model |
---|
334 | if self.model !=None: |
---|
335 | self.disp_list= self.model.getDispParamList() |
---|
336 | self.set_model_param_sizer(self.model) |
---|
337 | ## keep the sizer view consistent with the model menu selecting |
---|
338 | self._set_model_sizer_selection( self.model ) |
---|
339 | self.enable_disp.SetValue(False) |
---|
340 | self.disable_disp.SetValue(True) |
---|
341 | self.set_dispers_sizer() |
---|
342 | |
---|
343 | self.model_view.SetFocus() |
---|
344 | if self.model !=None: |
---|
345 | self._draw_model() |
---|
346 | self.state.structurecombobox = self.structurebox.GetCurrentSelection() |
---|
347 | self.state.formfactorcombobox = self.formfactorbox.GetCurrentSelection() |
---|
348 | |
---|
349 | ## post state to fit panel |
---|
350 | self._undo.Enable(True) |
---|
351 | event = PageInfoEvent(page = self) |
---|
352 | wx.PostEvent(self.parent, event) |
---|
353 | |
---|
354 | |
---|
355 | def set_model_description(self,description,sizer): |
---|
356 | """ |
---|
357 | fill a sizer with description |
---|
358 | @param description: of type string |
---|
359 | @param sizer: wx.BoxSizer() |
---|
360 | """ |
---|
361 | |
---|
362 | sizer.Clear(True) |
---|
363 | box_description= wx.StaticBox(self, -1, 'Model Description') |
---|
364 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
365 | |
---|
366 | sizer_selection=wx.BoxSizer(wx.HORIZONTAL) |
---|
367 | self.description_hide = wx.RadioButton(self, -1, 'Hide', style=wx.RB_GROUP) |
---|
368 | self.description_show = wx.RadioButton(self, -1, 'Show') |
---|
369 | |
---|
370 | |
---|
371 | if description=="": |
---|
372 | self.description_hide.SetValue(True) |
---|
373 | description=" Description unavailable. Click for details" |
---|
374 | |
---|
375 | self.description = wx.StaticText( self,-1,str(description) ) |
---|
376 | |
---|
377 | self.Bind( wx.EVT_RADIOBUTTON, self._on_display_description, |
---|
378 | id=self.description_hide.GetId() ) |
---|
379 | |
---|
380 | self.Bind( wx.EVT_RADIOBUTTON, self._on_display_description, |
---|
381 | id=self.description_show.GetId() ) |
---|
382 | |
---|
383 | self.model_description = wx.Button(self,-1, label="Details") |
---|
384 | self.model_description.Bind(wx.EVT_BUTTON,self.on_button_clicked) |
---|
385 | self.model_description.SetToolTipString("Click Model Functions in HelpWindow...") |
---|
386 | |
---|
387 | sizer_selection.Add( self.description_show ) |
---|
388 | sizer_selection.Add( (20,20)) |
---|
389 | sizer_selection.Add( self.description_hide ) |
---|
390 | sizer_selection.Add((20,20),0, wx.LEFT|wx.RIGHT|wx.EXPAND,67) |
---|
391 | sizer_selection.Add( self.model_description ) |
---|
392 | |
---|
393 | |
---|
394 | self.sizer_description=wx.BoxSizer(wx.HORIZONTAL) |
---|
395 | self.sizer_description.Add( self.description, 1, wx.EXPAND | wx.ALL, 10 ) |
---|
396 | boxsizer1.Add( sizer_selection) |
---|
397 | boxsizer1.Add( (20,20)) |
---|
398 | boxsizer1.Add( self.sizer_description) |
---|
399 | |
---|
400 | self._on_display_description(event=None) |
---|
401 | sizer.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
402 | sizer.Layout() |
---|
403 | |
---|
404 | def on_button_clicked(self,event): |
---|
405 | """ |
---|
406 | #On 'More details' button |
---|
407 | """ |
---|
408 | from helpPanel import HelpWindow |
---|
409 | |
---|
410 | if self.model == None: |
---|
411 | name = 'FuncHelp' |
---|
412 | else: |
---|
413 | name = self.model.name |
---|
414 | frame = HelpWindow(None, -1, name) |
---|
415 | frame.Show(True) |
---|
416 | if frame.rhelp.HasAnchor(name): |
---|
417 | frame.rhelp.ScrollToAnchor(name) |
---|
418 | else: |
---|
419 | msg= "Model does not contains an available description " |
---|
420 | msg +="Please.Search in the Help window" |
---|
421 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
422 | |
---|
423 | |
---|
424 | |
---|
425 | def set_range(self, qmin_x, qmax_x, npts): |
---|
426 | """ |
---|
427 | Set the range for the plotted models |
---|
428 | @param qmin: minimum Q |
---|
429 | @param qmax: maximum Q |
---|
430 | @param npts: number of Q bins |
---|
431 | """ |
---|
432 | # Set the data members |
---|
433 | self.qmin_x = qmin_x |
---|
434 | self.qmax_x = qmax_x |
---|
435 | self.num_points = npts |
---|
436 | |
---|
437 | # Set the controls |
---|
438 | #For qmin and qmax, do not use format_number.(If do, qmin and max could be different from what is in the data.) |
---|
439 | """ |
---|
440 | self.qmin.SetValue(format_number(self.qmin_x)) |
---|
441 | self.qmax.SetValue(format_number(self.qmax_x)) |
---|
442 | self.npts.SetValue(format_number(self.num_points)) |
---|
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 | |
---|