source: sasview/sansview/perspectives/fitting/simfitpage.py @ 29ef718

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 29ef718 was 66ff250, checked in by Gervaise Alina <gervyh@…>, 14 years ago

working on fit stop

  • Property mode set to 100644
File size: 23.9 KB
RevLine 
[d89f09b]1
[2140e68]2import sys,re,string, wx 
3import wx.lib.newevent 
[4ce74917]4from sans.guiframe.events import StatusEvent
[c99a6c5]5   
6#Control panel width
[6e9976b]7if sys.platform.count("darwin")==0:
[c99a6c5]8    PANEL_WID = 420
[f1aa385]9    FONT_VARIANT = 0
[c99a6c5]10else:
11    PANEL_WID = 490
[f1aa385]12    FONT_VARIANT = 1
[8bd4dc0]13           
14def get_fittableParam( model):
[2140e68]15    """
[5062bbf]16    return list of fittable parameters name of a model
17   
18    :param model: the model used
19   
[2140e68]20    """
[8bd4dc0]21    fittable_param=[]
22   
23    for item in model.getParamList():
24        if not item  in model.getDispParamList():
[fb59ed9]25            if not item in model.non_fittable:
26                fittable_param.append(item)
[8bd4dc0]27           
28    for item in model.fixed:
29        fittable_param.append(item)
[2140e68]30       
[8bd4dc0]31    return fittable_param
[2140e68]32
[3aae6b6]33class SimultaneousFitPage(wx.ScrolledWindow):
[d89f09b]34    """
[5062bbf]35    Simultaneous fitting panel
36    All that needs to be defined are the
37    two data members window_name and window_caption
[d89f09b]38    """
[925a30e]39    ## Internal name for the AUI manager
[d89f09b]40    window_name = "simultaneous Fit page"
41    ## Title to appear on top of the window
42    window_caption = "Simultaneous Fit Page"
43   
44   
[2140e68]45    def __init__(self, parent,page_finder ={}, *args, **kwargs):
[e814734]46        wx.ScrolledWindow.__init__(self, parent,style= wx.FULL_REPAINT_ON_RESIZE )
[d89f09b]47        """
[5062bbf]48        Simultaneous page display
[d89f09b]49        """
[f1aa385]50        ##Font size
51        self.SetWindowVariant(variant = FONT_VARIANT)
[6bbeacd4]52        self.id = None
[d89f09b]53        self.parent = parent
[2140e68]54        ## store page_finder
[b28717b]55        self.page_finder = page_finder
[2140e68]56        ## list contaning info to set constraint
[6bbeacd4]57        ## look like self.constraint_dict[page_id]= page
[2140e68]58        self.constraint_dict={}
59        ## item list  self.constraints_list=[combobox1, combobox2,=,textcrtl, button ]
60        self.constraints_list=[]
61        ## list of current model
62        self.model_list=[]
63        ## selected mdoel to fit
64        self.model_toFit=[]
[b28717b]65        ## number of constraint
66        self.nb_constraint= 0
[66ff250]67        self.id = wx.NewId()
[b28717b]68        ## draw page
[2140e68]69        self.define_page_structure()
[b28717b]70        self.draw_page()
[2140e68]71        self.set_layout()
72       
73    def define_page_structure(self):
74        """
[5062bbf]75        Create empty sizer for a panel
[2140e68]76        """
[d89f09b]77        self.vbox  = wx.BoxSizer(wx.VERTICAL)
[2140e68]78        self.sizer1 = wx.BoxSizer(wx.VERTICAL)
79        self.sizer2 = wx.BoxSizer(wx.VERTICAL)
[8bd4dc0]80        self.sizer3 = wx.BoxSizer(wx.VERTICAL)
[c99a6c5]81
82        self.sizer1.SetMinSize((PANEL_WID,-1))
83        self.sizer2.SetMinSize((PANEL_WID,-1))
84        self.sizer3.SetMinSize((PANEL_WID,-1))
[d89f09b]85        self.vbox.Add(self.sizer1)
86        self.vbox.Add(self.sizer2)
[8bd4dc0]87        self.vbox.Add(self.sizer3)
[51d47b5]88       
[2140e68]89    def set_scroll(self):
[5062bbf]90        """
91        """
[c99a6c5]92        self.SetScrollbars(20,20,25,65)
[2140e68]93        self.Layout() 
94         
95    def set_layout(self):
96        """
[5062bbf]97        layout
[2140e68]98        """
[d89f09b]99        self.vbox.Layout()
100        self.vbox.Fit(self) 
101        self.SetSizer(self.vbox)
[2140e68]102        self.set_scroll()
[d89f09b]103        self.Centre()
104       
[8bd4dc0]105    def onRemove(self, event):
106        """
[5062bbf]107        Remove constraint fields
[8bd4dc0]108        """
[a911b48]109        if len(self.constraints_list)==1:
110            self.hide_constraint.SetValue(True)
111            self._hide_constraint()
112            return 
113        if len(self.constraints_list)==0:
[8bd4dc0]114            return 
115        for item in self.constraints_list:
116            length= len(item)
117            if event.GetId()==item[length-2].GetId():
118                sizer= item[length-1]
[bb7d8a4]119                sizer.Clear(True)
[8bd4dc0]120                self.sizer_constraints.Remove(sizer)
[998b6b8]121             
[8bd4dc0]122                self.sizer2.Layout()
[c99a6c5]123                self.SetScrollbars(20,20,25,65)
[8bd4dc0]124                self.constraints_list.remove(item)
125                self.nb_constraint -= 1
126                break
127               
[d89f09b]128    def onFit(self,event):
[5062bbf]129        """
130        signal for fitting
131       
132        """
[2140e68]133        ## making sure all parameters content a constraint
134        ## validity of the constraint expression is own by fit engine
[ac11e40]135        if self.show_constraint.GetValue():
136            self._set_constraint()
[2140e68]137        ## get the fit range of very fit problem       
[6bbeacd4]138        for id, value in self.page_finder.iteritems():
139            qmin, qmax= self.page_finder[id].get_range()
[2140e68]140            value.set_range(qmin, qmax)
141        ## model was actually selected from this page to be fit
[3215d32]142        if len(self.model_toFit) >= 1 :
[66ff250]143            self.manager._reset_schedule_problem(value=0)
[6f023e8]144            for item in self.model_list:
145                if item[0].GetValue():
146                    self.manager.schedule_for_fit( value=1,fitproblem =item[1]) 
[ca7a626]147            self.manager.onFit()
[1b07935d]148        else:
[2140e68]149            msg= "Select at least one model to fit "
150            wx.PostEvent(self.parent.Parent, StatusEvent(status= msg ))
[f343069]151           
[d89f09b]152    def set_manager(self, manager):
153        """
[5062bbf]154        set panel manager
155       
156        :param manager: instance of plugin fitting
157       
[d89f09b]158        """
159        self.manager = manager
[b28717b]160       
[2140e68]161    def check_all_model_name(self,event):
[d89f09b]162        """
[5062bbf]163        check all models names
[d89f09b]164        """
[6bbeacd4]165        self.model_toFit = [] 
166        if self.cb1.GetValue()== True:
[d89f09b]167            for item in self.model_list:
168                item[0].SetValue(True)
169                self.model_toFit.append(item)
[2140e68]170               
171            ## constraint info
172            self._store_model()
173            ## display constraint fields
174            if self.show_constraint.GetValue():
175                self._show_constraint()
176                return
[d89f09b]177        else:
178            for item in self.model_list:
179                item[0].SetValue(False) 
[948add7]180               
[d89f09b]181            self.model_toFit=[]
[2140e68]182            ##constraint info
183            self._hide_constraint()
[925a30e]184       
[2140e68]185    def check_model_name(self,event):
[d89f09b]186        """
[5062bbf]187        Save information related to checkbox and their states
[d89f09b]188        """
189        self.model_toFit=[]
190        for item in self.model_list:
191            if item[0].GetValue()==True:
192                self.model_toFit.append(item)
193            else:
194                if item in self.model_toFit:
195                    self.model_toFit.remove(item)
196                    self.cb1.SetValue(False)
[b28717b]197       
[2140e68]198        ## display constraint fields
[b28717b]199        if len(self.model_toFit)==2:
[2140e68]200            self._store_model()
[b28717b]201            if self.show_constraint.GetValue() and len(self.constraints_list)==0:
[2140e68]202                self._show_constraint()
[b28717b]203        elif len(self.model_toFit)< 2:
204            ##constraint info
205            self._hide_constraint()             
[2140e68]206       
207        ## set the value of the main check button         
[d89f09b]208        if len(self.model_list)==len(self.model_toFit):
209            self.cb1.SetValue(True)
[b28717b]210            return
[d89f09b]211        else:
212            self.cb1.SetValue(False)
[948add7]213       
[b28717b]214    def draw_page(self):     
[2140e68]215        """
[5062bbf]216        Draw a sizer containing couples of data and model
[b28717b]217        """ 
[2140e68]218        self.model_list=[]
219        self.model_toFit=[]
[8bd4dc0]220        self.constraints_list=[]
[1d2782d]221        self.constraint_dict={}
222        self.nb_constraint= 0
223       
[2140e68]224        if len(self.model_list)>0:
225            for item in self.model_list:
226                item[0].SetValue(False) 
227                self.manager.schedule_for_fit( value=0,fitproblem =item[1])
228               
[5062bbf]229        self.sizer1.Clear(True)   
[8bd4dc0]230        box_description= wx.StaticBox(self, -1,"Fit Combinations")
[2140e68]231        boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL)
232        sizer_title = wx.BoxSizer(wx.HORIZONTAL)
233        sizer_couples = wx.GridBagSizer(5,5)
234        #------------------------------------------------------
235        if len(self.page_finder)==0:
[c99a6c5]236            sizer_title.Add(wx.StaticText(self,-1," No fit combinations are found!"))
[2140e68]237        else:
238            ## store model 
239            self._store_model()
240       
[8bd4dc0]241            self.cb1 = wx.CheckBox(self, -1,'Select all')
[2140e68]242            self.cb1.SetValue(False)
243            wx.EVT_CHECKBOX(self, self.cb1.GetId(), self.check_all_model_name)
244           
[8bd4dc0]245            sizer_title.Add((10,10),0,
246                wx.TOP|wx.BOTTOM|wx.EXPAND|wx.ADJUST_MINSIZE,border=5)
247            sizer_title.Add(self.cb1,0,
248                wx.TOP|wx.BOTTOM|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE,border=5)
249           
250            ## draw list of model and data name
[2140e68]251            self._fill_sizer_model_list(sizer_couples)
252            ## draw the sizer containing constraint info
253            self._fill_sizer_constraint()
[8bd4dc0]254            ## draw fit button
255            self._fill_sizer_fit()
[2140e68]256        #--------------------------------------------------------
[8bd4dc0]257        boxsizer1.Add(sizer_title, flag= wx.TOP|wx.BOTTOM,border=5) 
258        boxsizer1.Add(sizer_couples, flag= wx.TOP|wx.BOTTOM,border=5)
[2140e68]259       
[8bd4dc0]260        self.sizer1.Add(boxsizer1,1, wx.EXPAND | wx.ALL, 10)
[2140e68]261        self.sizer1.Layout()
[c99a6c5]262        self.SetScrollbars(20,20,25,65)
[2140e68]263        self.AdjustScrollbars()
264       
265    def _store_model(self):
[d89f09b]266        """
[5062bbf]267         Store selected model
[d89f09b]268        """
[2140e68]269        if len(self.model_toFit) < 2:
270            return
[1d2782d]271        for item in self.model_toFit:
272            model = item[3]
[6bbeacd4]273            page_id= item[2]
274            self.constraint_dict[page_id] = model
[2140e68]275                   
276    def _display_constraint(self, event):
277        """
[5062bbf]278        Show fields to add constraint
[2140e68]279        """
280        if len(self.model_toFit)< 2:
281            msg= "Select at least 2 models to add constraint "
282            wx.PostEvent(self.parent.Parent, StatusEvent(status= msg ))
283            ## hide button
284            self._hide_constraint()
285            return
286        if self.show_constraint.GetValue():
287            self._show_constraint()
288            return
289        else:
290           self._hide_constraint()
291           return 
292           
293    def _show_constraint(self):
294        """
[5062bbf]295        Show constraint fields
[2140e68]296        """
[77e23a2]297        self.btAdd.Show(True)
[2140e68]298        if len(self.constraints_list)!= 0:
299            nb_fit_param = 0
[1d2782d]300            for model in self.constraint_dict.values():
[8bd4dc0]301                nb_fit_param += len(get_fittableParam(model))
[2140e68]302            ##Don't add anymore
303            if len(self.constraints_list) == nb_fit_param:
[ac11e40]304                msg= "Cannot add another constraint .Maximum of number "
305                msg += "Parameters name reached %s"%str(nb_fit_param)
306                wx.PostEvent(self.parent.Parent, StatusEvent(status= msg ))
[b28717b]307                self.sizer_constraints.Layout()
[ac11e40]308                self.sizer2.Layout()
[c99a6c5]309                self.SetScrollbars(20,20,25,65)
[ac11e40]310                return
311           
312        if len(self.model_toFit) < 2 :
[2140e68]313            msg= "Select at least 2 model to add constraint "
314            wx.PostEvent(self.parent.Parent, StatusEvent(status= msg ))
[b28717b]315            self.sizer_constraints.Layout()
[2140e68]316            self.sizer2.Layout()
[c99a6c5]317            self.SetScrollbars(20,20,25,65)
[2140e68]318            return
319           
320        sizer_constraint =  wx.BoxSizer(wx.HORIZONTAL)
[8bd4dc0]321        model_cbox = wx.ComboBox(self, -1,style=wx.CB_READONLY)
[2140e68]322        model_cbox.Clear()
[8bd4dc0]323        param_cbox = wx.ComboBox(self, -1,style=wx.CB_READONLY)
[b28717b]324        param_cbox.Hide()
[8dfe0fd]325       
326        #This is for GetCLientData() _on_select_param: Was None return on MAC.
327        self.param_cbox = param_cbox
328       
[2140e68]329        wx.EVT_COMBOBOX(param_cbox,-1, self._on_select_param)
330        ctl2 = wx.TextCtrl(self, -1)
331        egal_txt= wx.StaticText(self,-1," = ")
[8bd4dc0]332        btRemove = wx.Button(self,wx.NewId(),'Remove')
333        btRemove.Bind(wx.EVT_BUTTON, self.onRemove,id= btRemove.GetId())
334        btRemove.SetToolTipString("Remove constraint.")
[2140e68]335       
[6bbeacd4]336        for id,model in self.constraint_dict.iteritems():
[2140e68]337            ## check if all parameters have been selected for constraint
338            ## then do not allow add constraint on parameters
[ac11e40]339            model_cbox.Append( str(model.name), model)
[2140e68]340           
[8dfe0fd]341        #This is for GetCLientData() passing to self._on_select_param: Was None return on MAC.
342        self.model_cbox = model_cbox
[2140e68]343           
344        wx.EVT_COMBOBOX(model_cbox,-1, self._on_select_model)
[5062bbf]345   
[b28717b]346        sizer_constraint.Add(model_cbox, flag= wx.RIGHT|wx.EXPAND,border=10)
347        sizer_constraint.Add(param_cbox, flag= wx.RIGHT|wx.EXPAND,border=5)
348        sizer_constraint.Add(egal_txt, flag= wx.RIGHT|wx.EXPAND,border=5)
349        sizer_constraint.Add(ctl2, flag= wx.RIGHT|wx.EXPAND,border=10)
[8bd4dc0]350        sizer_constraint.Add(btRemove, flag= wx.RIGHT|wx.EXPAND,border=10)
[b28717b]351     
352        self.sizer_constraints.Insert(before=self.nb_constraint,
353                                      item=sizer_constraint, flag= wx.TOP|wx.BOTTOM|wx.EXPAND,
[8bd4dc0]354                                   border=5)
355        ##[combobox1, combobox2,=,textcrtl, remove button ]
356        self.constraints_list.append([model_cbox, param_cbox, egal_txt, ctl2,btRemove,sizer_constraint])
[5062bbf]357   
[b28717b]358        self.nb_constraint += 1
359        self.sizer_constraints.Layout()
[2140e68]360        self.sizer2.Layout()
[c99a6c5]361        self.SetScrollbars(20,20,25,65)
[2140e68]362       
363    def _hide_constraint(self): 
364        """
[5062bbf]365        hide buttons related constraint
[ac11e40]366        """ 
[6bbeacd4]367        for id in  self.page_finder.iterkeys():
368            self.page_finder[id].clear_model_param()
[b28717b]369               
370        self.nb_constraint =0     
[ac11e40]371        self.constraint_dict={}
[69bee6d]372        if hasattr(self,"btAdd"):
373            self.btAdd.Hide()
[ac11e40]374        self._store_model()
[2140e68]375        self.constraints_list=[]         
[b28717b]376        self.sizer_constraints.Clear(True) 
377        self.sizer_constraints.Layout()   
[2140e68]378        self.sizer2.Layout()
[c99a6c5]379        self.SetScrollbars(20,20,25,65)
[2140e68]380        self.AdjustScrollbars()   
[5062bbf]381           
[2140e68]382    def _on_select_model(self, event):
383        """
[5062bbf]384        fill combox box with list of parameters
[2140e68]385        """
[8dfe0fd]386        ##This way PC/MAC both work, instead of using event.GetClientData().
387        n = self.model_cbox.GetCurrentSelection()
388        model = self.model_cbox.GetClientData(n)
389       
[8bd4dc0]390        param_list= get_fittableParam(model)
[2140e68]391        length = len(self.constraints_list)
392        if length < 1:
393            return 
394        param_cbox = self.constraints_list[length-1][1]
395        param_cbox.Clear()
396        ## insert only fittable paramaters
397        for param in param_list:
[ac11e40]398            param_cbox.Append( str(param), model)
399           
[2140e68]400        param_cbox.Show(True)
401        self.sizer2.Layout()
[c99a6c5]402        self.SetScrollbars(20,20,25,65)
[2140e68]403       
404    def _on_select_param(self, event):
405        """
[5062bbf]406        Store the appropriate constraint in the page_finder
[2140e68]407        """
[8dfe0fd]408        ##This way PC/MAC both work, instead of using event.GetClientData().
409        n = self.param_cbox.GetCurrentSelection()
410        model = self.param_cbox.GetClientData(n)
[2140e68]411        param = event.GetString()
[ac11e40]412     
[2140e68]413        length = len(self.constraints_list)
414        if length < 1:
415            return 
416        egal_txt = self.constraints_list[length-1][2]
417        egal_txt.Show(True)       
418       
419        ctl2 = self.constraints_list[length-1][3]
420        ctl2.Show(True)
[6e9976b]421        #self.sizer2.Layout()
[c99a6c5]422        self.SetScrollbars(20,20,25,65)
[2140e68]423       
424    def _onAdd_constraint(self, event): 
425        """
[5062bbf]426        Add another line for constraint
[2140e68]427        """
[8bd4dc0]428        if not self.show_constraint.GetValue():
429            msg= " Select Yes to add Constraint "
430            wx.PostEvent(self.parent.Parent, StatusEvent(status= msg ))
431            return 
[2140e68]432        ## check that a constraint is added before allow to add another cosntraint
433        for item in self.constraints_list:
434            model_cbox = item[0]
435            if model_cbox.GetString(0)=="":
436                msg= " Select a model Name! "
437                wx.PostEvent(self.parent.Parent, StatusEvent(status= msg ))
438                return 
439            param_cbox = item[1]
440            if param_cbox.GetString(0)=="":
441                msg= " Select a parameter Name! "
442                wx.PostEvent(self.parent.Parent, StatusEvent(status= msg ))
443                return 
444            ctl2 = item[3]
445            if ctl2.GetValue().lstrip().rstrip()=="":
[b28717b]446                model= param_cbox.GetClientData(param_cbox.GetCurrentSelection())
447                msg= " Enter a constraint for %s.%s! "%(model.name,param_cbox.GetString(0))           
448                wx.PostEvent(self.parent.Parent, StatusEvent(status= msg ))
449                return 
[2140e68]450        ## some model or parameters can be constrained
451        self._show_constraint()
452       
[8bd4dc0]453    def _fill_sizer_fit(self):
454        """
[5062bbf]455        Draw fit button
[8bd4dc0]456        """
457        self.sizer3.Clear(True)
458        box_description= wx.StaticBox(self, -1,"Fit ")
459        boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL)
460        sizer_button = wx.BoxSizer(wx.HORIZONTAL)
461         
462        self.btFit = wx.Button(self,wx.NewId(),'Fit')
463        self.btFit.Bind(wx.EVT_BUTTON, self.onFit,id= self.btFit.GetId())
464        self.btFit.SetToolTipString("Perform fit.")
[2140e68]465       
[8bd4dc0]466        text= "Hint: Park fitting engine will be selected \n"
467        text+= "automatically for more than 2 combinations checked"
468        text_hint = wx.StaticText(self,-1,text)
469       
470        sizer_button.Add(text_hint,  wx.RIGHT|wx.EXPAND, 10)
471        sizer_button.Add(self.btFit, 0, wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10)
472       
473        boxsizer1.Add(sizer_button, flag= wx.TOP|wx.BOTTOM,border=10)
474        self.sizer3.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10)
475        self.sizer3.Layout()
[c99a6c5]476        self.SetScrollbars(20,20,25,65)
[2140e68]477       
478    def _fill_sizer_constraint(self):
479        """
[5062bbf]480        Fill sizer containing constraint info
[2140e68]481        """
[5062bbf]482        msg = "Select at least 2 model to add constraint "
[2140e68]483        wx.PostEvent(self.parent.Parent, StatusEvent(status= msg ))
484       
485        self.sizer2.Clear(True)
486        box_description= wx.StaticBox(self, -1,"Fit Constraints")
487        boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL)
488        sizer_title = wx.BoxSizer(wx.HORIZONTAL)
[b28717b]489        self.sizer_constraints = wx.BoxSizer(wx.VERTICAL)
[2140e68]490        sizer_button = wx.BoxSizer(wx.HORIZONTAL)
491       
492        self.hide_constraint = wx.RadioButton(self, -1, 'No', (10, 10), style=wx.RB_GROUP)
493        self.show_constraint = wx.RadioButton(self, -1, 'Yes', (10, 30))
494        self.Bind( wx.EVT_RADIOBUTTON, self._display_constraint,
495                    id= self.hide_constraint.GetId() )
496        self.Bind(  wx.EVT_RADIOBUTTON, self._display_constraint,
497                         id= self.show_constraint.GetId()    )
[17c5868]498        self.hide_constraint.SetValue(True)
[2140e68]499        sizer_title.Add( wx.StaticText(self,-1," Model") )
500        sizer_title.Add(( 10,10) )
501        sizer_title.Add( wx.StaticText(self,-1," Parameter") )
502        sizer_title.Add(( 10,10) )
503        sizer_title.Add( wx.StaticText(self,-1," Add Constraint?") )
504        sizer_title.Add(( 10,10) )
505        sizer_title.Add( self.show_constraint )
506        sizer_title.Add( self.hide_constraint )
507        sizer_title.Add(( 10,10) )
508       
509        self.btAdd =wx.Button(self,wx.NewId(),'Add')
510        self.btAdd.Bind(wx.EVT_BUTTON, self._onAdd_constraint,id= self.btAdd.GetId())
511        self.btAdd.SetToolTipString("Add another constraint?")
[77e23a2]512        self.btAdd.Hide()
[8bd4dc0]513     
[d5fd5ce]514        text_hint = wx.StaticText(self,-1,"Example: [M0][paramter] = M1.parameter") 
[2140e68]515        sizer_button.Add(text_hint, 0 , wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10)
516        sizer_button.Add(self.btAdd, 0, wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10)
517       
[8bd4dc0]518        boxsizer1.Add(sizer_title, flag= wx.TOP|wx.BOTTOM,border=10)
519        boxsizer1.Add(self.sizer_constraints, flag= wx.TOP|wx.BOTTOM,border=10)
520        boxsizer1.Add(sizer_button, flag= wx.TOP|wx.BOTTOM,border=10)
[2140e68]521       
522        self.sizer2.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10)
523        self.sizer2.Layout()
[c99a6c5]524        self.SetScrollbars(20,20,25,65)
[5062bbf]525   
[2140e68]526    def _set_constraint(self):
[d89f09b]527        """
[5062bbf]528        get values from the constrainst textcrtl ,parses them into model name
529        parameter name and parameters values.
530        store them in a list self.params .when when params is not empty set_model
531        uses it to reset the appropriate model and its appropriates parameters
[d89f09b]532        """
[2140e68]533        for item in self.constraints_list:
[ac11e40]534            model = item[0].GetClientData(item[0].GetCurrentSelection())
535            param = item[1].GetString(item[1].GetCurrentSelection())
[2140e68]536            constraint = item[3].GetValue().lstrip().rstrip()
[bb7d8a4]537            if param.lstrip().rstrip()=="":
538                param= None
539                msg= " Constraint will be ignored!. missing parameters in combobox"
540                msg+= " to set constraint! "
541                wx.PostEvent(self.parent.Parent, StatusEvent(status= msg ))
[6bbeacd4]542            for id, value in self.constraint_dict.iteritems():
[1f57dfd]543                if model == value:
544                    if constraint == "":
545                        msg= " Constraint will be ignored!. missing value in textcrtl"
546                        msg+= " to set constraint! "
547                        wx.PostEvent(self.parent.Parent, StatusEvent(status= msg ))
548                        constraint = None
[6bbeacd4]549                    self.page_finder[id].set_model_param(param,constraint)
[1f57dfd]550                    break
[5062bbf]551   
[2140e68]552    def _fill_sizer_model_list(self,sizer):
[d89f09b]553        """
[5062bbf]554        Receive a dictionary containing information to display model name
555       
556        :param page_finder: the dictionary containing models information
557       
[d89f09b]558        """
[2140e68]559        ix = 0
560        iy = 0
561        list=[]
562        sizer.Clear(True)
563       
564        new_name = wx.StaticText(self, -1, 'New Model Name', style=wx.ALIGN_CENTER)
565        new_name.SetBackgroundColour('orange')
566        sizer.Add(new_name,(iy, ix),(1,1),
567                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
[5062bbf]568        ix += 2 
[2140e68]569        model_type = wx.StaticText(self, -1, '  Model Type')
570        model_type.SetBackgroundColour('grey')
571        sizer.Add(model_type,(iy, ix),(1,1),
572                            wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
[5062bbf]573        ix += 1 
[2140e68]574        data_used = wx.StaticText(self, -1, '  Used Data')
575        data_used.SetBackgroundColour('grey')
576        sizer.Add(data_used,(iy, ix),(1,1),
577                            wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
[6bbeacd4]578        ix += 1 
579        tab_used = wx.StaticText(self, -1, '  Fit Tab')
580        tab_used.SetBackgroundColour('grey')
581        sizer.Add(tab_used,(iy, ix),(1,1),
582                            wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
583        for id, value in self.page_finder.iteritems():
[2140e68]584            try:
585                ix = 0
586                iy += 1 
587                model = value.get_model()
[6bbeacd4]588                name = '_'
589                if model is not None:
590                    name = str(model.name)
591                cb = wx.CheckBox(self, -1, name)
[2140e68]592                cb.SetValue(False)
[6bbeacd4]593                cb.Enable(model is not None)
[2140e68]594                sizer.Add( cb,( iy,ix),(1,1),  wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
595                wx.EVT_CHECKBOX(self, cb.GetId(), self.check_model_name)
[5062bbf]596                ix += 2 
[2140e68]597                type = model.__class__.__name__
598                model_type = wx.StaticText(self, -1, str(type))
599                sizer.Add(model_type,( iy,ix),(1,1),  wx.EXPAND|wx.ADJUST_MINSIZE, 0)
600                data = value.get_fit_data()
[6bbeacd4]601                name = '-'
602                if data is not None:
603                    name = str(data.name)
604                data_used = wx.StaticText(self, -1, name)
605                ix += 1 
[2140e68]606                sizer.Add(data_used,( iy,ix),(1,1),  wx.EXPAND|wx.ADJUST_MINSIZE, 0)
[6bbeacd4]607                   
608                ix += 1 
609                caption = value.get_fit_tab_caption()
610                tab_caption_used= wx.StaticText(self, -1, str(caption))
611                sizer.Add(tab_caption_used,( iy,ix),(1,1),  wx.EXPAND|wx.ADJUST_MINSIZE, 0)
[2140e68]612               
[6bbeacd4]613                self.model_list.append([cb,value,id,model])
[2140e68]614               
615            except:
[6bbeacd4]616                raise
617                #pass
[5062bbf]618        iy += 1
[2140e68]619        sizer.Add((20,20),( iy,ix),(1,1),  wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
620        sizer.Layout()   
Note: See TracBrowser for help on using the repository browser.