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