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 ModelPanel(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 |
---|
23 | one parameter on fit Panel window. |
---|
24 | """ |
---|
25 | ## Flag to tell the AUI manager to put this panel in the center pane |
---|
26 | CENTER_PANE = True |
---|
27 | ## Internal name for the AUI manager |
---|
28 | window_name = "Theory model" |
---|
29 | ## Title to appear on top of the window |
---|
30 | window_caption = "Theory Model" |
---|
31 | def __init__(self,parent, page_info, model_list_box): |
---|
32 | BasicPage.__init__(self, parent, page_info , model_list_box) |
---|
33 | """ |
---|
34 | Initialization of the Panel |
---|
35 | """ |
---|
36 | self._fill_model_sizer( self.sizer1) |
---|
37 | self._fill_range_sizer() |
---|
38 | self.engine_type = None |
---|
39 | |
---|
40 | description="" |
---|
41 | if self.model!=None: |
---|
42 | |
---|
43 | description = self.model.description |
---|
44 | |
---|
45 | self.select_model(self.model) |
---|
46 | self.set_model_description(description,self.sizer2) |
---|
47 | |
---|
48 | def _on_display_description(self, event): |
---|
49 | """ |
---|
50 | Show or Hide description |
---|
51 | @param event: wx.EVT_RADIOBUTTON |
---|
52 | """ |
---|
53 | self._on_display_description_helper() |
---|
54 | |
---|
55 | self.SetScrollbars(20,20,25,65) |
---|
56 | self.Refresh() |
---|
57 | |
---|
58 | def _on_display_description_helper(self): |
---|
59 | """ |
---|
60 | Show or Hide description |
---|
61 | @param event: wx.EVT_RADIOBUTTON |
---|
62 | """ |
---|
63 | ## Show description |
---|
64 | if self.description_hide.GetValue(): |
---|
65 | self.sizer_description.Clear(True) |
---|
66 | |
---|
67 | else: |
---|
68 | description="Model contains no description" |
---|
69 | if self.model!=None: |
---|
70 | description = self.model.description |
---|
71 | if description.lstrip().rstrip() =="": |
---|
72 | description="Model contains no description" |
---|
73 | self.description = wx.StaticText( self,-1,str(description) ) |
---|
74 | self.sizer_description.Add( self.description, 1, wx.EXPAND | wx.ALL, 10 ) |
---|
75 | |
---|
76 | self.Layout() |
---|
77 | |
---|
78 | |
---|
79 | def _fill_range_sizer(self): |
---|
80 | """ |
---|
81 | Fill the sizer containing the plotting range |
---|
82 | add access to npts |
---|
83 | """ |
---|
84 | ##The following 3 lines are for Mac. Let JHC know before modifying.. |
---|
85 | title = "Plotted Q Range" |
---|
86 | box_description= wx.StaticBox(self, -1,str(title)) |
---|
87 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
88 | |
---|
89 | sizer_npts= wx.GridSizer(1, 1,5, 5) |
---|
90 | self.npts = self.ModelTextCtrl(self, -1,size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER) |
---|
91 | self.npts.SetValue(format_number(self.num_points)) |
---|
92 | self.npts.SetToolTipString("Number of point to plot.") |
---|
93 | |
---|
94 | sizer_npts.Add(wx.StaticText(self, -1, 'Npts'),1, wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 13) |
---|
95 | |
---|
96 | sizer_npts.Add(self.npts,1,wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
97 | self._set_range_sizer( title=title, box_sizer=boxsizer1, object= sizer_npts) |
---|
98 | |
---|
99 | |
---|
100 | def _on_select_model(self, event): |
---|
101 | """ |
---|
102 | call back for model selection |
---|
103 | """ |
---|
104 | self._on_select_model_helper() |
---|
105 | #Reset dispersity that was not done in _on_select_model_helper() |
---|
106 | self._reset_dispersity() |
---|
107 | self.select_model(self.model) |
---|
108 | |
---|
109 | |
---|
110 | def _fill_model_sizer(self, sizer): |
---|
111 | """ |
---|
112 | fill sizer containing model info |
---|
113 | """ |
---|
114 | ##The following 3 lines are for Mac. Let JHC know before modifying.. |
---|
115 | title = "Model" |
---|
116 | box_description= wx.StaticBox(self, -1,str(title)) |
---|
117 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
118 | |
---|
119 | id = wx.NewId() |
---|
120 | self.model_view =wx.Button(self,id,'View 2D', size=(80,23)) |
---|
121 | self.model_view.Bind(wx.EVT_BUTTON, self._onModel2D,id=id) |
---|
122 | self.model_view.SetToolTipString("View model in 2D") |
---|
123 | |
---|
124 | ## class base method to add view 2d button |
---|
125 | self._set_model_sizer(sizer=sizer,box_sizer=boxsizer1, title=title,object= self.model_view ) |
---|
126 | |
---|
127 | |
---|
128 | #def _set_sizer_gaussian(self): |
---|
129 | def _set_sizer_dispersion(self, dispersity): |
---|
130 | """ |
---|
131 | draw sizer with gaussian, log or schulz dispersity parameters |
---|
132 | """ |
---|
133 | self.fittable_param=[] |
---|
134 | self.fixed_param=[] |
---|
135 | self.orientation_params_disp=[] |
---|
136 | #self.temp=[] |
---|
137 | |
---|
138 | self.sizer4_4.Clear(True) |
---|
139 | if self.model==None: |
---|
140 | ##no model is selected |
---|
141 | return |
---|
142 | if not self.enable_disp.GetValue(): |
---|
143 | ## the user didn't select dispersity display |
---|
144 | return |
---|
145 | self._reset_dispersity() |
---|
146 | # Create the dispersion objects |
---|
147 | for item in self.model.dispersion.keys(): |
---|
148 | #disp_model = GaussianDispersion() |
---|
149 | disp_model = dispersity() |
---|
150 | self._disp_obj_dict[item] = disp_model |
---|
151 | self.model.set_dispersion(item, disp_model) |
---|
152 | self.state._disp_obj_dict[item]= disp_model |
---|
153 | |
---|
154 | |
---|
155 | ix=0 |
---|
156 | iy=1 |
---|
157 | disp = wx.StaticText(self, -1, 'Names') |
---|
158 | self.sizer4_4.Add(disp,( iy, ix),(1,1), |
---|
159 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
160 | ix += 1 |
---|
161 | values = wx.StaticText(self, -1, 'Sigmas (STD)') |
---|
162 | self.sizer4_4.Add(values,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
163 | |
---|
164 | ix += 1 |
---|
165 | npts = wx.StaticText(self, -1, 'Npts') |
---|
166 | self.sizer4_4.Add(npts,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
167 | ix += 1 |
---|
168 | nsigmas = wx.StaticText(self, -1, 'Nsigmas') |
---|
169 | self.sizer4_4.Add(nsigmas,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
170 | |
---|
171 | for item in self.model.dispersion.keys(): |
---|
172 | if not item in self.model.orientation_params: |
---|
173 | self.disp_cb_dict[item]= None |
---|
174 | name1=item+".width" |
---|
175 | name2=item+".npts" |
---|
176 | name3=item+".nsigmas" |
---|
177 | iy += 1 |
---|
178 | for p in self.model.dispersion[item].keys(): |
---|
179 | if p=="width": |
---|
180 | ix = 0 |
---|
181 | name = wx.StaticText(self, -1, name1) |
---|
182 | self.sizer4_4.Add( name,( iy, ix),(1,1), |
---|
183 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
184 | ix = 1 |
---|
185 | value= self.model.getParam(name1) |
---|
186 | ctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
187 | style=wx.TE_PROCESS_ENTER) |
---|
188 | ctl1.SetValue(str (format_number(value))) |
---|
189 | self.sizer4_4.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
190 | self.fittable_param.append([None,name1,ctl1,None, |
---|
191 | None, None, None,None]) |
---|
192 | elif p=="npts": |
---|
193 | ix =2 |
---|
194 | value= self.model.getParam(name2) |
---|
195 | Tctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), |
---|
196 | style=wx.TE_PROCESS_ENTER) |
---|
197 | Tctl1.SetValue(str (format_number(value))) |
---|
198 | self.sizer4_4.Add(Tctl1, (iy,ix),(1,1), |
---|
199 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
200 | self.fixed_param.append([None,name2, Tctl1,None,None, |
---|
201 | None, None,None]) |
---|
202 | elif p=="nsigmas": |
---|
203 | ix =3 |
---|
204 | value= self.model.getParam(name3) |
---|
205 | Tctl2 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), |
---|
206 | style=wx.TE_PROCESS_ENTER) |
---|
207 | Tctl2.SetValue(str (format_number(value))) |
---|
208 | self.sizer4_4.Add(Tctl2, (iy,ix),(1,1), |
---|
209 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
210 | ix +=1 |
---|
211 | self.sizer4_4.Add((20,20), (iy,ix),(1,1), |
---|
212 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
213 | self.fixed_param.append([None,name3, Tctl2, |
---|
214 | None,None, None, None,None]) |
---|
215 | for item in self.model.dispersion.keys(): |
---|
216 | if item in self.model.orientation_params: |
---|
217 | self.disp_cb_dict[item]= None |
---|
218 | name1=item+".width" |
---|
219 | name2=item+".npts" |
---|
220 | name3=item+".nsigmas" |
---|
221 | iy += 1 |
---|
222 | for p in self.model.dispersion[item].keys(): |
---|
223 | if p=="width": |
---|
224 | ix = 0 |
---|
225 | name = wx.StaticText(self, -1, name1) |
---|
226 | self.sizer4_4.Add( name,( iy, ix),(1,1), |
---|
227 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
228 | if not self.enable2D: |
---|
229 | name.Hide() |
---|
230 | else: |
---|
231 | name.Show(True) |
---|
232 | ix = 1 |
---|
233 | value= self.model.getParam(name1) |
---|
234 | ctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
235 | style=wx.TE_PROCESS_ENTER) |
---|
236 | ctl1.SetValue(str (format_number(value))) |
---|
237 | if not self.enable2D: |
---|
238 | ctl1.Hide() |
---|
239 | ctl1.Disable() |
---|
240 | else: |
---|
241 | ctl1.Show(True) |
---|
242 | ctl1.Enable() |
---|
243 | self.sizer4_4.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
244 | self.fittable_param.append([None,name1,ctl1,None, |
---|
245 | None, None, None,None]) |
---|
246 | self.orientation_params_disp.append([None,name1,ctl1,None, |
---|
247 | None, None, None,None]) |
---|
248 | elif p=="npts": |
---|
249 | ix =2 |
---|
250 | value= self.model.getParam(name2) |
---|
251 | Tctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), |
---|
252 | style=wx.TE_PROCESS_ENTER) |
---|
253 | Tctl1.SetValue(str (format_number(value))) |
---|
254 | if not self.enable2D: |
---|
255 | Tctl1.Hide() |
---|
256 | Tctl1.Disable() |
---|
257 | else: |
---|
258 | Tctl1.Show(True) |
---|
259 | Tctl1.Enable() |
---|
260 | self.sizer4_4.Add(Tctl1, (iy,ix),(1,1), |
---|
261 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
262 | self.fixed_param.append([None,name2, Tctl1,None,None, |
---|
263 | None, None,None]) |
---|
264 | self.orientation_params_disp.append([None,name2, Tctl1,None,None, |
---|
265 | None, None,None]) |
---|
266 | elif p=="nsigmas": |
---|
267 | ix =3 |
---|
268 | value= self.model.getParam(name3) |
---|
269 | Tctl2 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), |
---|
270 | style=wx.TE_PROCESS_ENTER) |
---|
271 | Tctl2.SetValue(str (format_number(value))) |
---|
272 | if not self.enable2D: |
---|
273 | Tctl2.Hide() |
---|
274 | Tctl2.Disable() |
---|
275 | else: |
---|
276 | Tctl2.Show(True) |
---|
277 | Tctl2.Enable() |
---|
278 | self.sizer4_4.Add(Tctl2, (iy,ix),(1,1), |
---|
279 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
280 | ix +=1 |
---|
281 | #self.sizer4_4.Add((20,20), (iy,ix),(1,1), |
---|
282 | #wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
283 | self.fixed_param.append([None,name3, Tctl2, |
---|
284 | None,None, None, None,None]) |
---|
285 | self.orientation_params_disp.append([None,name3, Tctl2, |
---|
286 | None,None, None, None,None]) |
---|
287 | |
---|
288 | msg = " Selected Distribution: Gaussian" |
---|
289 | wx.PostEvent(self.parent, StatusEvent( status= msg )) |
---|
290 | self.state.disp_cb_dict = copy.deepcopy(self.disp_cb_dict) |
---|
291 | ix =0 |
---|
292 | iy +=1 |
---|
293 | #self.sizer4_4.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
294 | self.sizer4_4.Layout() |
---|
295 | self.sizer4.Layout() |
---|
296 | self.SetScrollbars(20,20,25,65) |
---|
297 | |
---|
298 | |
---|
299 | def _onModel2D(self, event): |
---|
300 | """ |
---|
301 | call manager to plot model in 2D |
---|
302 | """ |
---|
303 | # If the 2D display is not currently enabled, plot the model in 2D |
---|
304 | # and set the enable2D flag. |
---|
305 | |
---|
306 | if self.fitrange: |
---|
307 | self.enable2D = True |
---|
308 | |
---|
309 | if self.enable2D: |
---|
310 | self._draw_model() |
---|
311 | self.model_view.Disable() |
---|
312 | |
---|
313 | n = self.disp_box.GetCurrentSelection() |
---|
314 | dispersity= self.disp_box.GetClientData(n) |
---|
315 | #TODO:Find a better way to reinitialize the parameters containers |
---|
316 | # when resetting the page and 2D view is enable |
---|
317 | #self.set_model_param_sizer(self.model): called here is using a lot |
---|
318 | #of for loops and redraw the sizer again .How to avoid it? |
---|
319 | self.set_model_param_sizer(self.model) |
---|
320 | |
---|
321 | if len(self.orientation_params)>0: |
---|
322 | for item in self.orientation_params: |
---|
323 | if item[2]!=None: |
---|
324 | item[2].Enable() |
---|
325 | # same as above why do we have to redraw the sizer of dispersity to get |
---|
326 | # the appropriate value of parameters containers on reset page? |
---|
327 | # Reset containers of dispersity parameters for the appropriate dispersity |
---|
328 | #and model |
---|
329 | if self.disp_name.lower()in ["array","arraydispersion"]: |
---|
330 | self._set_sizer_arraydispersion() |
---|
331 | else: |
---|
332 | self._set_sizer_dispersion(dispersity) |
---|
333 | if len(self.orientation_params_disp)>0: |
---|
334 | |
---|
335 | for item in self.orientation_params_disp: |
---|
336 | if item[2]!=None: |
---|
337 | item[2].Enable() |
---|
338 | |
---|
339 | self.state.enable2D = copy.deepcopy(self.enable2D) |
---|
340 | self.Layout() |
---|
341 | ## post state to fit panel |
---|
342 | #self._undo.Enable(True) |
---|
343 | event = PageInfoEvent(page = self) |
---|
344 | wx.PostEvent(self.parent, event) |
---|
345 | |
---|
346 | |
---|
347 | def reset_page(self, state): |
---|
348 | """ |
---|
349 | reset the state |
---|
350 | """ |
---|
351 | self.reset_page_helper(state) |
---|
352 | |
---|
353 | |
---|
354 | def select_model(self, model): |
---|
355 | """ |
---|
356 | Select a new model |
---|
357 | @param model: model object |
---|
358 | """ |
---|
359 | self.model = model |
---|
360 | if self.model !=None: |
---|
361 | self.disp_list= self.model.getDispParamList() |
---|
362 | self.set_model_param_sizer(self.model) |
---|
363 | ## keep the sizer view consistent with the model menu selecting |
---|
364 | self._set_model_sizer_selection( self.model ) |
---|
365 | self.enable_disp.SetValue(False) |
---|
366 | self.disable_disp.SetValue(True) |
---|
367 | self.set_dispers_sizer() |
---|
368 | |
---|
369 | self.model_view.SetFocus() |
---|
370 | if self.model !=None: |
---|
371 | self._draw_model() |
---|
372 | self.state.structurecombobox = self.structurebox.GetCurrentSelection() |
---|
373 | self.state.formfactorcombobox = self.formfactorbox.GetCurrentSelection() |
---|
374 | |
---|
375 | ## post state to fit panel |
---|
376 | #self._undo.Enable(True) |
---|
377 | event = PageInfoEvent(page = self) |
---|
378 | wx.PostEvent(self.parent, event) |
---|
379 | |
---|
380 | |
---|
381 | def set_model_description(self,description,sizer): |
---|
382 | """ |
---|
383 | fill a sizer with description |
---|
384 | @param description: of type string |
---|
385 | @param sizer: wx.BoxSizer() |
---|
386 | """ |
---|
387 | |
---|
388 | sizer.Clear(True) |
---|
389 | box_description= wx.StaticBox(self, -1, 'Model Description') |
---|
390 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
391 | |
---|
392 | sizer_selection=wx.BoxSizer(wx.HORIZONTAL) |
---|
393 | self.description_hide = wx.RadioButton(self, -1, 'Hide', style=wx.RB_GROUP) |
---|
394 | self.description_show = wx.RadioButton(self, -1, 'Show') |
---|
395 | |
---|
396 | |
---|
397 | if description=="": |
---|
398 | self.description_hide.SetValue(True) |
---|
399 | description=" Description unavailable. Click for details" |
---|
400 | |
---|
401 | self.description = wx.StaticText( self,-1,str(description) ) |
---|
402 | |
---|
403 | self.Bind( wx.EVT_RADIOBUTTON, self._on_display_description, |
---|
404 | id=self.description_hide.GetId() ) |
---|
405 | |
---|
406 | self.Bind( wx.EVT_RADIOBUTTON, self._on_display_description, |
---|
407 | id=self.description_show.GetId() ) |
---|
408 | #MAC needs SetValue |
---|
409 | self.description_hide.SetValue(True) |
---|
410 | |
---|
411 | self.model_description = wx.Button(self,-1, label="Details", size=(80,23)) |
---|
412 | |
---|
413 | self.model_description.Bind(wx.EVT_BUTTON,self.on_button_clicked) |
---|
414 | self.model_description.SetToolTipString("Click Model Functions in HelpWindow...") |
---|
415 | self.model_description.SetFocus() |
---|
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 help_panel import HelpWindow |
---|
438 | |
---|
439 | if self.model == None: |
---|
440 | name = 'FuncHelp' |
---|
441 | else: |
---|
442 | name = self.model.name |
---|
443 | frame = HelpWindow(None, -1, pageToOpen="media/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, 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 = self.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 | if self.model.details.has_key(item): |
---|
538 | units = wx.StaticText(self, -1, self.model.details[item][0], style=wx.ALIGN_LEFT) |
---|
539 | else: |
---|
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 = self.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 | if self.model.details.has_key(item): |
---|
590 | units = wx.StaticText(self, -1, self.model.details[item][0], style=wx.ALIGN_LEFT) |
---|
591 | else: |
---|
592 | units = wx.StaticText(self, -1, "", style=wx.ALIGN_LEFT) |
---|
593 | if not self.enable2D: |
---|
594 | units.Hide() |
---|
595 | else: |
---|
596 | units.Show(True) |
---|
597 | |
---|
598 | sizer.Add(units, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
599 | #Save 2D orient. params |
---|
600 | #self.temp.append([name,ctl1,units,orient_angle]) |
---|
601 | |
---|
602 | |
---|
603 | ##[cb state, name, value, "+/-", error of fit, min, max , units] |
---|
604 | self.parameters.append([None,item, ctl1, |
---|
605 | None,None, None, None,None]) |
---|
606 | self.orientation_params.append([None,item, ctl1, |
---|
607 | None,None, None, None,None]) |
---|
608 | |
---|
609 | iy+=1 |
---|
610 | |
---|
611 | #Display units text on panel |
---|
612 | for item in keys: |
---|
613 | self.text2_4.Show() |
---|
614 | |
---|
615 | |
---|
616 | boxsizer1.Add(sizer) |
---|
617 | self.sizer3.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
618 | self.sizer3.Layout() |
---|
619 | self.SetScrollbars(20,20,25,65) |
---|
620 | |
---|
621 | |
---|
622 | |
---|
623 | |
---|
624 | |
---|
625 | class HelpWindow(wx.Frame): |
---|
626 | def __init__(self, parent, id, title): |
---|
627 | wx.Frame.__init__(self, parent, id, title, size=(570, 400)) |
---|
628 | |
---|
629 | from sans.models.CylinderModel import CylinderModel |
---|
630 | model = CylinderModel() |
---|
631 | #from sans.models.LineModel import LineModel |
---|
632 | #model = LineModel() |
---|
633 | from fitpanel import PageInfo |
---|
634 | myinfo = PageInfo(self,model) |
---|
635 | from models import ModelList |
---|
636 | mylist= ModelList() |
---|
637 | |
---|
638 | from sans.models.SphereModel import SphereModel |
---|
639 | from sans.models.SquareWellStructure import SquareWellStructure |
---|
640 | from sans.models.DebyeModel import DebyeModel |
---|
641 | from sans.models.LineModel import LineModel |
---|
642 | name= "shapes" |
---|
643 | list1= [SphereModel] |
---|
644 | mylist.set_list( name, list1) |
---|
645 | |
---|
646 | name= "Shape-independent" |
---|
647 | list1= [DebyeModel] |
---|
648 | mylist.set_list( name, list1) |
---|
649 | |
---|
650 | name= "Structure Factors" |
---|
651 | list1= [SquareWellStructure] |
---|
652 | mylist.set_list( name, list1) |
---|
653 | |
---|
654 | name= "Added models" |
---|
655 | list1= [LineModel] |
---|
656 | mylist.set_list( name, list1) |
---|
657 | |
---|
658 | myinfo.model_list_box = mylist.get_list() |
---|
659 | |
---|
660 | self.page = ModelPage(self, myinfo) |
---|
661 | |
---|
662 | |
---|
663 | |
---|
664 | self.Centre() |
---|
665 | self.Show(True) |
---|
666 | |
---|
667 | |
---|
668 | |
---|
669 | if __name__=="__main__": |
---|
670 | app = wx.App() |
---|
671 | HelpWindow(None, -1, 'HelpWindow') |
---|
672 | app.MainLoop() |
---|
673 | |
---|