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