Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sasgui/perspectives/fitting/simfitpage.py

    re89aed5 r4cafdff  
    99from wx.lib.scrolledpanel import ScrolledPanel 
    1010 
    11 from sas.sasgui.guiframe.events import StatusEvent, PanelOnFocusEvent 
     11from sas.sasgui.guiframe.events import StatusEvent 
    1212from sas.sasgui.guiframe.panel_base import PanelBase 
     13from sas.sasgui.guiframe.events import PanelOnFocusEvent 
    1314from sas.sasgui.guiframe.utils import IdList 
    1415from sas.sasgui.guiframe.documentation_window import DocumentationWindow 
    1516 
    16 # Control panel width 
     17#Control panel width  
    1718if sys.platform.count("darwin") == 0: 
    1819    PANEL_WID = 420 
     
    2829        'model_cbox param_cbox egal_txt constraint btRemove sizer') 
    2930 
    30  
    3131def get_fittableParam(model): 
    3232    """ 
     
    4747    return fittable_param 
    4848 
    49  
    5049class SimultaneousFitPage(ScrolledPanel, PanelBase): 
    5150    """ 
     
    5453    two data members window_name and window_caption 
    5554    """ 
    56     # Internal name for the AUI manager 
    57     window_name = "Simultaneous Fit Page" 
    58     # Title to appear on top of the window 
     55    ## Internal name for the AUI manager 
     56    window_name = "simultaneous Fit page" 
     57    ## Title to appear on top of the window 
    5958    window_caption = "Simultaneous Fit Page" 
    6059    ID_DOC = wx.NewId() 
     
    7574        self._ids = iter(self._id_pool) 
    7675        self.SetupScrolling() 
    77         # Font size 
     76        ##Font size 
    7877        self.SetWindowVariant(variant=FONT_VARIANT) 
    7978        self.uid = wx.NewId() 
    8079        self.parent = parent 
    8180        self.batch_on = batch_on 
    82         # store page_finder 
     81        ## store page_finder 
    8382        self.page_finder = page_finder 
    84         # list containing info to set constraint 
    85         # look like self.constraint_dict[page_id]= page 
     83        ## list containing info to set constraint 
     84        ## look like self.constraint_dict[page_id]= page 
    8685        self.constraint_dict = {} 
    87         # item list 
    88         # self.constraints_list=[combobox1, combobox2,=,textcrtl, button ] 
     86        ## item list 
     87        ## self.constraints_list=[combobox1, combobox2,=,textcrtl, button ] 
    8988        self.constraints_list = [] 
    90         # list of current model 
     89        ## list of current model 
    9190        self.model_list = [] 
    92         # selected model to fit 
    93         self.model_to_fit = [] 
    94         # Control the fit state 
     91        ## selected mdoel to fit 
     92        self.model_toFit = [] 
     93        ## Control the fit state 
    9594        self.fit_started = False 
    96         # number of constraint 
     95        ## number of constraint 
    9796        self.nb_constraint = 0 
    98         self.state = SimFitPageState() 
    9997        self.model_cbox_left = None 
    10098        self.model_cbox_right = None 
    101         # draw page 
     99        ## draw page 
    102100        self.define_page_structure() 
    103101        self.draw_page() 
     
    109107        """ 
    110108        self.vbox = wx.BoxSizer(wx.VERTICAL) 
    111         self.data_selection_sizer = wx.BoxSizer(wx.VERTICAL) 
    112         self.constraints_sizer = wx.BoxSizer(wx.VERTICAL) 
    113         self.run_fit_sizer = wx.BoxSizer(wx.VERTICAL) 
    114  
    115         self.data_selection_sizer.SetMinSize((PANEL_WID, -1)) 
    116         self.constraints_sizer.SetMinSize((PANEL_WID, -1)) 
    117         self.run_fit_sizer.SetMinSize((PANEL_WID, -1)) 
    118         self.vbox.Add(self.data_selection_sizer) 
    119         self.vbox.Add(self.constraints_sizer) 
    120         self.vbox.Add(self.run_fit_sizer) 
     109        self.sizer1 = wx.BoxSizer(wx.VERTICAL) 
     110        self.sizer2 = wx.BoxSizer(wx.VERTICAL) 
     111        self.sizer3 = wx.BoxSizer(wx.VERTICAL) 
     112 
     113        self.sizer1.SetMinSize((PANEL_WID, -1)) 
     114        self.sizer2.SetMinSize((PANEL_WID, -1)) 
     115        self.sizer3.SetMinSize((PANEL_WID, -1)) 
     116        self.vbox.Add(self.sizer1) 
     117        self.vbox.Add(self.sizer2) 
     118        self.vbox.Add(self.sizer3) 
    121119        self.SetSizer(self.vbox) 
    122120        self.Centre() 
    123  
    124     def set_state(self): 
    125         """ 
    126         Define a set of state parameters for saving simultaneous fits. 
    127         """ 
    128         self._set_constraint() 
    129         self.state.fit_page_no = self.uid 
    130         self.state.select_all = self.cb1.GetValue() 
    131         self.state.model_list = self.model_list 
    132         self.state.model_to_fit = self.model_to_fit 
    133         self.state.no_constraint = self.nb_constraint 
    134         self.state.constraint_dict = self.constraint_dict 
    135         self.state.constraints_list = self.constraints_list 
    136         return self.get_state() 
    137  
    138     def get_state(self): 
    139         """ 
    140         Return the state of the current page 
    141         :return: self.state 
    142         """ 
    143         return self.state 
    144121 
    145122    def draw_page(self): 
     
    154131        # create blank list of constraints 
    155132        self.model_list = [] 
    156         self.model_to_fit = [] 
     133        self.model_toFit = [] 
    157134        self.constraints_list = [] 
    158135        self.constraint_dict = {} 
     
    167144 
    168145        #------------------------------------------------------- 
    169         # setup sizer1 (which fitpages to include) 
    170         self.data_selection_sizer.Clear(True) 
     146        ## setup sizer1 (which fitpages to include) 
     147        self.sizer1.Clear(True) 
    171148        box_description = wx.StaticBox(self, wx.ID_ANY, "Fit Combinations") 
    172149        boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 
     
    174151        sizer_couples = wx.GridBagSizer(5, 5) 
    175152 
    176         # The wx GUI has a flag to enable a menu item, but can still be 
    177         # reached via scripting. There is no guearantee future GUI 
    178         # implementations force this check, either. 
    179         # IMHO, this if statement should stay -- JRK 2016-OCT-05 
     153        #This if statement should be obsolete and can be removed in version 4 
     154        #Leave it here for now as no time to thoroughly test.  However if no 
     155        #fit page is found the menu item that calls this page is inactive  
     156        # Nov. 22 2015  --PDB 
    180157        if len(self.page_finder) == 0: 
    181158            msg = " No fit combinations are found! \n\n" 
     
    184161            sizer_title.Add(wx.StaticText(self, wx.ID_ANY, msg)) 
    185162        else: 
    186             # store model 
     163            ## store model 
    187164            self._store_model() 
    188165 
     
    194171                wx.TOP | wx.BOTTOM | wx.EXPAND | wx.ADJUST_MINSIZE, border=5) 
    195172            sizer_title.Add(self.cb1, 0, 
    196                 wx.TOP | wx.BOTTOM | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 
    197                 border=5) 
    198  
    199             # draw list of model and data names 
     173                wx.TOP | wx.BOTTOM | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, border=5) 
     174 
     175            ## draw list of model and data names 
    200176            self._fill_sizer_model_list(sizer_couples) 
    201177 
    202178        boxsizer1.Add(sizer_title, flag=wx.TOP | wx.BOTTOM, border=5) 
    203179        boxsizer1.Add(sizer_couples, 1, flag=wx.TOP | wx.BOTTOM, border=5) 
    204         self.data_selection_sizer.Add(boxsizer1, 1, wx.EXPAND | wx.ALL, 10) 
    205         # self.sizer1.Layout() 
     180        self.sizer1.Add(boxsizer1, 1, wx.EXPAND | wx.ALL, 10) 
     181#        self.sizer1.Layout() 
    206182 
    207183        #-------------------------------------------------------- 
    208         # set up the other 2 sizers: the constraints list and the 
    209         # buttons (fit, help etc) sizer at the bottom of the page. 
    210         # Note: the if statement should be removed along with the above 
    211         # if statement as soon as it can be properly tested. 
    212         # Nov. 22 2015  --PDB 
    213         # As above, this page can be accessed through other means than the 
    214         # base SasView GUI. 
    215         # Oct. 5, 2016 --JRK 
     184        ## set up the other 2 sizers: the constraints list and the 
     185        ## buttons (fit, help etc) sizer at the bottom of the page. 
     186        ## Note: the if statement should be removed along with the above 
     187        ## if statement as soon as it can be properly tested. 
     188        ## Nov. 22 2015  --PDB 
    216189        if len(self.page_finder) > 0: 
    217             # draw the sizer containing constraint info 
     190            ## draw the sizer containing constraint info 
    218191            if not self.batch_on: 
    219192                self._fill_sizer_constraint() 
    220             # draw fit button sizer 
     193            ## draw fit button sizer 
    221194            self._fill_sizer_fit() 
     195 
    222196 
    223197    def _fill_sizer_model_list(self, sizer): 
     
    227201        ix = 0 
    228202        iy = 0 
     203        list = [] 
    229204        sizer.Clear(True) 
    230205 
     
    234209        new_name.SetForegroundColour(wx.WHITE) 
    235210        sizer.Add(new_name, (iy, ix), (1, 1), 
    236                   wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
     211                            wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    237212        ix += 2 
    238213        model_type = wx.StaticText(self, wx.ID_ANY, '  Model ') 
     
    240215        model_type.SetForegroundColour(wx.WHITE) 
    241216        sizer.Add(model_type, (iy, ix), (1, 1), 
    242                   wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     217                            wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    243218        ix += 1 
    244219        data_used = wx.StaticText(self, wx.ID_ANY, '  Data ') 
     
    246221        data_used.SetForegroundColour(wx.WHITE) 
    247222        sizer.Add(data_used, (iy, ix), (1, 1), 
    248                   wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     223                            wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    249224        ix += 1 
    250225        tab_used = wx.StaticText(self, wx.ID_ANY, '  FitPage ') 
     
    327302        wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 
    328303 
    329         self.constraints_sizer.Clear(True) 
     304        self.sizer2.Clear(True) 
    330305        if self.batch_on: 
    331             if self.constraints_sizer.IsShown(): 
    332                 self.constraints_sizer.Show(False) 
     306            if self.sizer2.IsShown(): 
     307                self.sizer2.Show(False) 
    333308            return 
    334309        box_description = wx.StaticBox(self, wx.ID_ANY, "Fit Constraints") 
    335         box_sizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 
     310        boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 
    336311        sizer_title = wx.BoxSizer(wx.HORIZONTAL) 
    337312        self.sizer_all_constraints = wx.BoxSizer(wx.HORIZONTAL) 
     
    363338 
    364339        self.btAdd = wx.Button(self, self.ID_ADD, 'Add') 
    365         self.btAdd.Bind(wx.EVT_BUTTON, self._on_add_constraint, 
     340        self.btAdd.Bind(wx.EVT_BUTTON, self._onAdd_constraint, 
    366341                        id=self.btAdd.GetId()) 
    367342        self.btAdd.SetToolTipString("Add another constraint?") 
     
    369344 
    370345        text_hint = wx.StaticText(self, wx.ID_ANY, 
    371                                   "Example: [M0][parameter] = M1.parameter") 
     346                                  "Example: [M0][paramter] = M1.parameter") 
    372347        sizer_button.Add(text_hint, 0, 
    373348                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 10) 
     
    375350                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 10) 
    376351 
    377         box_sizer1.Add(sizer_title, flag=wx.TOP | wx.BOTTOM, border=10) 
    378         box_sizer1.Add(self.sizer_all_constraints, flag=wx.TOP | wx.BOTTOM, 
    379                        border=10) 
    380         box_sizer1.Add(self.sizer_constraints, flag=wx.TOP | wx.BOTTOM, 
    381                        border=10) 
    382         box_sizer1.Add(sizer_button, flag=wx.TOP | wx.BOTTOM, border=10) 
    383  
    384         self.constraints_sizer.Add(box_sizer1, 0, wx.EXPAND | wx.ALL, 10) 
     352        boxsizer1.Add(sizer_title, flag=wx.TOP | wx.BOTTOM, border=10) 
     353        boxsizer1.Add(self.sizer_all_constraints, flag=wx.TOP | wx.BOTTOM, 
     354                      border=10) 
     355        boxsizer1.Add(self.sizer_constraints, flag=wx.TOP | wx.BOTTOM, 
     356                      border=10) 
     357        boxsizer1.Add(sizer_button, flag=wx.TOP | wx.BOTTOM, border=10) 
     358 
     359        self.sizer2.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10) 
     360 
    385361 
    386362    def _fill_sizer_fit(self): 
     
    388364        Draw fit button 
    389365        """ 
    390         self.run_fit_sizer.Clear(True) 
     366        self.sizer3.Clear(True) 
    391367        box_description = wx.StaticBox(self, wx.ID_ANY, "Fit ") 
    392368        boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 
    393369        sizer_button = wx.BoxSizer(wx.HORIZONTAL) 
    394370 
    395         # Fit button 
     371        #Fit button 
    396372        self.btFit = wx.Button(self, self.ID_FIT, 'Fit', size=wx.DefaultSize) 
    397         self.btFit.Bind(wx.EVT_BUTTON, self.on_fit, id=self.btFit.GetId()) 
     373        self.btFit.Bind(wx.EVT_BUTTON, self.onFit, id=self.btFit.GetId()) 
    398374        self.btFit.SetToolTipString("Perform fit.") 
    399375 
    400         # General Help button 
     376        #General Help button 
    401377        self.btHelp = wx.Button(self, wx.ID_HELP, 'HELP') 
    402378        self.btHelp.SetToolTipString("Simultaneous/Constrained Fitting help.") 
    403         self.btHelp.Bind(wx.EVT_BUTTON, self._on_help) 
    404  
    405         # hint text on button line 
     379        self.btHelp.Bind(wx.EVT_BUTTON, self._onHelp) 
     380 
     381        #hint text on button line 
    406382        if self.batch_on: 
    407383            text = " Fit in Parallel all Data sets\n" 
     
    417393 
    418394        boxsizer1.Add(sizer_button, flag=wx.TOP | wx.BOTTOM, border=10) 
    419         self.run_fit_sizer.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10) 
    420  
    421     def on_remove(self, event): 
     395        self.sizer3.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10) 
     396 
     397    def onRemove(self, event): 
    422398        """ 
    423399        Remove constraint fields 
     
    430406            return 
    431407        wx.CallAfter(self._remove_after, event.GetId()) 
    432         # self._onAdd_constraint(None) 
     408        #self._onAdd_constraint(None) 
    433409 
    434410    def _remove_after(self, id): 
     
    440416                self.constraints_list.remove(item) 
    441417                self.nb_constraint -= 1 
    442                 self.constraints_sizer.Layout() 
     418                self.sizer2.Layout() 
    443419                self.FitInside() 
    444420                break 
    445421 
    446     def on_fit(self, event): 
     422    def onFit(self, event): 
    447423        """ 
    448424        signal for fitting 
     
    459435            flag = (self._manager.sim_page.uid == self.uid) 
    460436 
    461         # making sure all parameters content a constraint 
     437        ## making sure all parameters content a constraint 
    462438        if not self.batch_on and self.show_constraint.GetValue(): 
    463439            if not self._set_constraint(): 
    464440                return 
    465         # model was actually selected from this page to be fit 
    466         if len(self.model_to_fit) >= 1: 
     441        ## model was actually selected from this page to be fit 
     442        if len(self.model_toFit) >= 1: 
    467443            self.manager._reset_schedule_problem(value=0) 
    468444            for item in self.model_list: 
     
    480456            msg = "Select at least one model check box to fit " 
    481457            wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 
    482         self.set_state() 
    483458 
    484459    def _on_fit_complete(self): 
     
    492467        """ 
    493468        Attempt to stop the fitting thread 
    494  
    495         :param event: Event handler when stop fit is clicked 
    496         """ 
    497         if event is not None: 
     469        """ 
     470        if event != None: 
    498471            event.Skip() 
    499472        self.manager.stop_fit(self.uid) 
     
    512485        self.btFit.Enable(True) 
    513486 
    514     def _on_help(self, event): 
     487    def _onHelp(self, event): 
    515488        """ 
    516489        Bring up the simultaneous Fitting Documentation whenever the HELP 
     
    521494        versions of Wx (before 2.9) and thus not the release version of 
    522495        installers, the help comes up at the top level of the file as 
    523         web browser does not pass anything past the # to the browser when it is 
     496        webbrowser does not pass anything past the # to the browser when it is 
    524497        running "file:///...." 
    525498 
    526     :param event: Triggers on clicking the help button 
     499    :param evt: Triggers on clicking the help button 
    527500    """ 
    528501        _TreeLocation = "user/sasgui/perspectives/fitting/fitting_help.html" 
     
    537510 
    538511        :param manager: instance of plugin fitting 
     512 
    539513        """ 
    540514        self.manager = manager 
     
    544518        check all models names 
    545519        """ 
    546         self.model_to_fit = [] 
    547         if self.cb1.GetValue(): 
     520        self.model_toFit = [] 
     521        if self.cb1.GetValue() == True: 
    548522            for item in self.model_list: 
    549523                if item[0].IsEnabled(): 
    550524                    item[0].SetValue(True) 
    551                     self.model_to_fit.append(item) 
    552  
    553             # constraint info 
     525                    self.model_toFit.append(item) 
     526 
     527            ## constraint info 
    554528            self._store_model() 
    555529            if not self.batch_on: 
    556                 # display constraint fields 
     530                ## display constraint fields 
    557531                if (self.show_constraint.GetValue() and 
    558532                                 len(self.constraints_list) == 0): 
     
    564538 
    565539            if not self.batch_on: 
    566                 # constraint info 
     540                ##constraint info 
    567541                self._hide_constraint() 
    568542 
     
    570544        self.FitInside() 
    571545 
     546 
    572547    def check_model_name(self, event): 
    573548        """ 
    574549        Save information related to checkbox and their states 
    575550        """ 
    576         self.model_to_fit = [] 
     551        self.model_toFit = [] 
     552        cbox = event.GetEventObject() 
    577553        for item in self.model_list: 
    578             if item[0].GetValue(): 
    579                 self.model_to_fit.append(item) 
     554            if item[0].GetValue() == True: 
     555                self.model_toFit.append(item) 
    580556            else: 
    581                 if item in self.model_to_fit: 
    582                     self.model_to_fit.remove(item) 
     557                if item in self.model_toFit: 
     558                    self.model_toFit.remove(item) 
    583559                    self.cb1.SetValue(False) 
    584560 
    585         # display constraint fields 
    586         if len(self.model_to_fit) >= 1: 
     561        ## display constraint fields 
     562        if len(self.model_toFit) >= 1: 
    587563            self._store_model() 
    588564            if not self.batch_on and self.show_constraint.GetValue() and\ 
     
    591567                self._show_constraint() 
    592568 
    593         elif len(self.model_to_fit) < 1: 
    594             # constraint info 
     569        elif len(self.model_toFit) < 1: 
     570            ##constraint info 
    595571            self._hide_constraint() 
    596572 
    597573        self._update_easy_setup_cb() 
    598         # set the value of the main check button 
    599         if len(self.model_list) == len(self.model_to_fit): 
     574        ## set the value of the main check button 
     575        if len(self.model_list) == len(self.model_toFit): 
    600576            self.cb1.SetValue(True) 
    601577            self.FitInside() 
     
    609585        Update easy setup combobox on selecting a model 
    610586        """ 
    611         if self.model_cbox_left is None or self.model_cbox_right is None: 
    612             return 
    613  
    614         models = [(item[3].name, item[3]) for item in self.model_to_fit] 
     587        if self.model_cbox_left == None or self.model_cbox_right == None: 
     588            return 
     589 
     590        models = [(item[3].name, item[3]) for item in self.model_toFit] 
    615591        setComboBoxItems(self.model_cbox_left, models) 
    616592        setComboBoxItems(self.model_cbox_right, models) 
     
    619595        if self.model_cbox_left.GetSelection() == wx.NOT_FOUND: 
    620596            self.model_cbox_left.SetSelection(0) 
    621         self.constraints_sizer.Layout() 
     597        self.sizer2.Layout() 
    622598 
    623599    def _store_model(self): 
     
    625601         Store selected model 
    626602        """ 
    627         if len(self.model_to_fit) < 1: 
    628             return 
    629         for item in self.model_to_fit: 
     603        if len(self.model_toFit) < 1: 
     604            return 
     605        for item in self.model_toFit: 
    630606            model = item[3] 
    631607            page_id = item[2] 
     
    636612        Show fields to add constraint 
    637613        """ 
    638         if len(self.model_to_fit) < 1: 
     614        if len(self.model_toFit) < 1: 
    639615            msg = "Select at least 1 model to add constraint " 
    640616            wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 
    641             # hide button 
     617            ## hide button 
    642618            self._hide_constraint() 
    643619            return 
     
    656632        """ 
    657633        box_description = wx.StaticBox(self, wx.ID_ANY, "Easy Setup ") 
    658         box_sizer = wx.StaticBoxSizer(box_description, wx.HORIZONTAL) 
     634        boxsizer = wx.StaticBoxSizer(box_description, wx.HORIZONTAL) 
    659635        sizer_constraint = wx.BoxSizer(wx.HORIZONTAL) 
    660636        self.model_cbox_left = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY) 
     
    674650 
    675651        for id, model in self.constraint_dict.iteritems(): 
    676             # check if all parameters have been selected for constraint 
    677             # then do not allow add constraint on parameters 
     652            ## check if all parameters have been selected for constraint 
     653            ## then do not allow add constraint on parameters 
    678654            self.model_cbox_left.Append(str(model.name), model) 
    679655        self.model_cbox_left.Select(0) 
    680656        for id, model in self.constraint_dict.iteritems(): 
    681             # check if all parameters have been selected for constraint 
    682             # then do not allow add constraint on parameters 
     657            ## check if all parameters have been selected for constraint 
     658            ## then do not allow add constraint on parameters 
    683659            self.model_cbox_right.Append(str(model.name), model) 
    684         box_sizer.Add(self.model_cbox_left, 
     660        boxsizer.Add(self.model_cbox_left, 
    685661                             flag=wx.RIGHT | wx.EXPAND, border=10) 
    686         # box_sizer.Add(wx.StaticText(self, wx.ID_ANY, ".parameters"), 
     662        #boxsizer.Add(wx.StaticText(self, wx.ID_ANY, ".parameters"), 
    687663        #                     flag=wx.RIGHT | wx.EXPAND, border=5) 
    688         box_sizer.Add(egal_txt, flag=wx.RIGHT | wx.EXPAND, border=5) 
    689         box_sizer.Add(self.model_cbox_right, 
     664        boxsizer.Add(egal_txt, flag=wx.RIGHT | wx.EXPAND, border=5) 
     665        boxsizer.Add(self.model_cbox_right, 
    690666                             flag=wx.RIGHT | wx.EXPAND, border=10) 
    691         # box_sizer.Add(wx.StaticText(self, wx.ID_ANY, ".parameters"), 
     667        #boxsizer.Add(wx.StaticText(self, wx.ID_ANY, ".parameters"), 
    692668        #                     flag=wx.RIGHT | wx.EXPAND, border=5) 
    693         box_sizer.Add((20, -1)) 
    694         box_sizer.Add(self.set_button, flag=wx.RIGHT | wx.EXPAND, border=5) 
    695         sizer_constraint.Add(box_sizer, flag=wx.RIGHT | wx.EXPAND, border=5) 
     669        boxsizer.Add((20, -1)) 
     670        boxsizer.Add(self.set_button, flag=wx.RIGHT | wx.EXPAND, border=5) 
     671        sizer_constraint.Add(boxsizer, flag=wx.RIGHT | wx.EXPAND, border=5) 
    696672        self.sizer_all_constraints.Insert(before=0, 
    697673                             item=sizer_constraint, 
     
    723699            return 
    724700        param_list = [] 
    725         param_list_b = [] 
     701        param_listB = [] 
    726702        selection = self.model_cbox_left.GetCurrentSelection() 
    727703        model_left = self.model_cbox_left.GetValue() 
    728704        model = self.model_cbox_left.GetClientData(selection) 
    729         selection_b = self.model_cbox_right.GetCurrentSelection() 
     705        selectionB = self.model_cbox_right.GetCurrentSelection() 
    730706        model_right = self.model_cbox_right.GetValue() 
    731         model_b = self.model_cbox_right.GetClientData(selection_b) 
     707        modelB = self.model_cbox_right.GetClientData(selectionB) 
    732708        for id, dic_model in self.constraint_dict.iteritems(): 
    733709            if model == dic_model: 
    734710                param_list = self.page_finder[id].get_param2fit() 
    735             if model_b == dic_model: 
    736                 param_list_b = self.page_finder[id].get_param2fit() 
    737             if len(param_list) > 0 and len(param_list_b) > 0: 
     711            if modelB == dic_model: 
     712                param_listB = self.page_finder[id].get_param2fit() 
     713            if len(param_list) > 0 and len(param_listB) > 0: 
    738714                break 
    739715        num_cbox = 0 
     
    741717        for param in param_list: 
    742718            num_cbox += 1 
    743             if param in param_list_b: 
     719            if param in param_listB: 
    744720                item = self.constraints_list[-1] 
    745721                item.model_cbox.SetStringSelection(model_left) 
     
    768744        """ 
    769745        Show constraint fields 
    770         :param dict: dictionary mapping constraint values 
    771746        """ 
    772747        self.btAdd.Show(True) 
     
    775750            for id, model in self.constraint_dict.iteritems(): 
    776751                nb_fit_param += len(self.page_finder[id].get_param2fit()) 
    777             # Don't add anymore 
     752            ##Don't add anymore 
    778753            if len(self.constraints_list) == nb_fit_param: 
    779754                msg = "Cannot add another constraint. Maximum of number " 
     
    781756                wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 
    782757                self.sizer_constraints.Layout() 
    783                 self.constraints_sizer.Layout() 
     758                self.sizer2.Layout() 
    784759                return 
    785         if len(self.model_to_fit) < 1: 
     760        if len(self.model_toFit) < 1: 
    786761            msg = "Select at least 1 model to add constraint " 
    787762            wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 
    788763            self.sizer_constraints.Layout() 
    789             self.constraints_sizer.Layout() 
     764            self.sizer2.Layout() 
    790765            return 
    791766 
     
    796771        model_cbox.Clear() 
    797772        for id, model in self.constraint_dict.iteritems(): 
    798             # check if all parameters have been selected for constraint 
    799             # then do not allow add constraint on parameters 
     773            ## check if all parameters have been selected for constraint 
     774            ## then do not allow add constraint on parameters 
    800775            model_cbox.Append(str(model.name), model) 
    801776        wx.EVT_COMBOBOX(model_cbox, wx.ID_ANY, self._on_select_model) 
     
    814789        # Remove button 
    815790        #btRemove = wx.Button(self, self.ID_REMOVE, 'Remove') 
    816         bt_remove = wx.Button(self, self._ids.next(), 'Remove') 
    817         bt_remove.Bind(wx.EVT_BUTTON, self.on_remove, 
    818                       id=bt_remove.GetId()) 
    819         bt_remove.SetToolTipString("Remove constraint.") 
    820         bt_remove.Hide() 
     791        btRemove = wx.Button(self, self._ids.next(), 'Remove') 
     792        btRemove.Bind(wx.EVT_BUTTON, self.onRemove, 
     793                      id=btRemove.GetId()) 
     794        btRemove.SetToolTipString("Remove constraint.") 
     795        btRemove.Hide() 
    821796 
    822797        # Hid the add button, if it exists 
     
    829804        sizer_constraint.Add(egal_txt, flag=wx.RIGHT | wx.EXPAND, border=5) 
    830805        sizer_constraint.Add(constraint, flag=wx.RIGHT | wx.EXPAND, border=10) 
    831         sizer_constraint.Add(bt_remove, flag=wx.RIGHT | wx.EXPAND, border=10) 
     806        sizer_constraint.Add(btRemove, flag=wx.RIGHT | wx.EXPAND, border=10) 
    832807 
    833808        self.sizer_constraints.Insert(before=self.nb_constraint, 
     
    835810                border=5) 
    836811        c = ConstraintLine(model_cbox, param_cbox, egal_txt, 
    837                            constraint, bt_remove, sizer_constraint) 
     812                           constraint, btRemove, sizer_constraint) 
    838813        self.constraints_list.append(c) 
    839814 
    840815        self.nb_constraint += 1 
    841816        self.sizer_constraints.Layout() 
    842         self.constraints_sizer.Layout() 
    843         self.Layout() 
     817        self.sizer2.Layout() 
     818        self.Layout 
    844819 
    845820    def _hide_constraint(self): 
     
    866841        self.sizer_constraints.Clear(True) 
    867842        self.sizer_constraints.Layout() 
    868         self.constraints_sizer.Layout() 
    869         self.Layout() 
     843        self.sizer2.Layout() 
     844        self.Layout 
    870845        self.FitInside() 
    871846 
    872847    def _on_select_model(self, event): 
    873848        """ 
    874         fill combo box with list of parameters 
     849        fill combox box with list of parameters 
    875850        """ 
    876851        if not self.constraints_list: 
    877852            return 
    878853 
    879         # This way PC/MAC both work, instead of using event.GetClientData(). 
     854        ##This way PC/MAC both work, instead of using event.GetClientData(). 
    880855        model_cbox = self.constraints_list[-1].model_cbox 
    881856        n = model_cbox.GetCurrentSelection() 
     
    892867        param_cbox = self.constraints_list[-1].param_cbox 
    893868        param_cbox.Clear() 
    894         # insert only fittable paramaters 
     869        ## insert only fittable paramaters 
    895870        for param in param_list: 
    896871            param_cbox.Append(str(param), model) 
    897872        param_cbox.Show(True) 
    898873 
    899         bt_remove = self.constraints_list[-1].btRemove 
    900         bt_remove.Show(True) 
     874        btRemove = self.constraints_list[-1].btRemove 
     875        btRemove.Show(True) 
    901876        self.btAdd.Show(True) 
    902877#        self.Layout() 
     
    907882        Store the appropriate constraint in the page_finder 
    908883        """ 
    909         # This way PC/MAC both work, instead of using event.GetClientData(). 
    910         # n = self.param_cbox.GetCurrentSelection() 
    911         # model = self.param_cbox.GetClientData(n) 
    912         # param = event.GetString() 
     884        ##This way PC/MAC both work, instead of using event.GetClientData(). 
     885        #n = self.param_cbox.GetCurrentSelection() 
     886        #model = self.param_cbox.GetClientData(n) 
     887        #param = event.GetString() 
    913888 
    914889        if self.constraints_list: 
     
    916891            self.constraints_list[-1].constraint.Show(True) 
    917892 
    918     def _on_add_constraint(self, event): 
     893    def _onAdd_constraint(self, event): 
    919894        """ 
    920895        Add another line for constraint 
     
    924899            wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 
    925900            return 
    926         # check that a constraint is added 
     901        ## check that a constraint is added 
    927902        # before allow to add another constraint 
    928903        for item in self.constraints_list: 
     
    938913                model = item.param_cbox.GetClientData( 
    939914                                        item.param_cbox.GetCurrentSelection()) 
    940                 if model is not None: 
     915                if model != None: 
    941916                    msg = " Enter a constraint for %s.%s! " % (model.name, 
    942917                                        item.param_cbox.GetString(0)) 
     
    945920                wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 
    946921                return 
    947         # some model or parameters can be constrained 
     922        ## some model or parameters can be constrained 
    948923        self._show_constraint() 
    949924        self.FitInside() 
     
    1005980    def on_set_focus(self, event=None): 
    1006981        """ 
    1007         The derivative class is on focus if implemented 
     982        The  derivative class is on focus if implemented 
    1008983        """ 
    1009984        if self.parent is not None: 
     
    1020995        cbox.Append(name, value) 
    1021996    cbox.SetStringSelection(selected) 
    1022  
    1023  
    1024 class SimFitPageState: 
    1025     """ 
    1026     State of the simultaneous fit page for saving purposes 
    1027     """ 
    1028  
    1029     def __init__(self): 
    1030         # Sim Fit Page Number 
    1031         self.fit_page_no = None 
    1032         # Select all data 
    1033         self.select_all = False 
    1034         # Data sets sent to fit page 
    1035         self.model_list = [] 
    1036         # Data sets to be fit 
    1037         self.model_to_fit = [] 
    1038         # Number of constraints 
    1039         self.no_constraint = 0 
    1040         # Dictionary of constraints 
    1041         self.constraint_dict = {} 
    1042         # List of constraints 
    1043         self.constraints_list = [] 
    1044  
    1045     def load_from_save_state(self, fit): 
    1046         """ 
    1047         Load in a simultaneous/constrained fit from a save state 
    1048         :param fit: Fitpanel object 
    1049         :return: None 
    1050         """ 
    1051  
    1052         model_map = {} 
    1053         fit.fit_panel.add_sim_page() 
    1054  
    1055         # Process each model and associate old M# with new M# 
    1056         i = 0 
    1057         for model in fit.fit_panel.sim_page.model_list: 
    1058             model_id = self._format_id(model[1].keys()[0]) 
    1059             for saved_model in self.model_list: 
    1060                 save_id = saved_model.pop('name') 
    1061                 saved_model['name'] = save_id 
    1062                 save_id = self._format_id(save_id) 
    1063                 if save_id == model_id: 
    1064                     model_map[saved_model.pop('fit_page_source')] = \ 
    1065                         model[3].name 
    1066                     check = bool(saved_model.pop('checked')) 
    1067                     fit.fit_panel.sim_page.model_list[i][0].SetValue(check) 
    1068                     continue 
    1069             i += 1 
    1070         fit.fit_panel.sim_page.check_model_name(None) 
    1071  
    1072         if len(self.constraints_list) > 0: 
    1073             fit.fit_panel.sim_page.hide_constraint.SetValue(False) 
    1074             fit.fit_panel.sim_page.show_constraint.SetValue(True) 
    1075             fit.fit_panel.sim_page._display_constraint(None) 
    1076  
    1077         for constraint in self.constraints_list: 
    1078             model_cbox = constraint.pop('model_cbox') 
    1079             constraint_value = constraint.pop('constraint') 
    1080             for key, value in model_map.iteritems(): 
    1081                 model_cbox.replace(key, value) 
    1082                 constraint_value.replace(key, value) 
    1083  
    1084             bt_remove = wx.Button(fit.fit_panel.sim_page, 
    1085                                   fit.fit_panel.sim_page._ids.next(), 'Remove') 
    1086             bt_remove.Bind(wx.EVT_BUTTON, fit.fit_panel.sim_page.on_remove, 
    1087                            id=bt_remove.GetId()) 
    1088             bt_remove.SetToolTipString("Remove constraint.") 
    1089             param_cbox = wx.ComboBox(fit.fit_panel.sim_page, wx.ID_ANY, 
    1090                                      style=wx.CB_READONLY, size=(100, -1)) 
    1091             egal_txt = wx.StaticText(fit.fit_panel.sim_page, wx.ID_ANY, " = ") 
    1092             # Model list 
    1093             model_cbox_sizer = wx.ComboBox(fit.fit_panel.sim_page, 
    1094                                            wx.ID_ANY, style=wx.CB_READONLY) 
    1095             model_cbox_sizer.Clear() 
    1096             wx.EVT_COMBOBOX(model_cbox_sizer, wx.ID_ANY, 
    1097                             fit.fit_panel.sim_page._on_select_model) 
    1098             constraint_sizer = wx.TextCtrl(fit.fit_panel.sim_page, wx.ID_ANY) 
    1099             sizer_constraint = wx.BoxSizer(wx.HORIZONTAL) 
    1100             sizer_constraint.Add((5, -1)) 
    1101             sizer_constraint.Add(model_cbox_sizer, flag=wx.RIGHT | wx.EXPAND, 
    1102                                  border=10) 
    1103             sizer_constraint.Add(param_cbox, flag=wx.RIGHT | wx.EXPAND, 
    1104                                  border=5) 
    1105             sizer_constraint.Add(egal_txt, flag=wx.RIGHT | wx.EXPAND, border=5) 
    1106             sizer_constraint.Add(constraint_sizer, flag=wx.RIGHT | wx.EXPAND, 
    1107                                  border=10) 
    1108             sizer_constraint.Add(bt_remove, flag=wx.RIGHT | wx.EXPAND, 
    1109                                  border=10) 
    1110             new_const = ConstraintLine(model_cbox=model_cbox_sizer, 
    1111                                        param_cbox=constraint.pop('param_cbox'), 
    1112                                        egal_txt=constraint.pop('egal_txt'), 
    1113                                        constraint=constraint_value, 
    1114                                        btRemove=bt_remove, 
    1115                                        sizer=sizer_constraint 
    1116                                        ) 
    1117             # ConstraintLine = namedtuple('ConstraintLine', 
    1118             #      'model_cbox param_cbox egal_txt constraint btRemove sizer') 
    1119             fit.fit_panel.sim_page.sizer_constraints.Insert( 
    1120                 before=fit.fit_panel.sim_page.nb_constraint, 
    1121                 item=sizer_constraint, flag=wx.TOP | wx.BOTTOM | wx.EXPAND, 
    1122                 border=5) 
    1123             fit.fit_panel.sim_page.constraints_list.append(new_const) 
    1124  
    1125     def _format_id(self, original_id): 
    1126         original_id = original_id.rstrip('1234567890.') 
    1127         new_id_list = original_id.split() 
    1128         new_id = ' '.join(new_id_list) 
    1129         return new_id 
Note: See TracChangeset for help on using the changeset viewer.