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