1 | import sys |
---|
2 | import wx |
---|
3 | import wx.lib |
---|
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 | |
---|
15 | |
---|
16 | |
---|
17 | class ModelPage(wx.ScrolledWindow): |
---|
18 | """ |
---|
19 | FitPanel class contains fields allowing to display results when |
---|
20 | fitting a model and one data |
---|
21 | @note: For Fit to be performed the user should check at least one parameter |
---|
22 | on fit Panel window. |
---|
23 | |
---|
24 | """ |
---|
25 | ## Internal name for the AUI manager |
---|
26 | window_name = "Fit page" |
---|
27 | ## Title to appear on top of the window |
---|
28 | window_caption = "Fit Page" |
---|
29 | name="" |
---|
30 | def __init__(self, parent,model,name, *args, **kwargs): |
---|
31 | wx.ScrolledWindow.__init__(self, parent, *args, **kwargs) |
---|
32 | """ |
---|
33 | Initialization of the Panel |
---|
34 | """ |
---|
35 | # model on which the fit would be performed |
---|
36 | self.model=model |
---|
37 | # Data member to store the dispersion object created |
---|
38 | self._disp_obj_dict = {} |
---|
39 | self.back_up_model= model.clone() |
---|
40 | #list of dispersion paramaters |
---|
41 | self.disp_list=[] |
---|
42 | try: |
---|
43 | self.disp_list=self.model.getDispParamList() |
---|
44 | except: |
---|
45 | pass |
---|
46 | self.manager = None |
---|
47 | self.parent = parent |
---|
48 | self.event_owner = None |
---|
49 | # this panel does contain data .existing data allow a different drawing |
---|
50 | #on set_model parameters |
---|
51 | self.data=None |
---|
52 | #panel interface |
---|
53 | self.vbox = wx.BoxSizer(wx.VERTICAL) |
---|
54 | self.sizer11 = wx.BoxSizer(wx.HORIZONTAL) |
---|
55 | #self.sizer10 = wx.GridBagSizer(5,5) |
---|
56 | self.sizer9 = wx.GridBagSizer(5,5) |
---|
57 | self.sizer8 = wx.GridBagSizer(5,5) |
---|
58 | self.sizer7 = wx.GridBagSizer(5,5) |
---|
59 | self.sizer6 = wx.GridBagSizer(5,5) |
---|
60 | self.sizer5 = wx.GridBagSizer(5,5) |
---|
61 | self.sizer4 = wx.GridBagSizer(5,5) |
---|
62 | |
---|
63 | #model selection |
---|
64 | self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0) |
---|
65 | self.vbox.Add(self.sizer4) |
---|
66 | #model description |
---|
67 | self.vbox.Add(self.sizer11) |
---|
68 | #model paramaters layer |
---|
69 | self.vbox.Add(self.sizer5) |
---|
70 | #polydispersion selected |
---|
71 | self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0) |
---|
72 | self.vbox.Add(self.sizer6) |
---|
73 | #combox box for type of dispersion |
---|
74 | self.vbox.Add(self.sizer7) |
---|
75 | #dispersion parameters layer |
---|
76 | self.vbox.Add(self.sizer8) |
---|
77 | # plotting range |
---|
78 | self.vbox.Add(self.sizer9) |
---|
79 | #close layer |
---|
80 | #self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0) |
---|
81 | #self.vbox.Add(self.sizer10) |
---|
82 | |
---|
83 | |
---|
84 | #------------------ sizer 4 draw------------------------ |
---|
85 | |
---|
86 | |
---|
87 | # define combox box |
---|
88 | self.modelbox = wx.ComboBox(self, -1) |
---|
89 | # preview selected model name |
---|
90 | self.prevmodel_name=name |
---|
91 | #print "model view prev_model",name |
---|
92 | self.modelbox.SetValue(self.prevmodel_name) |
---|
93 | #enable model 2D draw |
---|
94 | self.enable2D= False |
---|
95 | #filling sizer2 |
---|
96 | ix = 0 |
---|
97 | iy = 1 |
---|
98 | self.sizer4.Add(wx.StaticText(self,-1,'Model'),(iy,ix),(1,1)\ |
---|
99 | , wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
100 | ix += 1 |
---|
101 | self.sizer4.Add(self.modelbox,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
102 | ix += 1 |
---|
103 | id = wx.NewId() |
---|
104 | self.model_view =wx.Button(self,id,'View 2D') |
---|
105 | self.model_view.Bind(wx.EVT_BUTTON, self.onModel2D,id=id) |
---|
106 | self.model_view.SetToolTipString("View model in 2D") |
---|
107 | |
---|
108 | self.sizer4.Add(self.model_view,(iy,ix),(1,1),\ |
---|
109 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
110 | |
---|
111 | self.model_view.Enable() |
---|
112 | self.model_view.SetFocus() |
---|
113 | |
---|
114 | ix = 0 |
---|
115 | iy += 1 |
---|
116 | self.sizer4.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
117 | |
---|
118 | #----------sizer6------------------------------------------------- |
---|
119 | self.disable_disp = wx.RadioButton(self, -1, 'No', (10, 10), style=wx.RB_GROUP) |
---|
120 | self.enable_disp = wx.RadioButton(self, -1, 'Yes', (10, 30)) |
---|
121 | self.Bind(wx.EVT_RADIOBUTTON, self.Set_DipersParam, id=self.disable_disp.GetId()) |
---|
122 | self.Bind(wx.EVT_RADIOBUTTON, self.Set_DipersParam, id=self.enable_disp.GetId()) |
---|
123 | ix= 0 |
---|
124 | iy=1 |
---|
125 | self.sizer6.Add(wx.StaticText(self,-1,'Polydispersity: '),(iy,ix),(1,1)\ |
---|
126 | , wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
127 | ix += 1 |
---|
128 | self.sizer6.Add(self.enable_disp ,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
129 | ix += 1 |
---|
130 | self.sizer6.Add(self.disable_disp ,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
131 | ix =0 |
---|
132 | iy+=1 |
---|
133 | self.sizer6.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
134 | |
---|
135 | |
---|
136 | #---------sizer 9 draw---------------------------------------- |
---|
137 | |
---|
138 | ## Q range |
---|
139 | self.qmin_x= 0.001 |
---|
140 | self.qmax_x= 0.1 |
---|
141 | self.num_points= 100 |
---|
142 | |
---|
143 | |
---|
144 | self.qmin = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20)) |
---|
145 | self.qmin.SetValue(format_number(self.qmin_x)) |
---|
146 | self.qmin.SetToolTipString("Minimun value of Q in linear scale.") |
---|
147 | self.qmin.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
148 | self.qmin.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter) |
---|
149 | |
---|
150 | self.qmax = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20)) |
---|
151 | self.qmax.SetValue(format_number(self.qmax_x)) |
---|
152 | self.qmax.SetToolTipString("Maximum value of Q in linear scale.") |
---|
153 | self.qmax.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
154 | self.qmax.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter) |
---|
155 | |
---|
156 | |
---|
157 | self.npts = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20)) |
---|
158 | self.npts.SetValue(format_number(self.num_points)) |
---|
159 | self.npts.SetToolTipString("Number of point to plot.") |
---|
160 | self.npts.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
161 | self.npts.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter) |
---|
162 | |
---|
163 | ix = 0 |
---|
164 | iy = 1 |
---|
165 | self.sizer9.Add(wx.StaticText(self, -1, 'Plotting Range'),(iy, ix),(1,1),\ |
---|
166 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
167 | ix += 1 |
---|
168 | self.sizer9.Add(wx.StaticText(self, -1, 'Min'),(iy, ix),(1,1),\ |
---|
169 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
170 | ix += 1 |
---|
171 | self.sizer9.Add(wx.StaticText(self, -1, 'Max'),(iy, ix),(1,1),\ |
---|
172 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
173 | ix += 1 |
---|
174 | self.sizer9.Add(wx.StaticText(self, -1, 'Npts'),(iy, ix),(1,1),\ |
---|
175 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
176 | ix = 0 |
---|
177 | iy += 1 |
---|
178 | self.sizer9.Add(wx.StaticText(self, -1, 'Q range'),(iy, ix),(1,1),\ |
---|
179 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
180 | ix += 1 |
---|
181 | self.sizer9.Add(self.qmin,(iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
182 | ix += 1 |
---|
183 | self.sizer9.Add(self.qmax,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
184 | ix += 1 |
---|
185 | self.sizer9.Add(self.npts,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
186 | |
---|
187 | ix =0 |
---|
188 | iy+=1 |
---|
189 | self.sizer9.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
190 | #----------sizer 10 draw------------------------------------------------------ |
---|
191 | """ |
---|
192 | id = wx.NewId() |
---|
193 | self.btClose =wx.Button(self,id,'Close') |
---|
194 | self.btClose.Bind(wx.EVT_BUTTON, self.onClose,id=id) |
---|
195 | self.btClose.SetToolTipString("Close page.") |
---|
196 | |
---|
197 | ix= 3 |
---|
198 | iy= 1 |
---|
199 | self.sizer10.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
200 | ix +=1 |
---|
201 | self.sizer10.Add( self.btClose,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
202 | ix =0 |
---|
203 | iy+=1 |
---|
204 | self.sizer10.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
205 | """ |
---|
206 | # contains link between model ,all its parameters, and panel organization |
---|
207 | self.parameters=[] |
---|
208 | self.fixed_param=[] |
---|
209 | self.fittable_param=[] |
---|
210 | self.polydisp= {} |
---|
211 | #contains link between a model and selected parameters to fit |
---|
212 | self.param_toFit=[] |
---|
213 | |
---|
214 | #dictionary of model name and model class |
---|
215 | self.model_list_box={} |
---|
216 | #Draw initial panel |
---|
217 | #-----sizer 11--------------------model description------ |
---|
218 | if self.model!=None: |
---|
219 | self.set_panel(self.model) |
---|
220 | self.theta_cb=None |
---|
221 | |
---|
222 | |
---|
223 | self.vbox.Layout() |
---|
224 | self.vbox.Fit(self) |
---|
225 | self.SetSizer(self.vbox) |
---|
226 | self.SetScrollbars(20,20,55,40) |
---|
227 | |
---|
228 | self.Centre() |
---|
229 | self.Layout() |
---|
230 | self.parent.GetSizer().Layout() |
---|
231 | def set_model_description(self, model): |
---|
232 | |
---|
233 | if model !=None and str(model.description)!=""and self.data==None: |
---|
234 | self.sizer11.Clear(True) |
---|
235 | self.box_description= wx.StaticBox(self, -1, 'Model Description') |
---|
236 | boxsizer1 = wx.StaticBoxSizer(self.box_description, wx.VERTICAL) |
---|
237 | boxsizer1.SetMinSize((320,20)) |
---|
238 | self.description = wx.StaticText(self,-1,str(model.description)) |
---|
239 | boxsizer1.Add(self.description, 0, wx.EXPAND) |
---|
240 | self.sizer11.Add(boxsizer1,1, wx.EXPAND | wx.ALL, 2) |
---|
241 | |
---|
242 | |
---|
243 | def set_owner(self,owner): |
---|
244 | """ |
---|
245 | set owner of fitpage |
---|
246 | @param owner: the class responsible of plotting |
---|
247 | """ |
---|
248 | self.event_owner=owner |
---|
249 | |
---|
250 | |
---|
251 | def set_manager(self, manager): |
---|
252 | """ |
---|
253 | set panel manager |
---|
254 | @param manager: instance of plugin fitting |
---|
255 | """ |
---|
256 | self.manager = manager |
---|
257 | |
---|
258 | def populate_box(self, dict): |
---|
259 | """ |
---|
260 | Populate each combox box of each page |
---|
261 | @param page: the page to populate |
---|
262 | """ |
---|
263 | id=0 |
---|
264 | self.model_list_box=dict |
---|
265 | list_name=[] |
---|
266 | for item in self.model_list_box.itervalues(): |
---|
267 | name = item.__name__ |
---|
268 | if hasattr(item, "name"): |
---|
269 | name = item.name |
---|
270 | list_name.append(name) |
---|
271 | list_name.sort() |
---|
272 | |
---|
273 | for name in list_name: |
---|
274 | self.modelbox.Insert(name,int(id)) |
---|
275 | id+=1 |
---|
276 | wx.EVT_COMBOBOX(self.modelbox,-1, self._on_select_model) |
---|
277 | return 0 |
---|
278 | |
---|
279 | |
---|
280 | def Set_DipersParam(self, event): |
---|
281 | if self.enable_disp.GetValue(): |
---|
282 | if len(self.disp_list)==0: |
---|
283 | ix=0 |
---|
284 | iy=1 |
---|
285 | self.fittable_param=[] |
---|
286 | self.fixed_param=[] |
---|
287 | self.sizer8.Clear(True) |
---|
288 | model_disp = wx.StaticText(self, -1, 'No PolyDispersity for this model') |
---|
289 | self.sizer7.Add(model_disp,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
290 | self.vbox.Layout() |
---|
291 | self.SetScrollbars(20,20,55,40) |
---|
292 | self.Layout() |
---|
293 | self.parent.GetSizer().Layout() |
---|
294 | return |
---|
295 | else: |
---|
296 | if self.data !=None and self.model !=None: # allow to recognize data panel from model panel |
---|
297 | |
---|
298 | |
---|
299 | self.cb1.SetValue(False) |
---|
300 | self.select_all_param_helper() |
---|
301 | |
---|
302 | self.populate_disp_box() |
---|
303 | self.set_panel_dispers(self.disp_list) |
---|
304 | |
---|
305 | else: |
---|
306 | if self.data !=None and self.model!=None: |
---|
307 | if self.cb1.GetValue(): |
---|
308 | self.select_all_param_helper() |
---|
309 | |
---|
310 | if self.back_up_model!=None: |
---|
311 | keys = self.back_up_model.getDispParamList() |
---|
312 | keys.sort() |
---|
313 | #disperse param into the initial state |
---|
314 | for item in keys: |
---|
315 | value= self.back_up_model.getParam(item) |
---|
316 | self.model.setParam(item, value) |
---|
317 | self._draw_model() |
---|
318 | |
---|
319 | |
---|
320 | self.fittable_param=[] |
---|
321 | self.fixed_param=[] |
---|
322 | self.sizer7.Clear(True) |
---|
323 | self.sizer8.Clear(True) |
---|
324 | self.vbox.Layout() |
---|
325 | self.SetScrollbars(20,20,55,40) |
---|
326 | self.Layout() |
---|
327 | self.parent.GetSizer().Layout() |
---|
328 | |
---|
329 | def populate_disp_box(self): |
---|
330 | self.sizer7.Clear(True) |
---|
331 | if len(self.disp_list)>0: |
---|
332 | ix=0 |
---|
333 | iy=1 |
---|
334 | model_disp = wx.StaticText(self, -1, 'Model Disp') |
---|
335 | self.sizer7.Add(model_disp,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
336 | ix += 1 |
---|
337 | # set up the combox box |
---|
338 | id = 0 |
---|
339 | import sans.models.dispersion_models |
---|
340 | self.polydisp= sans.models.dispersion_models.models |
---|
341 | self.disp_box = wx.ComboBox(self, -1) |
---|
342 | self.disp_box.SetValue("GaussianModel") |
---|
343 | for k,v in self.polydisp.iteritems(): |
---|
344 | if str(v)=="MyModel": |
---|
345 | # Remove the option until the rest of the code is ready for it |
---|
346 | #self.disp_box.Insert("Select customized Model",id) |
---|
347 | pass |
---|
348 | else: |
---|
349 | self.disp_box.Insert(str(v),id) |
---|
350 | id+=1 |
---|
351 | |
---|
352 | wx.EVT_COMBOBOX(self.disp_box,-1, self._on_select_Disp) |
---|
353 | self.sizer7.Add(self.disp_box,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
354 | self.vbox.Layout() |
---|
355 | self.SetScrollbars(20,20,55,40) |
---|
356 | self.Layout() |
---|
357 | self.parent.GetSizer().Layout() |
---|
358 | |
---|
359 | |
---|
360 | def set_range(self, qmin_x, qmax_x, npts): |
---|
361 | """ |
---|
362 | Set the range for the plotted models |
---|
363 | @param qmin: minimum Q |
---|
364 | @param qmax: maximum Q |
---|
365 | @param npts: number of Q bins |
---|
366 | """ |
---|
367 | # Set the data members |
---|
368 | self.qmin_x = qmin_x |
---|
369 | self.qmax_x = qmax_x |
---|
370 | self.num_points = npts |
---|
371 | |
---|
372 | # Set the controls |
---|
373 | self.qmin.SetValue(format_number(self.qmin_x)) |
---|
374 | self.qmax.SetValue(format_number(self.qmax_x)) |
---|
375 | self.npts.SetValue(format_number(self.num_points)) |
---|
376 | def checkFitRange(self): |
---|
377 | """ |
---|
378 | Check the validity of fitting range |
---|
379 | @note: qmin should always be less than qmax or else each control box |
---|
380 | background is colored in pink. |
---|
381 | """ |
---|
382 | |
---|
383 | flag = True |
---|
384 | valueMin = self.qmin.GetValue() |
---|
385 | valueMax = self.qmax.GetValue() |
---|
386 | # Check for possible values entered |
---|
387 | #print "fitpage: checkfitrange:",valueMin,valueMax |
---|
388 | try: |
---|
389 | if (float(valueMax)> float(valueMin)): |
---|
390 | self.qmax.SetBackgroundColour(wx.WHITE) |
---|
391 | self.qmin.SetBackgroundColour(wx.WHITE) |
---|
392 | else: |
---|
393 | flag = False |
---|
394 | self.qmin.SetBackgroundColour("pink") |
---|
395 | self.qmax.SetBackgroundColour("pink") |
---|
396 | except: |
---|
397 | flag = False |
---|
398 | self.qmin.SetBackgroundColour("pink") |
---|
399 | self.qmax.SetBackgroundColour("pink") |
---|
400 | |
---|
401 | self.qmin.Refresh() |
---|
402 | self.qmax.Refresh() |
---|
403 | return flag |
---|
404 | |
---|
405 | |
---|
406 | |
---|
407 | def onClose(self,event): |
---|
408 | """ close the page associated with this panel""" |
---|
409 | self.parent.onClose() |
---|
410 | |
---|
411 | |
---|
412 | |
---|
413 | def onModel2D(self, event): |
---|
414 | """ |
---|
415 | call manager to plot model in 2D |
---|
416 | """ |
---|
417 | # If the 2D display is not currently enabled, plot the model in 2D |
---|
418 | # and set the enable2D flag. |
---|
419 | if self.enable2D==False: |
---|
420 | self.enable2D=True |
---|
421 | self._draw_model() |
---|
422 | self.model_view.Disable() |
---|
423 | |
---|
424 | |
---|
425 | def select_model(self, model, name): |
---|
426 | """ |
---|
427 | Select a new model |
---|
428 | @param model: model object |
---|
429 | """ |
---|
430 | self.model = model |
---|
431 | self.parent.model_page.name = name |
---|
432 | self.parent.draw_model_name = name |
---|
433 | |
---|
434 | self.set_panel(model) |
---|
435 | self._draw_model(name) |
---|
436 | |
---|
437 | # Select the model from the combo box |
---|
438 | items = self.modelbox.GetItems() |
---|
439 | for i in range(len(items)): |
---|
440 | if items[i]==name: |
---|
441 | self.modelbox.SetSelection(i) |
---|
442 | self.model_view.SetFocus() |
---|
443 | |
---|
444 | def _on_select_Disp(self,event): |
---|
445 | """ |
---|
446 | allow selecting different dispersion |
---|
447 | self.disp_list should change type later .now only gaussian |
---|
448 | """ |
---|
449 | type =event.GetString() |
---|
450 | self.set_panel_dispers( self.disp_list,type ) |
---|
451 | |
---|
452 | def _on_select_model(self,event): |
---|
453 | """ |
---|
454 | react when a model is selected from page's combo box |
---|
455 | post an event to its owner to draw an appropriate theory |
---|
456 | """ |
---|
457 | self.disable_disp.SetValue(True) |
---|
458 | self.sizer8.Clear(True) |
---|
459 | self.sizer7.Clear(True) |
---|
460 | self.vbox.Layout() |
---|
461 | self.SetScrollbars(20,20,55,40) |
---|
462 | self.Layout() |
---|
463 | self.parent.GetSizer().Layout() |
---|
464 | for item in self.model_list_box.itervalues(): |
---|
465 | name = item.__name__ |
---|
466 | if hasattr(item, "name"): |
---|
467 | name = item.name |
---|
468 | if name ==event.GetString(): |
---|
469 | model=item() |
---|
470 | self.model= model |
---|
471 | self.set_panel(model) |
---|
472 | self.name= name |
---|
473 | self.model_view.SetFocus() |
---|
474 | self.parent.model_page.name=name |
---|
475 | self.parent.draw_model_name=name |
---|
476 | |
---|
477 | self._draw_model(name) |
---|
478 | |
---|
479 | |
---|
480 | def get_model_box(self): |
---|
481 | """ return reference to combox box self.model""" |
---|
482 | return self.modelbox |
---|
483 | |
---|
484 | |
---|
485 | def get_param_list(self): |
---|
486 | """ |
---|
487 | @return self.param_toFit: list containing references to TextCtrl |
---|
488 | checked.Theses TextCtrl will allow reference to parameters to fit. |
---|
489 | @raise: if return an empty list of parameter fit will nnote work |
---|
490 | properly so raise ValueError,"missing parameter to fit" |
---|
491 | """ |
---|
492 | if self.param_toFit !=[]: |
---|
493 | return self.param_toFit |
---|
494 | else: |
---|
495 | raise ValueError,"missing parameter to fit" |
---|
496 | |
---|
497 | |
---|
498 | def set_panel(self,model): |
---|
499 | """ |
---|
500 | Build the panel from the model content |
---|
501 | @param model: the model selected in combo box for fitting purpose |
---|
502 | """ |
---|
503 | |
---|
504 | self.sizer5.Clear(True) |
---|
505 | self.parameters = [] |
---|
506 | self.param_toFit=[] |
---|
507 | self.fixed_param=[] |
---|
508 | self.model = model |
---|
509 | |
---|
510 | self.set_model_description( self.model) |
---|
511 | |
---|
512 | keys = self.model.getParamList() |
---|
513 | #list of dispersion paramaters |
---|
514 | self.disp_list=self.model.getDispParamList() |
---|
515 | |
---|
516 | keys.sort() |
---|
517 | ik=0 |
---|
518 | im=1 |
---|
519 | |
---|
520 | iy = 1 |
---|
521 | ix = 0 |
---|
522 | self.cb1 = wx.CheckBox(self, -1,"Select all", (10, 10)) |
---|
523 | if self.data!=None: |
---|
524 | wx.EVT_CHECKBOX(self, self.cb1.GetId(), self.select_all_param) |
---|
525 | self.cb1.SetValue(False) |
---|
526 | else: |
---|
527 | self.cb1.Disable() |
---|
528 | self.cb1.Hide() |
---|
529 | |
---|
530 | self.sizer5.Add(self.cb1,(iy, ix),(1,1),\ |
---|
531 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
532 | ix +=1 |
---|
533 | self.text2_2 = wx.StaticText(self, -1, 'Values') |
---|
534 | self.sizer5.Add(self.text2_2,(iy, ix),(1,1),\ |
---|
535 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
536 | ix +=2 |
---|
537 | self.text2_3 = wx.StaticText(self, -1, 'Errors') |
---|
538 | self.sizer5.Add(self.text2_3,(iy, ix),(1,1),\ |
---|
539 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
540 | self.text2_3.Hide() |
---|
541 | |
---|
542 | |
---|
543 | ix +=1 |
---|
544 | self.text2_4 = wx.StaticText(self, -1, 'Units') |
---|
545 | self.sizer5.Add(self.text2_4,(iy, ix),(1,1),\ |
---|
546 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
547 | self.text2_4.Hide() |
---|
548 | disp_list=self.model.getDispParamList() |
---|
549 | for item in keys: |
---|
550 | if not item in disp_list: |
---|
551 | iy += 1 |
---|
552 | ix = 0 |
---|
553 | |
---|
554 | cb = wx.CheckBox(self, -1, item, (10, 10)) |
---|
555 | if self.data!=None: |
---|
556 | cb.SetValue(False) |
---|
557 | wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) |
---|
558 | else: |
---|
559 | cb.Disable() |
---|
560 | self.sizer5.Add( cb,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
561 | |
---|
562 | ix += 1 |
---|
563 | value= self.model.getParam(item) |
---|
564 | ctl1 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER) |
---|
565 | ctl1.SetValue(str (format_number(value))) |
---|
566 | ctl1.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
567 | ctl1.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) |
---|
568 | self.sizer5.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
569 | |
---|
570 | ix += 1 |
---|
571 | text2=wx.StaticText(self, -1, '+/-') |
---|
572 | self.sizer5.Add(text2,(iy, ix),(1,1),\ |
---|
573 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
574 | text2.Hide() |
---|
575 | ix += 1 |
---|
576 | ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER) |
---|
577 | self.sizer5.Add(ctl2, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
578 | ctl2.Hide() |
---|
579 | |
---|
580 | ix +=1 |
---|
581 | # Units |
---|
582 | try: |
---|
583 | units = wx.StaticText(self, -1, self.model.details[item][0], style=wx.ALIGN_LEFT) |
---|
584 | except: |
---|
585 | units = wx.StaticText(self, -1, "", style=wx.ALIGN_LEFT) |
---|
586 | self.sizer5.Add(units, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
587 | |
---|
588 | self.parameters.append([cb,ctl1,text2,ctl2]) |
---|
589 | |
---|
590 | iy+=1 |
---|
591 | self.sizer5.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
592 | |
---|
593 | #Display units text on panel |
---|
594 | for item in keys: |
---|
595 | if self.model.details[item][0]!='': |
---|
596 | self.text2_4.Show() |
---|
597 | break |
---|
598 | else: |
---|
599 | self.text2_4.Hide() |
---|
600 | |
---|
601 | self.vbox.Layout() |
---|
602 | self.SetScrollbars(20,20,55,40) |
---|
603 | self.Layout() |
---|
604 | self.parent.GetSizer().Layout() |
---|
605 | |
---|
606 | |
---|
607 | |
---|
608 | def _selectDlg(self): |
---|
609 | import os |
---|
610 | dlg = wx.FileDialog(self, "Choose a weight file", os.getcwd(), "", "*.*", wx.OPEN) |
---|
611 | path = None |
---|
612 | if dlg.ShowModal() == wx.ID_OK: |
---|
613 | path = dlg.GetPath() |
---|
614 | dlg.Destroy() |
---|
615 | return path |
---|
616 | def read_file(self, path): |
---|
617 | try: |
---|
618 | if path==None: |
---|
619 | wx.PostEvent(self.parent.parent, StatusEvent(status=\ |
---|
620 | " Selected Distribution was not loaded: %s"%path)) |
---|
621 | return None, None |
---|
622 | input_f = open(path, 'r') |
---|
623 | buff = input_f.read() |
---|
624 | lines = buff.split('\n') |
---|
625 | |
---|
626 | angles = [] |
---|
627 | weights=[] |
---|
628 | for line in lines: |
---|
629 | toks = line.split() |
---|
630 | if len(toks)==2: |
---|
631 | try: |
---|
632 | angle = float(toks[0]) |
---|
633 | weight = float(toks[1]) |
---|
634 | except: |
---|
635 | # Skip non-data lines |
---|
636 | pass |
---|
637 | angles.append(angle) |
---|
638 | weights.append(weight) |
---|
639 | return numpy.array(angles), numpy.array(weights) |
---|
640 | except: |
---|
641 | raise |
---|
642 | |
---|
643 | |
---|
644 | def select_disp_angle(self, event): |
---|
645 | """ |
---|
646 | Event for when a user select a parameter to average over. |
---|
647 | @param event: check box event |
---|
648 | """ |
---|
649 | |
---|
650 | |
---|
651 | # Go through the list of dispersion check boxes to identify which one has changed |
---|
652 | for p in self.disp_cb_dict: |
---|
653 | # Catch which one of the box was just checked or unchecked. |
---|
654 | if event.GetEventObject() == self.disp_cb_dict[p]: |
---|
655 | |
---|
656 | |
---|
657 | if self.disp_cb_dict[p].GetValue() == True: |
---|
658 | # The user wants this parameter to be averaged. |
---|
659 | # Pop up the file selection dialog. |
---|
660 | path = self._selectDlg() |
---|
661 | |
---|
662 | # If nothing was selected, just return |
---|
663 | if path is None: |
---|
664 | self.disp_cb_dict[p].SetValue(False) |
---|
665 | return |
---|
666 | |
---|
667 | try: |
---|
668 | values,weights = self.read_file(path) |
---|
669 | except: |
---|
670 | wx.PostEvent(self.parent.parent, StatusEvent(status=\ |
---|
671 | "Could not read input file")) |
---|
672 | return |
---|
673 | |
---|
674 | # If any of the two arrays is empty, notify the user that we won't |
---|
675 | # proceed |
---|
676 | if values is None or weights is None: |
---|
677 | wx.PostEvent(self.parent.parent, StatusEvent(status=\ |
---|
678 | "The loaded %s distrubtion is corrupted or empty" % p)) |
---|
679 | return |
---|
680 | |
---|
681 | # Tell the user that we are about to apply the distribution |
---|
682 | wx.PostEvent(self.parent.parent, StatusEvent(status=\ |
---|
683 | "Applying loaded %s distribution: %s" % (p, path))) |
---|
684 | |
---|
685 | # Create the dispersion objects |
---|
686 | disp_model = ArrayDispersion() |
---|
687 | disp_model.set_weights(values, weights) |
---|
688 | # Store the object to make it persist outside the scope of this method |
---|
689 | #TODO: refactor model to clean this up? |
---|
690 | self._disp_obj_dict[p] = disp_model |
---|
691 | |
---|
692 | # Set the new model as the dispersion object for the selected parameter |
---|
693 | self.model.set_dispersion(p, disp_model) |
---|
694 | |
---|
695 | |
---|
696 | # Redraw the model |
---|
697 | self._draw_model() |
---|
698 | |
---|
699 | else: |
---|
700 | # The parameter was un-selected. Go back to Gaussian model (with 0 pts) |
---|
701 | disp_model = GaussianDispersion() |
---|
702 | # Store the object to make it persist outside the scope of this method |
---|
703 | #TODO: refactor model to clean this up? |
---|
704 | self._disp_obj_dict[p] = disp_model |
---|
705 | |
---|
706 | # Set the new model as the dispersion object for the selected parameter |
---|
707 | self.model.set_dispersion(p, disp_model) |
---|
708 | |
---|
709 | # Redraw the model |
---|
710 | self._draw_model() |
---|
711 | return |
---|
712 | |
---|
713 | |
---|
714 | |
---|
715 | |
---|
716 | def set_panel_dispers(self, disp_list, type="GaussianModel" ): |
---|
717 | """ |
---|
718 | """ |
---|
719 | |
---|
720 | self.fittable_param=[] |
---|
721 | self.fixed_param=[] |
---|
722 | |
---|
723 | ix=0 |
---|
724 | iy=1 |
---|
725 | ### this will become a separate method |
---|
726 | if type== "Select customized Model": |
---|
727 | ix=0 |
---|
728 | iy=1 |
---|
729 | self.sizer8.Clear(True) |
---|
730 | disp1 = wx.StaticText(self, -1, 'Array Dispersion') |
---|
731 | self.sizer8.Add(disp1,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
732 | |
---|
733 | # Look for model parameters to which we can apply an ArrayDispersion model |
---|
734 | # Add a check box for each parameter. |
---|
735 | self.disp_cb_dict = {} |
---|
736 | for p in self.model.dispersion.keys(): |
---|
737 | ix+=1 |
---|
738 | self.disp_cb_dict[p] = wx.CheckBox(self, -1, p, (10, 10)) |
---|
739 | |
---|
740 | wx.EVT_CHECKBOX(self, self.disp_cb_dict[p].GetId(), self.select_disp_angle) |
---|
741 | self.sizer8.Add(self.disp_cb_dict[p], (iy, ix), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
742 | |
---|
743 | ix =0 |
---|
744 | iy +=1 |
---|
745 | self.sizer8.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
746 | self.vbox.Layout() |
---|
747 | self.SetScrollbars(20,20,55,40) |
---|
748 | self.Layout() |
---|
749 | self.parent.GetSizer().Layout() |
---|
750 | |
---|
751 | if type== "GaussianModel" : |
---|
752 | |
---|
753 | self.sizer8.Clear(True) |
---|
754 | disp = wx.StaticText(self, -1, 'Dispersion') |
---|
755 | self.sizer8.Add(disp,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
756 | ix += 1 |
---|
757 | values = wx.StaticText(self, -1, 'Values') |
---|
758 | self.sizer8.Add(values,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
759 | ix +=2 |
---|
760 | self.text2_3 = wx.StaticText(self, -1, 'Errors') |
---|
761 | self.sizer8.Add(self.text2_3,(iy, ix),(1,1),\ |
---|
762 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
763 | self.text2_3.Hide() |
---|
764 | |
---|
765 | ix += 1 |
---|
766 | npts = wx.StaticText(self, -1, 'Npts') |
---|
767 | self.sizer8.Add(npts,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
768 | ix += 1 |
---|
769 | nsigmas = wx.StaticText(self, -1, 'Nsigmas') |
---|
770 | self.sizer8.Add(nsigmas,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
771 | |
---|
772 | disp_list.sort() |
---|
773 | #print disp_list,self.model.dispersion |
---|
774 | for item in self.model.dispersion.keys(): |
---|
775 | name1=item+".width" |
---|
776 | name2=item+".npts" |
---|
777 | name3=item+".nsigmas" |
---|
778 | iy += 1 |
---|
779 | for p in self.model.dispersion[item].keys(): |
---|
780 | #print "name 1 2 3", name1, name2, name3 |
---|
781 | if p=="width": |
---|
782 | ix = 0 |
---|
783 | cb = wx.CheckBox(self, -1, name1, (10, 10)) |
---|
784 | if self.data !=None: |
---|
785 | cb.SetValue(False) |
---|
786 | wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) |
---|
787 | else: |
---|
788 | cb.Disable() |
---|
789 | self.sizer8.Add( cb,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
790 | ix = 1 |
---|
791 | value= self.model.getParam(name1) |
---|
792 | ctl1 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER) |
---|
793 | ctl1.SetValue(str (format_number(value))) |
---|
794 | ctl1.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
795 | ctl1.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) |
---|
796 | self.sizer8.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
797 | |
---|
798 | ix = 2 |
---|
799 | text2=wx.StaticText(self, -1, '+/-') |
---|
800 | self.sizer8.Add(text2,(iy, ix),(1,1),\ |
---|
801 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
802 | text2.Hide() |
---|
803 | ix = 3 |
---|
804 | ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER) |
---|
805 | self.sizer8.Add(ctl2, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
806 | ctl2.Hide() |
---|
807 | self.fittable_param.append([cb,ctl1,text2,ctl2]) |
---|
808 | |
---|
809 | |
---|
810 | elif p=="npts": |
---|
811 | ix =4 |
---|
812 | value= self.model.getParam(name2) |
---|
813 | Tctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER) |
---|
814 | Tctl.SetValue(str (format_number(value))) |
---|
815 | Tctl.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
816 | Tctl.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) |
---|
817 | self.sizer8.Add(Tctl, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
818 | self.fixed_param.append([name2, Tctl]) |
---|
819 | elif p=="nsigmas": |
---|
820 | ix =5 |
---|
821 | value= self.model.getParam(name3) |
---|
822 | Tctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER) |
---|
823 | Tctl.SetValue(str (format_number(value))) |
---|
824 | Tctl.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
825 | Tctl.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) |
---|
826 | self.sizer8.Add(Tctl, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
827 | self.fixed_param.append([name3, Tctl]) |
---|
828 | wx.PostEvent(self.parent.parent, StatusEvent(status=\ |
---|
829 | " Selected Distribution: Gaussian")) |
---|
830 | ix =0 |
---|
831 | iy +=1 |
---|
832 | self.sizer8.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
833 | self.vbox.Layout() |
---|
834 | self.SetScrollbars(20,20,55,40) |
---|
835 | self.Layout() |
---|
836 | self.parent.GetSizer().Layout() |
---|
837 | |
---|
838 | def checkFitValues(self,val_min, val_max): |
---|
839 | """ |
---|
840 | Check the validity of input values |
---|
841 | """ |
---|
842 | flag = True |
---|
843 | min_value = val_min.GetValue() |
---|
844 | max_value = val_max.GetValue() |
---|
845 | # Check for possible values entered |
---|
846 | if min_value.lstrip().rstrip() =="-inf": |
---|
847 | min_value= -numpy.inf |
---|
848 | if max_value.lstrip().rstrip() =="+inf": |
---|
849 | max_value= numpy.inf |
---|
850 | if min_value==-numpy.inf and max_value== numpy.inf: |
---|
851 | val_min.SetBackgroundColour(wx.WHITE) |
---|
852 | val_min.Refresh() |
---|
853 | val_max.SetBackgroundColour(wx.WHITE) |
---|
854 | val_max.Refresh() |
---|
855 | return flag |
---|
856 | elif max_value== numpy.inf: |
---|
857 | try: |
---|
858 | float(min_value) |
---|
859 | val_min.SetBackgroundColour(wx.WHITE) |
---|
860 | val_min.Refresh() |
---|
861 | except: |
---|
862 | flag = False |
---|
863 | val_min.SetBackgroundColour("pink") |
---|
864 | val_min.Refresh() |
---|
865 | return flag |
---|
866 | elif min_value==-numpy.inf: |
---|
867 | try: |
---|
868 | float(max_value) |
---|
869 | val_max.SetBackgroundColour(wx.WHITE) |
---|
870 | val_max.Refresh() |
---|
871 | except: |
---|
872 | flag = False |
---|
873 | val_max.SetBackgroundColour("pink") |
---|
874 | val_max.Refresh() |
---|
875 | return flag |
---|
876 | else: |
---|
877 | if (float(min_value)< float(max_value)): |
---|
878 | val_min.SetBackgroundColour(wx.WHITE) |
---|
879 | val_min.Refresh() |
---|
880 | else: |
---|
881 | flag = False |
---|
882 | val_min.SetBackgroundColour("pink") |
---|
883 | val_min.Refresh() |
---|
884 | return flag |
---|
885 | |
---|
886 | |
---|
887 | def _onparamEnter(self,event): |
---|
888 | """ |
---|
889 | when enter value on panel redraw model according to changed |
---|
890 | """ |
---|
891 | self.set_model_parameter() |
---|
892 | |
---|
893 | def set_model_parameter(self): |
---|
894 | """ |
---|
895 | """ |
---|
896 | if len(self.parameters) !=0 and self.model !=None: |
---|
897 | # Flag to register when a parameter has changed. |
---|
898 | is_modified = False |
---|
899 | for item in self.fittable_param: |
---|
900 | try: |
---|
901 | name=str(item[0].GetLabelText()) |
---|
902 | value= float(item[1].GetValue()) |
---|
903 | # If the value of the parameter has changed, |
---|
904 | # update the model and set the is_modified flag |
---|
905 | if value != self.model.getParam(name): |
---|
906 | self.model.setParam(name,value) |
---|
907 | is_modified = True |
---|
908 | |
---|
909 | except: |
---|
910 | #raise |
---|
911 | wx.PostEvent(self.parent.parent, StatusEvent(status=\ |
---|
912 | "Model Drawing Error:wrong value entered : %s"% sys.exc_value)) |
---|
913 | return |
---|
914 | |
---|
915 | |
---|
916 | for item in self.fixed_param: |
---|
917 | try: |
---|
918 | name=str(item[0]) |
---|
919 | value= float(item[1].GetValue()) |
---|
920 | # If the value of the parameter has changed, |
---|
921 | # update the model and set the is_modified flag |
---|
922 | if value != self.model.getParam(name): |
---|
923 | self.model.setParam(name,value) |
---|
924 | is_modified = True |
---|
925 | |
---|
926 | except: |
---|
927 | raise |
---|
928 | wx.PostEvent(self.parent.parent, StatusEvent(status=\ |
---|
929 | "Model Drawing Error:wrong value entered : %s"% sys.exc_value)) |
---|
930 | |
---|
931 | for item in self.parameters: |
---|
932 | try: |
---|
933 | name=str(item[0].GetLabelText()) |
---|
934 | value= float(item[1].GetValue()) |
---|
935 | # If the value of the parameter has changed, |
---|
936 | # update the model and set the is_modified flag |
---|
937 | if value != self.model.getParam(name): |
---|
938 | self.model.setParam(name,value) |
---|
939 | is_modified = True |
---|
940 | |
---|
941 | except: |
---|
942 | #raise |
---|
943 | wx.PostEvent(self.parent.parent, StatusEvent(status=\ |
---|
944 | "Model Drawing Error:wrong value entered : %s"% sys.exc_value)) |
---|
945 | return |
---|
946 | |
---|
947 | |
---|
948 | # Here we should check whether the boundaries have been modified. |
---|
949 | # If qmin and qmax have been modified, update qmin and qmax and |
---|
950 | # set the is_modified flag to True |
---|
951 | if float(self.qmin.GetValue()) != self.qmin_x: |
---|
952 | self.qmin_x = float(self.qmin.GetValue()) |
---|
953 | is_modified = True |
---|
954 | if float(self.qmax.GetValue()) != self.qmax_x: |
---|
955 | self.qmax_x = float(self.qmax.GetValue()) |
---|
956 | is_modified = True |
---|
957 | |
---|
958 | if float(self.npts.GetValue()) != self.num_points: |
---|
959 | self.num_points = float(self.npts.GetValue()) |
---|
960 | is_modified = True |
---|
961 | |
---|
962 | if is_modified: |
---|
963 | self._draw_model() |
---|
964 | |
---|
965 | def _draw_model(self, name=None): |
---|
966 | """ |
---|
967 | Method to draw or refresh a plotted model. |
---|
968 | The method will use the data member from the model page |
---|
969 | to build a call to the fitting perspective manager. |
---|
970 | |
---|
971 | [Note to coder: This way future changes will be done in only one place.] |
---|
972 | """ |
---|
973 | if name==None: |
---|
974 | name= self.model.name |
---|
975 | |
---|
976 | self.manager.draw_model(self.model, name, data=self.data, |
---|
977 | qmin=self.qmin_x, qmax=self.qmax_x, |
---|
978 | qstep= self.num_points, |
---|
979 | enable2D=self.enable2D) |
---|
980 | |
---|
981 | def select_param(self,event): |
---|
982 | """ |
---|
983 | |
---|
984 | """ |
---|
985 | pass |
---|
986 | def select_all_param(self,event): |
---|
987 | """ |
---|
988 | |
---|
989 | """ |
---|
990 | pass |
---|
991 | def select_all_param_helper(self): |
---|
992 | """ |
---|
993 | Allows selecting or delecting button |
---|
994 | """ |
---|
995 | self.param_toFit=[] |
---|
996 | if self.parameters !=[]: |
---|
997 | if self.cb1.GetValue()==True: |
---|
998 | for item in self.parameters: |
---|
999 | item[0].SetValue(True) |
---|
1000 | list= [item[0],item[1],item[2],item[3]] |
---|
1001 | self.param_toFit.append(list ) |
---|
1002 | if len(self.fittable_param)>0: |
---|
1003 | for item in self.fittable_param: |
---|
1004 | item[0].SetValue(True) |
---|
1005 | list= [item[0],item[1],item[2],item[3]] |
---|
1006 | self.param_toFit.append(list ) |
---|
1007 | else: |
---|
1008 | for item in self.parameters: |
---|
1009 | item[0].SetValue(False) |
---|
1010 | for item in self.fittable_param: |
---|
1011 | item[0].SetValue(False) |
---|
1012 | self.param_toFit=[] |
---|
1013 | |
---|
1014 | |
---|
1015 | |
---|