source: sasview/fittingview/src/sans/perspectives/fitting/simfitpage.py @ d74fbff

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 d74fbff was 0a9871c, checked in by Gervaise Alina <gervyh@…>, 13 years ago

make sure simfitpage is display when batchpage is on

  • Property mode set to 100644
File size: 33.3 KB
RevLine 
[d89f09b]1
[2140e68]2import sys,re,string, wx 
3import wx.lib.newevent 
[4ce74917]4from sans.guiframe.events import StatusEvent
[4bd492f]5from sans.guiframe.panel_base import PanelBase
6from wx.lib.scrolledpanel import ScrolledPanel
[1976004]7from sans.guiframe.events import PanelOnFocusEvent
[c99a6c5]8#Control panel width
[6e9976b]9if sys.platform.count("darwin")==0:
[c99a6c5]10    PANEL_WID = 420
[f1aa385]11    FONT_VARIANT = 0
[c99a6c5]12else:
13    PANEL_WID = 490
[f1aa385]14    FONT_VARIANT = 1
[8bd4dc0]15           
16def get_fittableParam( model):
[2140e68]17    """
[5062bbf]18    return list of fittable parameters name of a model
19   
20    :param model: the model used
21   
[2140e68]22    """
[8bd4dc0]23    fittable_param=[]
24    for item in model.getParamList():
25        if not item  in model.getDispParamList():
[fb59ed9]26            if not item in model.non_fittable:
27                fittable_param.append(item)
[8bd4dc0]28           
29    for item in model.fixed:
30        fittable_param.append(item)
[2140e68]31       
[8bd4dc0]32    return fittable_param
[2140e68]33
[4bd492f]34class SimultaneousFitPage(ScrolledPanel, PanelBase):
[d89f09b]35    """
[5062bbf]36    Simultaneous fitting panel
37    All that needs to be defined are the
38    two data members window_name and window_caption
[d89f09b]39    """
[925a30e]40    ## Internal name for the AUI manager
[d89f09b]41    window_name = "simultaneous Fit page"
42    ## Title to appear on top of the window
43    window_caption = "Simultaneous Fit Page"
44   
45   
[2140e68]46    def __init__(self, parent,page_finder ={}, *args, **kwargs):
[4bd492f]47        ScrolledPanel.__init__(self, parent,style= wx.FULL_REPAINT_ON_RESIZE )
48        PanelBase.__init__(self, parent)
[d89f09b]49        """
[5062bbf]50        Simultaneous page display
[d89f09b]51        """
[00daba9]52        self.SetupScrolling()
[f1aa385]53        ##Font size
54        self.SetWindowVariant(variant = FONT_VARIANT)
[922497f]55        self.uid = wx.NewId()
[d89f09b]56        self.parent = parent
[2140e68]57        ## store page_finder
[b28717b]58        self.page_finder = page_finder
[2140e68]59        ## list contaning info to set constraint
[6bbeacd4]60        ## look like self.constraint_dict[page_id]= page
[2140e68]61        self.constraint_dict={}
[1b14795]62        ## item list 
63        # self.constraints_list=[combobox1, combobox2,=,textcrtl, button ]
[2140e68]64        self.constraints_list=[]
65        ## list of current model
66        self.model_list=[]
67        ## selected mdoel to fit
68        self.model_toFit=[]
[b28717b]69        ## number of constraint
70        self.nb_constraint= 0
[dc613d6]71        self.uid = wx.NewId()
[b28717b]72        ## draw page
[2140e68]73        self.define_page_structure()
[b28717b]74        self.draw_page()
[2140e68]75        self.set_layout()
76       
77    def define_page_structure(self):
78        """
[5062bbf]79        Create empty sizer for a panel
[2140e68]80        """
[d89f09b]81        self.vbox  = wx.BoxSizer(wx.VERTICAL)
[2140e68]82        self.sizer1 = wx.BoxSizer(wx.VERTICAL)
83        self.sizer2 = wx.BoxSizer(wx.VERTICAL)
[8bd4dc0]84        self.sizer3 = wx.BoxSizer(wx.VERTICAL)
[c99a6c5]85
86        self.sizer1.SetMinSize((PANEL_WID,-1))
87        self.sizer2.SetMinSize((PANEL_WID,-1))
88        self.sizer3.SetMinSize((PANEL_WID,-1))
[d89f09b]89        self.vbox.Add(self.sizer1)
90        self.vbox.Add(self.sizer2)
[8bd4dc0]91        self.vbox.Add(self.sizer3)
[51d47b5]92       
[2140e68]93    def set_scroll(self):
[5062bbf]94        """
95        """
[e1a97f8]96        #self.SetScrollbars(20,20,25,65)
[2140e68]97        self.Layout() 
98         
99    def set_layout(self):
100        """
[5062bbf]101        layout
[2140e68]102        """
[d89f09b]103        self.vbox.Layout()
104        self.vbox.Fit(self) 
105        self.SetSizer(self.vbox)
[2140e68]106        self.set_scroll()
[d89f09b]107        self.Centre()
108       
[8bd4dc0]109    def onRemove(self, event):
110        """
[5062bbf]111        Remove constraint fields
[8bd4dc0]112        """
[a911b48]113        if len(self.constraints_list)==1:
114            self.hide_constraint.SetValue(True)
115            self._hide_constraint()
116            return 
117        if len(self.constraints_list)==0:
[8bd4dc0]118            return 
119        for item in self.constraints_list:
120            length= len(item)
121            if event.GetId()==item[length-2].GetId():
122                sizer= item[length-1]
[bb7d8a4]123                sizer.Clear(True)
[8bd4dc0]124                self.sizer_constraints.Remove(sizer)
[1b14795]125                #self.SetScrollbars(20,20,25,65)
[8bd4dc0]126                self.constraints_list.remove(item)
127                self.nb_constraint -= 1
[1b14795]128                self.sizer2.Layout()
129                self.Layout()
[8bd4dc0]130                break
[1b14795]131        self._onAdd_constraint(None)   
132             
[922497f]133    def onFit(self, event):
[5062bbf]134        """
135        signal for fitting
136       
137        """
[2140e68]138        ## making sure all parameters content a constraint
139        ## validity of the constraint expression is own by fit engine
[ac11e40]140        if self.show_constraint.GetValue():
[00daba9]141            if not self._set_constraint():
142                return
[2140e68]143        ## model was actually selected from this page to be fit
[3215d32]144        if len(self.model_toFit) >= 1 :
[66ff250]145            self.manager._reset_schedule_problem(value=0)
[6f023e8]146            for item in self.model_list:
147                if item[0].GetValue():
[c647377]148                    self.manager.schedule_for_fit(value=1, uid=item[2]) 
[1b14795]149            try:
150                self.manager.onFit(uid=self.uid)
151            except:
152                msg= "Select at least one parameter to fit in the FitPages."
153                wx.PostEvent(self.parent.parent, StatusEvent(status=msg))
[1b07935d]154        else:
[2140e68]155            msg= "Select at least one model to fit "
[1b14795]156            wx.PostEvent(self.parent.parent, StatusEvent(status=msg))
[f343069]157           
[d89f09b]158    def set_manager(self, manager):
159        """
[5062bbf]160        set panel manager
161       
162        :param manager: instance of plugin fitting
163       
[d89f09b]164        """
165        self.manager = manager
[b28717b]166       
[2140e68]167    def check_all_model_name(self,event):
[d89f09b]168        """
[5062bbf]169        check all models names
[d89f09b]170        """
[6bbeacd4]171        self.model_toFit = [] 
172        if self.cb1.GetValue()== True:
[d89f09b]173            for item in self.model_list:
[6c08ba5]174                if item[0].IsEnabled():
175                    item[0].SetValue(True)
176                    self.model_toFit.append(item)
[2140e68]177               
178            ## constraint info
179            self._store_model()
180            ## display constraint fields
181            if self.show_constraint.GetValue():
[77a43fb]182                self._show_all_constraint() 
[2140e68]183                self._show_constraint()
184                return
[d89f09b]185        else:
186            for item in self.model_list:
187                item[0].SetValue(False) 
[948add7]188               
[d89f09b]189            self.model_toFit=[]
[2140e68]190            ##constraint info
191            self._hide_constraint()
[925a30e]192       
[2140e68]193    def check_model_name(self,event):
[d89f09b]194        """
[5062bbf]195        Save information related to checkbox and their states
[d89f09b]196        """
197        self.model_toFit=[]
198        for item in self.model_list:
199            if item[0].GetValue()==True:
200                self.model_toFit.append(item)
201            else:
202                if item in self.model_toFit:
203                    self.model_toFit.remove(item)
204                    self.cb1.SetValue(False)
[b28717b]205       
[2140e68]206        ## display constraint fields
[b28717b]207        if len(self.model_toFit)==2:
[2140e68]208            self._store_model()
[1b14795]209            if self.show_constraint.GetValue() and\
210                             len(self.constraints_list)==0:
[77a43fb]211                self._show_all_constraint() 
[2140e68]212                self._show_constraint()
[b28717b]213        elif len(self.model_toFit)< 2:
214            ##constraint info
215            self._hide_constraint()             
[2140e68]216       
217        ## set the value of the main check button         
[d89f09b]218        if len(self.model_list)==len(self.model_toFit):
219            self.cb1.SetValue(True)
[b28717b]220            return
[d89f09b]221        else:
222            self.cb1.SetValue(False)
[948add7]223       
[b28717b]224    def draw_page(self):     
[2140e68]225        """
[5062bbf]226        Draw a sizer containing couples of data and model
[b28717b]227        """ 
[2140e68]228        self.model_list=[]
229        self.model_toFit=[]
[8bd4dc0]230        self.constraints_list=[]
[1d2782d]231        self.constraint_dict={}
232        self.nb_constraint= 0
233       
[2140e68]234        if len(self.model_list)>0:
235            for item in self.model_list:
236                item[0].SetValue(False) 
[c647377]237                self.manager.schedule_for_fit(value=0, uid=item[2])
[2140e68]238               
[5062bbf]239        self.sizer1.Clear(True)   
[8bd4dc0]240        box_description= wx.StaticBox(self, -1,"Fit Combinations")
[2140e68]241        boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL)
242        sizer_title = wx.BoxSizer(wx.HORIZONTAL)
243        sizer_couples = wx.GridBagSizer(5,5)
244        #------------------------------------------------------
245        if len(self.page_finder)==0:
[2296316]246            msg = " No fit combinations are found! \n\n"
[1b14795]247            msg += " Please load data and set up "
248            msg += "at least two fit panels first..."
[2296316]249            sizer_title.Add(wx.StaticText(self, -1, msg))
[2140e68]250        else:
251            ## store model 
252            self._store_model()
253       
[8bd4dc0]254            self.cb1 = wx.CheckBox(self, -1,'Select all')
[2140e68]255            self.cb1.SetValue(False)
256            wx.EVT_CHECKBOX(self, self.cb1.GetId(), self.check_all_model_name)
257           
[8bd4dc0]258            sizer_title.Add((10,10),0,
259                wx.TOP|wx.BOTTOM|wx.EXPAND|wx.ADJUST_MINSIZE,border=5)
260            sizer_title.Add(self.cb1,0,
261                wx.TOP|wx.BOTTOM|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE,border=5)
262           
263            ## draw list of model and data name
[2140e68]264            self._fill_sizer_model_list(sizer_couples)
265            ## draw the sizer containing constraint info
266            self._fill_sizer_constraint()
[8bd4dc0]267            ## draw fit button
268            self._fill_sizer_fit()
[2140e68]269        #--------------------------------------------------------
[8bd4dc0]270        boxsizer1.Add(sizer_title, flag= wx.TOP|wx.BOTTOM,border=5) 
[0a9871c]271        boxsizer1.Add(sizer_couples, 1, flag= wx.TOP|wx.BOTTOM,border=5)
[2140e68]272       
[0a9871c]273        self.sizer1.Add(boxsizer1, 1, wx.EXPAND | wx.ALL, 10)
[2140e68]274        self.sizer1.Layout()
[e1a97f8]275        #self.SetScrollbars(20,20,25,65)
[2140e68]276        self.AdjustScrollbars()
[0a9871c]277        self.Layout()
[2140e68]278       
279    def _store_model(self):
[d89f09b]280        """
[5062bbf]281         Store selected model
[d89f09b]282        """
[2140e68]283        if len(self.model_toFit) < 2:
284            return
[1d2782d]285        for item in self.model_toFit:
286            model = item[3]
[6bbeacd4]287            page_id= item[2]
288            self.constraint_dict[page_id] = model
[2140e68]289                   
290    def _display_constraint(self, event):
291        """
[5062bbf]292        Show fields to add constraint
[2140e68]293        """
294        if len(self.model_toFit)< 2:
295            msg= "Select at least 2 models to add constraint "
[1b14795]296            wx.PostEvent(self.parent.parent, StatusEvent(status= msg ))
[2140e68]297            ## hide button
298            self._hide_constraint()
299            return
300        if self.show_constraint.GetValue():
[1b14795]301            self._show_all_constraint() 
[2140e68]302            self._show_constraint()
[e1a97f8]303            self.Layout()
[2140e68]304            return
305        else:
306           self._hide_constraint()
[e1a97f8]307           self.Layout()
[2140e68]308           return 
[1b14795]309       
310    def _show_all_constraint(self):
311        """
312        Show constraint fields
313        """
314        #for id, model in self.constraint_dict.iteritems():   
315        box_description= wx.StaticBox(self, -1,"Easy Setup ")
316        boxsizer = wx.StaticBoxSizer(box_description, wx.HORIZONTAL)     
317        sizer_constraint =  wx.BoxSizer(wx.HORIZONTAL|wx.LEFT|wx.RIGHT|wx.EXPAND)
318        self.model_cbox_left = wx.ComboBox(self, -1, style=wx.CB_READONLY)
319        self.model_cbox_left.Clear()
320        self.model_cbox_right = wx.ComboBox(self, -1, style=wx.CB_READONLY)
321        self.model_cbox_right.Clear()
322        wx.EVT_COMBOBOX(self.model_cbox_left, -1, self._on_select_modelcb)
323        wx.EVT_COMBOBOX(self.model_cbox_right, -1, self._on_select_modelcb)
324        egal_txt= wx.StaticText(self,-1," = ")
325        self.set_button =wx.Button(self, wx.NewId(),'Set All')
326        self.set_button.Bind(wx.EVT_BUTTON, self._on_set_all_equal,
327                                       id=self.set_button.GetId())
328        set_tip = "Add constraints for all the adjustable parameters "
329        set_tip += "(checked in FitPages) if exist."
330        self.set_button.SetToolTipString(set_tip)
331        self.set_button.Disable()
332       
333        for id, model in self.constraint_dict.iteritems():
334            ## check if all parameters have been selected for constraint
335            ## then do not allow add constraint on parameters
336            self.model_cbox_left.Append( str(model.name), model)
337        self.model_cbox_left.Select(0)
338        for id, model in self.constraint_dict.iteritems():
339            ## check if all parameters have been selected for constraint
340            ## then do not allow add constraint on parameters
341            self.model_cbox_right.Append( str(model.name), model)
342        boxsizer.Add(self.model_cbox_left, 
343                             flag= wx.RIGHT|wx.EXPAND, border=10)
344        boxsizer.Add(wx.StaticText(self, -1,".parameters"),
345                             flag= wx.RIGHT|wx.EXPAND, border=5)
346        boxsizer.Add(egal_txt, flag= wx.RIGHT|wx.EXPAND, border=5)
347        boxsizer.Add(self.model_cbox_right, 
348                             flag= wx.RIGHT|wx.EXPAND, border=10)
349        boxsizer.Add(wx.StaticText(self, -1,".parameters"),
350                             flag= wx.RIGHT|wx.EXPAND,border=5)
351        boxsizer.Add((20,-1))
352        boxsizer.Add(self.set_button, flag= wx.RIGHT|wx.EXPAND, border=5)
353        sizer_constraint.Add(boxsizer, flag= wx.RIGHT|wx.EXPAND, border=5)
354        self.sizer_all_constraints.Insert(before=0,
355                             item=sizer_constraint, 
356                             flag= wx.TOP|wx.BOTTOM|wx.EXPAND, border=5)
357
358        self.sizer_all_constraints.Layout()
359        self.sizer2.Layout()
[e1a97f8]360        #self.SetScrollbars(20,20,25,65)
[1b14795]361   
362    def _on_select_modelcb(self, event):
363        """
364        On select model left or right combobox
365        """
366        event.Skip()
367        flag = True
368        if self.model_cbox_left.GetValue().strip() == '':
369            flag = False
370        if self.model_cbox_right.GetValue().strip() == '':
371            flag = False
372        if self.model_cbox_left.GetValue() ==\
373                self.model_cbox_right.GetValue():
374            flag = False
375        self.set_button.Enable(flag)
376       
377    def _on_set_all_equal(self, event):
378        """
379        On set button
380        """
381        event.Skip()
382        length = len(self.constraints_list)
383        if length < 1:
384            return 
385        param_list = []
386        param_listB = []
387        selection = self.model_cbox_left.GetCurrentSelection()
388        model_left = self.model_cbox_left.GetValue()
389        model = self.model_cbox_left.GetClientData(selection)
390        selectionB = self.model_cbox_right.GetCurrentSelection()
391        model_right = self.model_cbox_right.GetValue()
392        modelB = self.model_cbox_right.GetClientData(selectionB)
393        for id, dic_model in self.constraint_dict.iteritems():
394            if model == dic_model:
395                param_list = self.page_finder[id].get_param2fit()
396            if modelB == dic_model:
397                param_listB = self.page_finder[id].get_param2fit()
398            if len(param_list) > 0 and len(param_listB) > 0:
399                break
400        #param_list= get_fittableParam(model)
401        #param_listB= get_fittableParam(modelB)
402        num_cbox = 0
403        has_param = False
404        for param in param_list:
405            num_cbox += 1
406            if param in param_listB:
407                self.model_cbox.SetStringSelection(model_left)
408                self._on_select_model(None)
409                self.param_cbox.Clear()
410                self.param_cbox.Append( str(param), model)
411                self.param_cbox.SetStringSelection( str(param))
412                self.ctl2.SetValue(str(model_right + "." + str(param)))
413                has_param = True
[00daba9]414                if num_cbox == (len(param_list) + 1):
[1b14795]415                    break
416                self._show_constraint()
417       
418        self.sizer_constraints.Layout()
419        self.sizer2.Layout()
[e1a97f8]420        self.SetScrollbars(20,20,25,65)
421        self.Layout()
[1b14795]422        if not has_param:
423            msg= " There is no adjustable parameter (checked to fit)"
424            msg += " either one of the models."
425            wx.PostEvent(self.parent.parent, StatusEvent(info="warning", 
426                                                         status= msg ))
427        else:
428            msg= " The constraints are added."
429            wx.PostEvent(self.parent.parent, StatusEvent(info="info", 
430                                                         status= msg ))     
[2140e68]431    def _show_constraint(self):
432        """
[5062bbf]433        Show constraint fields
[2140e68]434        """
[77e23a2]435        self.btAdd.Show(True)
[2140e68]436        if len(self.constraints_list)!= 0:
437            nb_fit_param = 0
[1b14795]438            for id, model in self.constraint_dict.iteritems():
[00daba9]439                nb_fit_param += len(self.page_finder[id].get_param2fit())
[2140e68]440            ##Don't add anymore
441            if len(self.constraints_list) == nb_fit_param:
[ac11e40]442                msg= "Cannot add another constraint .Maximum of number "
443                msg += "Parameters name reached %s"%str(nb_fit_param)
[1b14795]444                wx.PostEvent(self.parent.parent, StatusEvent(status= msg ))
[b28717b]445                self.sizer_constraints.Layout()
[ac11e40]446                self.sizer2.Layout()
[00daba9]447                #self.SetScrollbars(20,20,25,65)
[ac11e40]448                return
449        if len(self.model_toFit) < 2 :
[2140e68]450            msg= "Select at least 2 model to add constraint "
[1b14795]451            wx.PostEvent(self.parent.parent, StatusEvent(status= msg ))
[b28717b]452            self.sizer_constraints.Layout()
[2140e68]453            self.sizer2.Layout()
[00daba9]454            #self.SetScrollbars(20,20,25,65)
[2140e68]455            return
456           
457        sizer_constraint =  wx.BoxSizer(wx.HORIZONTAL)
[8bd4dc0]458        model_cbox = wx.ComboBox(self, -1,style=wx.CB_READONLY)
[2140e68]459        model_cbox.Clear()
[1b14795]460        param_cbox = wx.ComboBox(self, -1,style=wx.CB_READONLY, size=(100,-1),)
[b28717b]461        param_cbox.Hide()
[8dfe0fd]462       
463        #This is for GetCLientData() _on_select_param: Was None return on MAC.
464        self.param_cbox = param_cbox
465       
[2140e68]466        wx.EVT_COMBOBOX(param_cbox,-1, self._on_select_param)
[1b14795]467        self.ctl2 = wx.TextCtrl(self, -1)
[77a43fb]468        egal_txt= wx.StaticText(self,-1, " = ")
469        self.btRemove = wx.Button(self,wx.NewId(),'Remove')
470        self.btRemove.Bind(wx.EVT_BUTTON, self.onRemove, 
471                                    id=self.btRemove.GetId())
472        self.btRemove.SetToolTipString("Remove constraint.")
473        self.btRemove.Hide()
474        if hasattr(self,"btAdd"):
475            self.btAdd.Hide()
[1b14795]476        for id, model in self.constraint_dict.iteritems():
[2140e68]477            ## check if all parameters have been selected for constraint
478            ## then do not allow add constraint on parameters
[ac11e40]479            model_cbox.Append( str(model.name), model)
[2140e68]480           
[8dfe0fd]481        #This is for GetCLientData() passing to self._on_select_param: Was None return on MAC.
482        self.model_cbox = model_cbox
[2140e68]483           
484        wx.EVT_COMBOBOX(model_cbox,-1, self._on_select_model)
[1b14795]485        sizer_constraint.Add((5,-1))
[b28717b]486        sizer_constraint.Add(model_cbox, flag= wx.RIGHT|wx.EXPAND,border=10)
487        sizer_constraint.Add(param_cbox, flag= wx.RIGHT|wx.EXPAND,border=5)
488        sizer_constraint.Add(egal_txt, flag= wx.RIGHT|wx.EXPAND,border=5)
[1b14795]489        sizer_constraint.Add(self.ctl2, flag= wx.RIGHT|wx.EXPAND,border=10)
[77a43fb]490        sizer_constraint.Add(self.btRemove, flag= wx.RIGHT|wx.EXPAND,border=10)
[b28717b]491     
492        self.sizer_constraints.Insert(before=self.nb_constraint,
[77a43fb]493                        item=sizer_constraint, flag= wx.TOP|wx.BOTTOM|wx.EXPAND,
494                        border=5)
[8bd4dc0]495        ##[combobox1, combobox2,=,textcrtl, remove button ]
[77a43fb]496        self.constraints_list.append([model_cbox, param_cbox, egal_txt, 
497                                    self.ctl2,self.btRemove,sizer_constraint])
[5062bbf]498   
[b28717b]499        self.nb_constraint += 1
500        self.sizer_constraints.Layout()
[2140e68]501        self.sizer2.Layout()
[00daba9]502        #self.SetScrollbars(20,20,25,65)
[2140e68]503       
504    def _hide_constraint(self): 
505        """
[5062bbf]506        hide buttons related constraint
[ac11e40]507        """ 
[6bbeacd4]508        for id in  self.page_finder.iterkeys():
509            self.page_finder[id].clear_model_param()
[b28717b]510               
[1b14795]511        self.nb_constraint = 0     
512        self.constraint_dict = {}
[69bee6d]513        if hasattr(self,"btAdd"):
514            self.btAdd.Hide()
[ac11e40]515        self._store_model()
[1b14795]516        self.constraints_list = []   
517        self.sizer_all_constraints.Clear(True) 
518        self.sizer_all_constraints.Layout()         
[b28717b]519        self.sizer_constraints.Clear(True) 
520        self.sizer_constraints.Layout()   
[2140e68]521        self.sizer2.Layout()
[e1a97f8]522        #self.SetScrollbars(20,20,25,65)
523        #self.AdjustScrollbars()   
[5062bbf]524           
[2140e68]525    def _on_select_model(self, event):
526        """
[5062bbf]527        fill combox box with list of parameters
[2140e68]528        """
[8dfe0fd]529        ##This way PC/MAC both work, instead of using event.GetClientData().
530        n = self.model_cbox.GetCurrentSelection()
531        model = self.model_cbox.GetClientData(n)
[1b14795]532        for id, dic_model in self.constraint_dict.iteritems():
533            if model == dic_model:
534                param_list = self.page_finder[id].get_param2fit()
535                break
536        #param_list= get_fittableParam(model)
[2140e68]537        length = len(self.constraints_list)
538        if length < 1:
539            return 
540        param_cbox = self.constraints_list[length-1][1]
541        param_cbox.Clear()
542        ## insert only fittable paramaters
543        for param in param_list:
[ac11e40]544            param_cbox.Append( str(param), model)
545           
[2140e68]546        param_cbox.Show(True)
[77a43fb]547        self.btRemove.Show(True)
548        self.btAdd.Show(True)
[2140e68]549        self.sizer2.Layout()
[e1a97f8]550        #self.SetScrollbars(20,20,25,65)
[2140e68]551       
552    def _on_select_param(self, event):
553        """
[5062bbf]554        Store the appropriate constraint in the page_finder
[2140e68]555        """
[8dfe0fd]556        ##This way PC/MAC both work, instead of using event.GetClientData().
557        n = self.param_cbox.GetCurrentSelection()
558        model = self.param_cbox.GetClientData(n)
[2140e68]559        param = event.GetString()
[ac11e40]560     
[2140e68]561        length = len(self.constraints_list)
562        if length < 1:
563            return 
564        egal_txt = self.constraints_list[length-1][2]
565        egal_txt.Show(True)       
566       
567        ctl2 = self.constraints_list[length-1][3]
568        ctl2.Show(True)
[6e9976b]569        #self.sizer2.Layout()
[e1a97f8]570        #self.SetScrollbars(20,20,25,65)
[2140e68]571       
572    def _onAdd_constraint(self, event): 
573        """
[5062bbf]574        Add another line for constraint
[2140e68]575        """
[8bd4dc0]576        if not self.show_constraint.GetValue():
577            msg= " Select Yes to add Constraint "
[1b14795]578            wx.PostEvent(self.parent.parent, StatusEvent(status= msg ))
[8bd4dc0]579            return 
[1b14795]580        ## check that a constraint is added
581        # before allow to add another constraint
[2140e68]582        for item in self.constraints_list:
583            model_cbox = item[0]
584            if model_cbox.GetString(0)=="":
585                msg= " Select a model Name! "
[1b14795]586                wx.PostEvent(self.parent.parent, StatusEvent(status= msg ))
[2140e68]587                return 
588            param_cbox = item[1]
589            if param_cbox.GetString(0)=="":
590                msg= " Select a parameter Name! "
[1b14795]591                wx.PostEvent(self.parent.parent, StatusEvent(status= msg ))
[2140e68]592                return 
593            ctl2 = item[3]
594            if ctl2.GetValue().lstrip().rstrip()=="":
[b28717b]595                model= param_cbox.GetClientData(param_cbox.GetCurrentSelection())
[1b14795]596                msg= " Enter a constraint for %s.%s! "%(model.name, 
597                                                        param_cbox.GetString(0))           
598                wx.PostEvent(self.parent.parent, StatusEvent(status= msg ))
[b28717b]599                return 
[2140e68]600        ## some model or parameters can be constrained
601        self._show_constraint()
602       
[8bd4dc0]603    def _fill_sizer_fit(self):
604        """
[5062bbf]605        Draw fit button
[8bd4dc0]606        """
607        self.sizer3.Clear(True)
608        box_description= wx.StaticBox(self, -1,"Fit ")
609        boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL)
610        sizer_button = wx.BoxSizer(wx.HORIZONTAL)
611         
612        self.btFit = wx.Button(self,wx.NewId(),'Fit')
613        self.btFit.Bind(wx.EVT_BUTTON, self.onFit,id= self.btFit.GetId())
614        self.btFit.SetToolTipString("Perform fit.")
[2140e68]615       
[8bd4dc0]616        text= "Hint: Park fitting engine will be selected \n"
617        text+= "automatically for more than 2 combinations checked"
618        text_hint = wx.StaticText(self,-1,text)
619       
620        sizer_button.Add(text_hint,  wx.RIGHT|wx.EXPAND, 10)
621        sizer_button.Add(self.btFit, 0, wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10)
622       
623        boxsizer1.Add(sizer_button, flag= wx.TOP|wx.BOTTOM,border=10)
624        self.sizer3.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10)
625        self.sizer3.Layout()
[e1a97f8]626        #self.SetScrollbars(20,20,25,65)
[2140e68]627       
628    def _fill_sizer_constraint(self):
629        """
[5062bbf]630        Fill sizer containing constraint info
[2140e68]631        """
[5062bbf]632        msg = "Select at least 2 model to add constraint "
[1b14795]633        wx.PostEvent(self.parent.parent, StatusEvent(status= msg ))
[2140e68]634       
635        self.sizer2.Clear(True)
636        box_description= wx.StaticBox(self, -1,"Fit Constraints")
637        boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL)
638        sizer_title = wx.BoxSizer(wx.HORIZONTAL)
[1b14795]639        self.sizer_all_constraints = wx.BoxSizer(wx.HORIZONTAL)
[b28717b]640        self.sizer_constraints = wx.BoxSizer(wx.VERTICAL)
[2140e68]641        sizer_button = wx.BoxSizer(wx.HORIZONTAL)
642       
[1b14795]643        self.hide_constraint = wx.RadioButton(self, -1, 'No', (10, 10), 
644                                              style=wx.RB_GROUP)
[2140e68]645        self.show_constraint = wx.RadioButton(self, -1, 'Yes', (10, 30))
646        self.Bind( wx.EVT_RADIOBUTTON, self._display_constraint,
647                    id= self.hide_constraint.GetId() )
648        self.Bind(  wx.EVT_RADIOBUTTON, self._display_constraint,
649                         id= self.show_constraint.GetId()    )
[17c5868]650        self.hide_constraint.SetValue(True)
[2140e68]651        sizer_title.Add( wx.StaticText(self,-1," Model") )
652        sizer_title.Add(( 10,10) )
653        sizer_title.Add( wx.StaticText(self,-1," Parameter") )
654        sizer_title.Add(( 10,10) )
655        sizer_title.Add( wx.StaticText(self,-1," Add Constraint?") )
656        sizer_title.Add(( 10,10) )
657        sizer_title.Add( self.show_constraint )
658        sizer_title.Add( self.hide_constraint )
659        sizer_title.Add(( 10,10) )
[1b14795]660       
[2140e68]661        self.btAdd =wx.Button(self,wx.NewId(),'Add')
[1b14795]662        self.btAdd.Bind(wx.EVT_BUTTON, self._onAdd_constraint, 
663                        id=self.btAdd.GetId())
[2140e68]664        self.btAdd.SetToolTipString("Add another constraint?")
[77e23a2]665        self.btAdd.Hide()
[8bd4dc0]666     
[1b14795]667        text_hint = wx.StaticText(self, -1, 
668                                  "Example: [M0][paramter] = M1.parameter") 
[2140e68]669        sizer_button.Add(text_hint, 0 , wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10)
670        sizer_button.Add(self.btAdd, 0, wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10)
671       
[8bd4dc0]672        boxsizer1.Add(sizer_title, flag= wx.TOP|wx.BOTTOM,border=10)
[1b14795]673        boxsizer1.Add(self.sizer_all_constraints, flag= wx.TOP|wx.BOTTOM, 
674                      border=10)
675        boxsizer1.Add(self.sizer_constraints, flag= wx.TOP|wx.BOTTOM, 
676                      border=10)
677        boxsizer1.Add(sizer_button, flag= wx.TOP|wx.BOTTOM, border=10)
[2140e68]678       
679        self.sizer2.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10)
680        self.sizer2.Layout()
[e1a97f8]681        #self.SetScrollbars(20,20,25,65)
[5062bbf]682   
[2140e68]683    def _set_constraint(self):
[d89f09b]684        """
[5062bbf]685        get values from the constrainst textcrtl ,parses them into model name
686        parameter name and parameters values.
[1b14795]687        store them in a list self.params .when when params is not empty
688        set_model uses it to reset the appropriate model
689        and its appropriates parameters
[d89f09b]690        """
[2140e68]691        for item in self.constraints_list:
[ac11e40]692            model = item[0].GetClientData(item[0].GetCurrentSelection())
693            param = item[1].GetString(item[1].GetCurrentSelection())
[2140e68]694            constraint = item[3].GetValue().lstrip().rstrip()
[bb7d8a4]695            if param.lstrip().rstrip()=="":
696                param= None
[1b14795]697                msg= " Constraint will be ignored!. missing parameters"
698                msg+= " in combobox to set constraint! "
699                wx.PostEvent(self.parent.parent, StatusEvent(status= msg ))
[6bbeacd4]700            for id, value in self.constraint_dict.iteritems():
[1f57dfd]701                if model == value:
702                    if constraint == "":
[1b14795]703                        msg= " Constraint will be ignored!. missing value"
704                        msg+= " in textcrtl to set constraint! "
705                        wx.PostEvent(self.parent.parent, 
706                                     StatusEvent(status= msg ))
[1f57dfd]707                        constraint = None
[00daba9]708                    if str(param) in self.page_finder[id].get_param2fit():
709                        msg = " Checking constraint for parameter: %s ", param
710                        wx.PostEvent(self.parent.parent, 
711                                    StatusEvent(info="info", status= msg ))
712                    else:
713                        model_name = item[0].GetLabel()
714                        fitpage = self.page_finder[id].get_fit_tab_caption()
715                        msg = "All constrainted parameters must be set "
716                        msg += " adjustable: '%s.%s' "% (model_name, param)
717                        msg += "is NOT checked in '%s'. "% fitpage
718                        msg += " Please check it to fit or"
719                        msg += " remove the line of the constraint."
720                        wx.PostEvent(self.parent.parent, 
721                                StatusEvent(info="error", status= msg ))
722                        return False
723                       
[c647377]724                    for fid in self.page_finder[id].iterkeys():
725                        self.page_finder[id].set_model_param(param,
726                                                        constraint, fid=fid)
[1f57dfd]727                    break
[00daba9]728        return True
[5062bbf]729   
[2140e68]730    def _fill_sizer_model_list(self,sizer):
[d89f09b]731        """
[5062bbf]732        Receive a dictionary containing information to display model name
733       
734        :param page_finder: the dictionary containing models information
735       
[d89f09b]736        """
[2140e68]737        ix = 0
738        iy = 0
739        list=[]
740        sizer.Clear(True)
741       
[1b14795]742        new_name = wx.StaticText(self, -1, 'New Model Name', 
743                                 style=wx.ALIGN_CENTER)
[2140e68]744        new_name.SetBackgroundColour('orange')
745        sizer.Add(new_name,(iy, ix),(1,1),
746                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
[5062bbf]747        ix += 2 
[2140e68]748        model_type = wx.StaticText(self, -1, '  Model Type')
749        model_type.SetBackgroundColour('grey')
750        sizer.Add(model_type,(iy, ix),(1,1),
751                            wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
[5062bbf]752        ix += 1 
[2140e68]753        data_used = wx.StaticText(self, -1, '  Used Data')
754        data_used.SetBackgroundColour('grey')
755        sizer.Add(data_used,(iy, ix),(1,1),
756                            wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
[6bbeacd4]757        ix += 1 
758        tab_used = wx.StaticText(self, -1, '  Fit Tab')
759        tab_used.SetBackgroundColour('grey')
760        sizer.Add(tab_used,(iy, ix),(1,1),
761                            wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
762        for id, value in self.page_finder.iteritems():
[2140e68]763            try:
764                ix = 0
[c647377]765                for fitproblem in value.get_fit_problem():
[0a9871c]766                    if  not self.parent.get_page_by_id(id).batch_on:
767                        iy += 1 
768                        data = fitproblem.get_fit_data()
769                        model = fitproblem.get_model()
770                        name = '_'
771                        if model is not None:
772                            name = str(model.name)
773                        cb = wx.CheckBox(self, -1, name)
774                        cb.SetValue(False)
775                        cb.Enable(model is not None and data.is_data)
776                        sizer.Add(cb, (iy, ix), (1, 1), 
777                                   wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
778                        wx.EVT_CHECKBOX(self, cb.GetId(), self.check_model_name)
779                        ix += 2 
780                        type = model.__class__.__name__
781                        model_type = wx.StaticText(self, -1, str(type))
782                        sizer.Add(model_type, (iy, ix), (1, 1), 
783                                  wx.EXPAND|wx.ADJUST_MINSIZE, 0)
784                        name = '-'
785                        if data is not None and data.is_data:
786                            name = str(data.name)
787                        data_used = wx.StaticText(self, -1, name)
788                        ix += 1 
789                        sizer.Add(data_used, (iy, ix), (1, 1), 
790                                  wx.EXPAND|wx.ADJUST_MINSIZE, 0)
791                        ix += 1 
792                        caption = value.get_fit_tab_caption()
793                        tab_caption_used= wx.StaticText(self, -1, str(caption))
794                        sizer.Add(tab_caption_used, (iy, ix), (1, 1), 
795                                  wx.EXPAND|wx.ADJUST_MINSIZE, 0)
[6bbeacd4]796                   
[0a9871c]797                        self.model_list.append([cb,value,id,model])
[2140e68]798               
799            except:
[6bbeacd4]800                raise
801                #pass
[5062bbf]802        iy += 1
[c647377]803        sizer.Add((20, 20), (iy, ix), (1, 1), 
804                  wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
[2140e68]805        sizer.Layout()   
[0a9871c]806   
[c647377]807
[4133316]808    def on_set_focus(self, event=None):
809        """
810        The  derivative class is on focus if implemented
811        """
812        if self.parent is not None:
[1976004]813            if self.parent.parent is not None:
814                wx.PostEvent(self.parent.parent, PanelOnFocusEvent(panel=self))
815            self.page_finder = self.parent._manager.get_page_finder()
[4133316]816       
Note: See TracBrowser for help on using the repository browser.