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