Ignore:
Timestamp:
Nov 23, 2015 1:29:38 AM (8 years ago)
Author:
butler
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
3596467
Parents:
80ba1a2
Message:

add self.FitInside? and some Layout calls to ensure resizing whenever
items are added and removed. fixes #480.

Also added help button which fixes #479

File:
1 edited

Legend:

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

    rd7b4decd r662d8d87  
    1313from sas.guiframe.events import PanelOnFocusEvent 
    1414from sas.guiframe.utils import IdList 
     15from sas.guiframe.documentation_window import DocumentationWindow 
    1516 
    1617#Control panel width  
     
    3031def get_fittableParam(model): 
    3132    """ 
    32     return list of fittable parameters name of a model 
     33    return list of fittable parameters from a model 
    3334 
    3435    :param model: the model used 
     
    5657    ## Title to appear on top of the window 
    5758    window_caption = "Simultaneous Fit Page" 
     59    ID_DOC = wx.NewId() 
    5860    ID_SET_ALL = wx.NewId() 
    5961    ID_FIT = wx.NewId() 
     
    7981        ## store page_finder 
    8082        self.page_finder = page_finder 
    81         ## list contaning info to set constraint 
     83        ## list containing info to set constraint 
    8284        ## look like self.constraint_dict[page_id]= page 
    8385        self.constraint_dict = {} 
    8486        ## item list 
    85         # self.constraints_list=[combobox1, combobox2,=,textcrtl, button ] 
     87        ## self.constraints_list=[combobox1, combobox2,=,textcrtl, button ] 
    8688        self.constraints_list = [] 
    8789        ## list of current model 
     
    9698        self.define_page_structure() 
    9799        self.draw_page() 
    98         self.set_layout() 
    99100        self._set_save_flag(False) 
    100101 
    101102    def define_page_structure(self): 
    102103        """ 
    103         Create empty sizer for a panel 
     104        Create empty sizers, their hierarchy and set the sizer for the panel 
    104105        """ 
    105106        self.vbox = wx.BoxSizer(wx.VERTICAL) 
     
    114115        self.vbox.Add(self.sizer2) 
    115116        self.vbox.Add(self.sizer3) 
    116  
    117     def set_scroll(self): 
    118         """ 
    119         """ 
    120         self.Layout() 
    121  
    122     def set_layout(self): 
    123         """ 
    124         layout 
    125         """ 
    126         self.vbox.Layout() 
    127         self.vbox.Fit(self) 
    128117        self.SetSizer(self.vbox) 
    129         self.set_scroll() 
    130118        self.Centre() 
     119 
     120    def draw_page(self): 
     121        """ 
     122        Construct the Simultaneous/Constrained fit page. fills the first 
     123        region (sizer1) with the list of available fit page pairs of data  
     124        and models.  Then fills sizer2 with the checkbox for adding 
     125        constraints, and finally fills sizer3 with the fit button and 
     126        instructions. 
     127        """ 
     128 
     129        # create blank list of constraints 
     130        self.model_list = [] 
     131        self.model_toFit = [] 
     132        self.constraints_list = [] 
     133        self.constraint_dict = {} 
     134        self.nb_constraint = 0 
     135        self.model_cbox_left = None 
     136        self.model_cbox_right = None 
     137 
     138        if len(self.model_list) > 0: 
     139            for item in self.model_list: 
     140                item[0].SetValue(False) 
     141                self.manager.schedule_for_fit(value=0, uid=item[2]) 
     142 
     143        #------------------------------------------------------- 
     144        ## setup sizer1 (which fitpages to include) 
     145        self.sizer1.Clear(True) 
     146        box_description = wx.StaticBox(self, wx.ID_ANY, "Fit Combinations") 
     147        boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 
     148        sizer_title = wx.BoxSizer(wx.HORIZONTAL) 
     149        sizer_couples = wx.GridBagSizer(5, 5) 
     150 
     151        #This if statement should be obsolete and can be removed in version 4 
     152        #Leave it here for now as no time to thoroughly test.  However if no 
     153        #fit page is found the menu item that calls this page is inactive  
     154        # Nov. 22 2015  --PDB 
     155        if len(self.page_finder) == 0: 
     156            msg = " No fit combinations are found! \n\n" 
     157            msg += " Please load data and set up " 
     158            msg += "at least one fit panels first..." 
     159            sizer_title.Add(wx.StaticText(self, wx.ID_ANY, msg)) 
     160        else: 
     161            ## store model 
     162            self._store_model() 
     163 
     164            self.cb1 = wx.CheckBox(self, wx.ID_ANY, 'Select all') 
     165            self.cb1.SetValue(False) 
     166            wx.EVT_CHECKBOX(self, self.cb1.GetId(), self.check_all_model_name) 
     167 
     168            sizer_title.Add((10, 10), 0, 
     169                wx.TOP | wx.BOTTOM | wx.EXPAND | wx.ADJUST_MINSIZE, border=5) 
     170            sizer_title.Add(self.cb1, 0, 
     171                wx.TOP | wx.BOTTOM | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, border=5) 
     172 
     173            ## draw list of model and data names 
     174            self._fill_sizer_model_list(sizer_couples) 
     175 
     176        boxsizer1.Add(sizer_title, flag=wx.TOP | wx.BOTTOM, border=5) 
     177        boxsizer1.Add(sizer_couples, 1, flag=wx.TOP | wx.BOTTOM, border=5) 
     178        self.sizer1.Add(boxsizer1, 1, wx.EXPAND | wx.ALL, 10) 
     179#        self.sizer1.Layout() 
     180 
     181        #-------------------------------------------------------- 
     182        ## set up the other 2 sizers: the constraints list and the 
     183        ## buttons (fit, help etc) sizer at the bottom of the page. 
     184        ## Note: the if statement should be removed along with the above 
     185        ## if statement as soon as it can be properly tested. 
     186        ## Nov. 22 2015  --PDB 
     187        if len(self.page_finder) > 0: 
     188            ## draw the sizer containing constraint info 
     189            if not self.batch_on: 
     190                self._fill_sizer_constraint() 
     191            ## draw fit button sizer 
     192            self._fill_sizer_fit() 
     193 
     194 
     195    def _fill_sizer_model_list(self, sizer): 
     196        """ 
     197        Receive a dictionary containing information to display model name 
     198        """ 
     199        ix = 0 
     200        iy = 0 
     201        list = [] 
     202        sizer.Clear(True) 
     203 
     204        new_name = wx.StaticText(self, wx.ID_ANY, '  Model Title ', 
     205                                 style=wx.ALIGN_CENTER) 
     206        new_name.SetBackgroundColour('orange') 
     207        new_name.SetForegroundColour(wx.WHITE) 
     208        sizer.Add(new_name, (iy, ix), (1, 1), 
     209                            wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
     210        ix += 2 
     211        model_type = wx.StaticText(self, wx.ID_ANY, '  Model ') 
     212        model_type.SetBackgroundColour('grey') 
     213        model_type.SetForegroundColour(wx.WHITE) 
     214        sizer.Add(model_type, (iy, ix), (1, 1), 
     215                            wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     216        ix += 1 
     217        data_used = wx.StaticText(self, wx.ID_ANY, '  Data ') 
     218        data_used.SetBackgroundColour('grey') 
     219        data_used.SetForegroundColour(wx.WHITE) 
     220        sizer.Add(data_used, (iy, ix), (1, 1), 
     221                            wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     222        ix += 1 
     223        tab_used = wx.StaticText(self, wx.ID_ANY, '  FitPage ') 
     224        tab_used.SetBackgroundColour('grey') 
     225        tab_used.SetForegroundColour(wx.WHITE) 
     226        sizer.Add(tab_used, (iy, ix), (1, 1), 
     227                  wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     228        for id, value in self.page_finder.iteritems(): 
     229            if id not in self.parent.opened_pages: 
     230                continue 
     231 
     232            if self.batch_on != self.parent.get_page_by_id(id).batch_on: 
     233                continue 
     234 
     235            data_list = [] 
     236            model_list = [] 
     237            # get data name and model objetta 
     238            for fitproblem in value.get_fit_problem(): 
     239 
     240                data = fitproblem.get_fit_data() 
     241                if not data.is_data: 
     242                    continue 
     243                name = '-' 
     244                if data is not None and data.is_data: 
     245                    name = str(data.name) 
     246                data_list.append(name) 
     247 
     248                model = fitproblem.get_model() 
     249                if model is None: 
     250                    continue 
     251                model_list.append(model) 
     252 
     253            if len(model_list) == 0: 
     254                continue 
     255            # Draw sizer 
     256            ix = 0 
     257            iy += 1 
     258            model = model_list[0] 
     259            name = '_' 
     260            if model is not None: 
     261                name = str(model.name) 
     262            cb = wx.CheckBox(self, wx.ID_ANY, name) 
     263            cb.SetValue(False) 
     264            cb.Enable(model is not None and data.is_data) 
     265            sizer.Add(cb, (iy, ix), (1, 1), 
     266                      wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
     267            wx.EVT_CHECKBOX(self, cb.GetId(), self.check_model_name) 
     268            ix += 2 
     269            model_type = wx.StaticText(self, wx.ID_ANY, 
     270                                       model.__class__.__name__) 
     271            sizer.Add(model_type, (iy, ix), (1, 1), 
     272                      wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     273            if self.batch_on: 
     274                data_used = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY) 
     275                data_used.AppendItems(data_list) 
     276                data_used.SetSelection(0) 
     277            else: 
     278                data_used = wx.StaticText(self, wx.ID_ANY, data_list[0]) 
     279 
     280            ix += 1 
     281            sizer.Add(data_used, (iy, ix), (1, 1), 
     282                      wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     283            ix += 1 
     284            caption = value.get_fit_tab_caption() 
     285            tab_caption_used = wx.StaticText(self, wx.ID_ANY, str(caption)) 
     286            sizer.Add(tab_caption_used, (iy, ix), (1, 1), 
     287                      wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     288 
     289            self.model_list.append([cb, value, id, model]) 
     290 
     291        iy += 1 
     292        sizer.Add((20, 20), (iy, ix), (1, 1), 
     293                  wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
     294 
     295    def _fill_sizer_constraint(self): 
     296        """ 
     297        Fill sizer containing constraint info 
     298        """ 
     299        msg = "Select at least 1 model to add constraint " 
     300        wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 
     301 
     302        self.sizer2.Clear(True) 
     303        if self.batch_on: 
     304            if self.sizer2.IsShown(): 
     305                self.sizer2.Show(False) 
     306            return 
     307        box_description = wx.StaticBox(self, wx.ID_ANY, "Fit Constraints") 
     308        boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 
     309        sizer_title = wx.BoxSizer(wx.HORIZONTAL) 
     310        self.sizer_all_constraints = wx.BoxSizer(wx.HORIZONTAL) 
     311        self.sizer_constraints = wx.BoxSizer(wx.VERTICAL) 
     312        sizer_button = wx.BoxSizer(wx.HORIZONTAL) 
     313 
     314        self.hide_constraint = wx.RadioButton(self, wx.ID_ANY, 'No', (10, 10), 
     315                                              style=wx.RB_GROUP) 
     316        self.show_constraint = wx.RadioButton(self, wx.ID_ANY, 'Yes', (10, 30)) 
     317        self.Bind(wx.EVT_RADIOBUTTON, self._display_constraint, 
     318                  id=self.hide_constraint.GetId()) 
     319        self.Bind(wx.EVT_RADIOBUTTON, self._display_constraint, 
     320                  id=self.show_constraint.GetId()) 
     321        if self.batch_on: 
     322            self.hide_constraint.Enable(False) 
     323            self.show_constraint.Enable(False) 
     324        self.hide_constraint.SetValue(True) 
     325        self.show_constraint.SetValue(False) 
     326 
     327        sizer_title.Add(wx.StaticText(self, wx.ID_ANY, " Model")) 
     328        sizer_title.Add((10, 10)) 
     329        sizer_title.Add(wx.StaticText(self, wx.ID_ANY, " Parameter")) 
     330        sizer_title.Add((10, 10)) 
     331        sizer_title.Add(wx.StaticText(self, wx.ID_ANY, " Add Constraint?")) 
     332        sizer_title.Add((10, 10)) 
     333        sizer_title.Add(self.show_constraint) 
     334        sizer_title.Add(self.hide_constraint) 
     335        sizer_title.Add((10, 10)) 
     336 
     337        self.btAdd = wx.Button(self, self.ID_ADD, 'Add') 
     338        self.btAdd.Bind(wx.EVT_BUTTON, self._onAdd_constraint, 
     339                        id=self.btAdd.GetId()) 
     340        self.btAdd.SetToolTipString("Add another constraint?") 
     341        self.btAdd.Hide() 
     342 
     343        text_hint = wx.StaticText(self, wx.ID_ANY, 
     344                                  "Example: [M0][paramter] = M1.parameter") 
     345        sizer_button.Add(text_hint, 0, 
     346                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 10) 
     347        sizer_button.Add(self.btAdd, 0, 
     348                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 10) 
     349 
     350        boxsizer1.Add(sizer_title, flag=wx.TOP | wx.BOTTOM, border=10) 
     351        boxsizer1.Add(self.sizer_all_constraints, flag=wx.TOP | wx.BOTTOM, 
     352                      border=10) 
     353        boxsizer1.Add(self.sizer_constraints, flag=wx.TOP | wx.BOTTOM, 
     354                      border=10) 
     355        boxsizer1.Add(sizer_button, flag=wx.TOP | wx.BOTTOM, border=10) 
     356 
     357        self.sizer2.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10) 
     358 
     359 
     360    def _fill_sizer_fit(self): 
     361        """ 
     362        Draw fit button 
     363        """ 
     364        self.sizer3.Clear(True) 
     365        box_description = wx.StaticBox(self, wx.ID_ANY, "Fit ") 
     366        boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 
     367        sizer_button = wx.BoxSizer(wx.HORIZONTAL) 
     368 
     369        #Fit button 
     370        self.btFit = wx.Button(self, self.ID_FIT, 'Fit', size=wx.DefaultSize) 
     371        self.btFit.Bind(wx.EVT_BUTTON, self.onFit, id=self.btFit.GetId()) 
     372        self.btFit.SetToolTipString("Perform fit.") 
     373 
     374        #General Help button 
     375        self.btHelp = wx.Button(self, wx.ID_HELP, 'HELP') 
     376        self.btHelp.SetToolTipString("Simultaneous/Constrained Fitting help.") 
     377        self.btHelp.Bind(wx.EVT_BUTTON, self._onHelp) 
     378 
     379        #hint text on button line 
     380        if self.batch_on: 
     381            text = " Fit in Parallel all Data sets\n" 
     382            text += "and model selected." 
     383        else: 
     384            text = " At least one set of model and data\n" 
     385            text += " must be selected for fitting." 
     386        text_hint = wx.StaticText(self, wx.ID_ANY, text) 
     387 
     388        sizer_button.Add(text_hint) 
     389        sizer_button.Add(self.btFit, 0, wx.LEFT | wx.ADJUST_MINSIZE, 10) 
     390        sizer_button.Add(self.btHelp, 0, wx.LEFT | wx.ADJUST_MINSIZE, 10) 
     391 
     392        boxsizer1.Add(sizer_button, flag=wx.TOP | wx.BOTTOM, border=10) 
     393        self.sizer3.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10) 
    131394 
    132395    def onRemove(self, event): 
     
    149412                item.sizer.Clear(True) 
    150413                self.sizer_constraints.Remove(item.sizer) 
    151                 ##self.SetScrollbars(20,20,25,65) 
    152414                self.constraints_list.remove(item) 
    153415                self.nb_constraint -= 1 
    154416                self.sizer2.Layout() 
    155                 self.Layout() 
     417                self.FitInside() 
    156418                break 
    157419 
     
    186448            wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 
    187449 
     450    def _onHelp(self, event): 
     451        """ 
     452        Bring up the simultaneous Fitting Documentation whenever the HELP 
     453        button is clicked. 
     454 
     455        Calls DocumentationWindow with the path of the location within the 
     456        documentation tree (after /doc/ ....".  Note that when using old 
     457        versions of Wx (before 2.9) and thus not the release version of 
     458        installers, the help comes up at the top level of the file as 
     459        webbrowser does not pass anything past the # to the browser when it is 
     460        running "file:///...." 
     461 
     462    :param evt: Triggers on clicking the help button 
     463    """ 
     464        _TreeLocation = "user/perspectives/fitting/fitting_help.html" 
     465        _PageAnchor = "#simultaneous-fit-mode" 
     466        _doc_viewer = DocumentationWindow(self, self.ID_DOC, _TreeLocation, 
     467                                          _PageAnchor, 
     468                                          "Simultaneous/Constrained Fitting Help") 
     469 
    188470    def set_manager(self, manager): 
    189471        """ 
     
    223505 
    224506        self._update_easy_setup_cb() 
    225         self.Layout() 
    226         self.Refresh() 
     507        self.FitInside() 
     508 
    227509 
    228510    def check_model_name(self, event): 
     
    256538        if len(self.model_list) == len(self.model_toFit): 
    257539            self.cb1.SetValue(True) 
    258             self.Layout() 
     540            self.FitInside() 
    259541            return 
    260542        else: 
    261543            self.cb1.SetValue(False) 
    262             self.Layout() 
     544            self.FitInside() 
    263545 
    264546    def _update_easy_setup_cb(self): 
     
    277559            self.model_cbox_left.SetSelection(0) 
    278560        self.sizer2.Layout() 
    279         self.sizer3.Layout() 
    280  
    281     def draw_page(self): 
    282         """ 
    283         Draw a sizer containing couples of data and model 
    284         """ 
    285         self.model_list = [] 
    286         self.model_toFit = [] 
    287         self.constraints_list = [] 
    288         self.constraint_dict = {} 
    289         self.nb_constraint = 0 
    290         self.model_cbox_left = None 
    291         self.model_cbox_right = None 
    292  
    293         if len(self.model_list) > 0: 
    294             for item in self.model_list: 
    295                 item[0].SetValue(False) 
    296                 self.manager.schedule_for_fit(value=0, uid=item[2]) 
    297  
    298         self.sizer1.Clear(True) 
    299         box_description = wx.StaticBox(self, wx.ID_ANY, "Fit Combinations") 
    300         boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 
    301         sizer_title = wx.BoxSizer(wx.HORIZONTAL) 
    302         sizer_couples = wx.GridBagSizer(5, 5) 
    303         #------------------------------------------------------ 
    304         if len(self.page_finder) == 0: 
    305             msg = " No fit combinations are found! \n\n" 
    306             msg += " Please load data and set up " 
    307             msg += "at least two fit panels first..." 
    308             sizer_title.Add(wx.StaticText(self, wx.ID_ANY, msg)) 
    309         else: 
    310             ## store model 
    311             self._store_model() 
    312  
    313             self.cb1 = wx.CheckBox(self, wx.ID_ANY, 'Select all') 
    314             self.cb1.SetValue(False) 
    315  
    316             wx.EVT_CHECKBOX(self, self.cb1.GetId(), self.check_all_model_name) 
    317  
    318             sizer_title.Add((10, 10), 0, 
    319                 wx.TOP | wx.BOTTOM | wx.EXPAND | wx.ADJUST_MINSIZE, border=5) 
    320             sizer_title.Add(self.cb1, 0, 
    321                 wx.TOP | wx.BOTTOM | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, border=5) 
    322  
    323             ## draw list of model and data name 
    324             self._fill_sizer_model_list(sizer_couples) 
    325             ## draw the sizer containing constraint info 
    326             if not self.batch_on: 
    327                 self._fill_sizer_constraint() 
    328             ## draw fit button 
    329             self._fill_sizer_fit() 
    330         #-------------------------------------------------------- 
    331         boxsizer1.Add(sizer_title, flag=wx.TOP | wx.BOTTOM, border=5) 
    332         boxsizer1.Add(sizer_couples, 1, flag=wx.TOP | wx.BOTTOM, border=5) 
    333  
    334         self.sizer1.Add(boxsizer1, 1, wx.EXPAND | wx.ALL, 10) 
    335         self.sizer1.Layout() 
    336         #self.SetScrollbars(20,20,25,65) 
    337         self.AdjustScrollbars() 
    338         self.Layout() 
    339561 
    340562    def _store_model(self): 
     
    362584            self._show_all_constraint() 
    363585            self._show_constraint() 
    364             self.Layout() 
     586            self.FitInside() 
    365587            return 
    366588        else: 
    367589            self._hide_constraint() 
    368             self.Layout() 
    369590            return 
    370591 
     
    415636                             item=sizer_constraint, 
    416637                             flag=wx.TOP | wx.BOTTOM | wx.EXPAND, border=5) 
    417  
    418         self.sizer_all_constraints.Layout() 
    419         self.sizer2.Layout() 
    420         #self.SetScrollbars(20,20,25,65) 
     638        self.FitInside() 
    421639 
    422640    def _on_select_modelcb(self, event): 
     
    475693                self._show_constraint() 
    476694 
    477         self.sizer_constraints.Layout() 
    478         self.sizer2.Layout() 
    479         self.SetScrollbars(20, 20, 25, 65) 
    480         self.Layout() 
     695        self.FitInside() 
    481696        if not has_param: 
    482697            msg = " There is no adjustable parameter (checked to fit)" 
     
    564779        self.sizer_constraints.Layout() 
    565780        self.sizer2.Layout() 
     781        self.Layout 
    566782 
    567783    def _hide_constraint(self): 
     
    589805        self.sizer_constraints.Layout() 
    590806        self.sizer2.Layout() 
     807        self.Layout 
     808        self.FitInside() 
    591809 
    592810    def _on_select_model(self, event): 
     
    620838        btRemove.Show(True) 
    621839        self.btAdd.Show(True) 
    622         self.sizer2.Layout() 
     840#        self.Layout() 
     841        self.FitInside() 
    623842 
    624843    def _on_select_param(self, event): 
     
    666885        ## some model or parameters can be constrained 
    667886        self._show_constraint() 
    668         self.sizer3.Layout() 
    669         self.Layout() 
    670         self.Refresh() 
    671  
    672     def _fill_sizer_fit(self): 
    673         """ 
    674         Draw fit button 
    675         """ 
    676         self.sizer3.Clear(True) 
    677         box_description = wx.StaticBox(self, wx.ID_ANY, "Fit ") 
    678         boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 
    679         sizer_button = wx.BoxSizer(wx.HORIZONTAL) 
    680  
    681         self.btFit = wx.Button(self, self.ID_FIT, 'Fit', size=wx.DefaultSize) 
    682         self.btFit.Bind(wx.EVT_BUTTON, self.onFit, id=self.btFit.GetId()) 
    683         self.btFit.SetToolTipString("Perform fit.") 
    684         if self.batch_on: 
    685             text = " Fit in Parallel all Data set and model selected.\n" 
    686         else: 
    687             text = " This page requires at least one FitPage with a data\n" 
    688             text = " and a model for fitting." 
    689         text_hint = wx.StaticText(self, wx.ID_ANY, text) 
    690  
    691         sizer_button.Add(text_hint, wx.RIGHT | wx.EXPAND, 10) 
    692         sizer_button.Add(self.btFit, 0, wx.LEFT | wx.ADJUST_MINSIZE, 10) 
    693  
    694         boxsizer1.Add(sizer_button, flag=wx.TOP | wx.BOTTOM, border=10) 
    695         self.sizer3.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10) 
    696         self.sizer3.Layout() 
    697  
    698     def _fill_sizer_constraint(self): 
    699         """ 
    700         Fill sizer containing constraint info 
    701         """ 
    702         msg = "Select at least 2 model to add constraint " 
    703         wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 
    704  
    705         self.sizer2.Clear(True) 
    706         if self.batch_on: 
    707             if self.sizer2.IsShown(): 
    708                 self.sizer2.Show(False) 
    709             return 
    710         box_description = wx.StaticBox(self, wx.ID_ANY, "Fit Constraints") 
    711         boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 
    712         sizer_title = wx.BoxSizer(wx.HORIZONTAL) 
    713         self.sizer_all_constraints = wx.BoxSizer(wx.HORIZONTAL) 
    714         self.sizer_constraints = wx.BoxSizer(wx.VERTICAL) 
    715         sizer_button = wx.BoxSizer(wx.HORIZONTAL) 
    716  
    717         self.hide_constraint = wx.RadioButton(self, wx.ID_ANY, 'No', (10, 10), 
    718                                               style=wx.RB_GROUP) 
    719         self.show_constraint = wx.RadioButton(self, wx.ID_ANY, 'Yes', (10, 30)) 
    720         self.Bind(wx.EVT_RADIOBUTTON, self._display_constraint, 
    721                   id=self.hide_constraint.GetId()) 
    722         self.Bind(wx.EVT_RADIOBUTTON, self._display_constraint, 
    723                   id=self.show_constraint.GetId()) 
    724         if self.batch_on: 
    725             self.hide_constraint.Enable(False) 
    726             self.show_constraint.Enable(False) 
    727         self.hide_constraint.SetValue(True) 
    728         self.show_constraint.SetValue(False) 
    729  
    730         sizer_title.Add(wx.StaticText(self, wx.ID_ANY, " Model")) 
    731         sizer_title.Add((10, 10)) 
    732         sizer_title.Add(wx.StaticText(self, wx.ID_ANY, " Parameter")) 
    733         sizer_title.Add((10, 10)) 
    734         sizer_title.Add(wx.StaticText(self, wx.ID_ANY, " Add Constraint?")) 
    735         sizer_title.Add((10, 10)) 
    736         sizer_title.Add(self.show_constraint) 
    737         sizer_title.Add(self.hide_constraint) 
    738         sizer_title.Add((10, 10)) 
    739  
    740         self.btAdd = wx.Button(self, self.ID_ADD, 'Add') 
    741         self.btAdd.Bind(wx.EVT_BUTTON, self._onAdd_constraint, 
    742                         id=self.btAdd.GetId()) 
    743         self.btAdd.SetToolTipString("Add another constraint?") 
    744         self.btAdd.Hide() 
    745  
    746         text_hint = wx.StaticText(self, wx.ID_ANY, 
    747                                   "Example: [M0][paramter] = M1.parameter") 
    748         sizer_button.Add(text_hint, 0, 
    749                          wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 10) 
    750         sizer_button.Add(self.btAdd, 0, 
    751                          wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 10) 
    752  
    753         boxsizer1.Add(sizer_title, flag=wx.TOP | wx.BOTTOM, border=10) 
    754         boxsizer1.Add(self.sizer_all_constraints, flag=wx.TOP | wx.BOTTOM, 
    755                       border=10) 
    756         boxsizer1.Add(self.sizer_constraints, flag=wx.TOP | wx.BOTTOM, 
    757                       border=10) 
    758         boxsizer1.Add(sizer_button, flag=wx.TOP | wx.BOTTOM, border=10) 
    759  
    760         self.sizer2.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10) 
    761         self.sizer2.Layout() 
    762  
    763         #self.SetScrollbars(20,20,25,65) 
     887        self.FitInside() 
    764888 
    765889    def _set_constraint(self): 
    766890        """ 
    767         get values from the constrainst textcrtl ,parses them into model name 
     891        get values from the constraint textcrtl ,parses them into model name 
    768892        parameter name and parameters values. 
    769893        store them in a list self.params .when when params is not empty 
     
    817941        return True 
    818942 
    819     def _fill_sizer_model_list(self, sizer): 
    820         """ 
    821         Receive a dictionary containing information to display model name 
    822         """ 
    823         ix = 0 
    824         iy = 0 
    825         list = [] 
    826         sizer.Clear(True) 
    827  
    828         new_name = wx.StaticText(self, wx.ID_ANY, '  Model Title ', 
    829                                  style=wx.ALIGN_CENTER) 
    830         new_name.SetBackgroundColour('orange') 
    831         new_name.SetForegroundColour(wx.WHITE) 
    832         sizer.Add(new_name, (iy, ix), (1, 1), 
    833                             wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    834         ix += 2 
    835         model_type = wx.StaticText(self, wx.ID_ANY, '  Model ') 
    836         model_type.SetBackgroundColour('grey') 
    837         model_type.SetForegroundColour(wx.WHITE) 
    838         sizer.Add(model_type, (iy, ix), (1, 1), 
    839                             wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    840         ix += 1 
    841         data_used = wx.StaticText(self, wx.ID_ANY, '  Data ') 
    842         data_used.SetBackgroundColour('grey') 
    843         data_used.SetForegroundColour(wx.WHITE) 
    844         sizer.Add(data_used, (iy, ix), (1, 1), 
    845                             wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    846         ix += 1 
    847         tab_used = wx.StaticText(self, wx.ID_ANY, '  FitPage ') 
    848         tab_used.SetBackgroundColour('grey') 
    849         tab_used.SetForegroundColour(wx.WHITE) 
    850         sizer.Add(tab_used, (iy, ix), (1, 1), 
    851                   wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    852         for id, value in self.page_finder.iteritems(): 
    853             if id not in self.parent.opened_pages: 
    854                 continue 
    855  
    856             if self.batch_on != self.parent.get_page_by_id(id).batch_on: 
    857                 continue 
    858  
    859             data_list = [] 
    860             model_list = [] 
    861             # get data name and model objetta 
    862             for fitproblem in value.get_fit_problem(): 
    863  
    864                 data = fitproblem.get_fit_data() 
    865                 if not data.is_data: 
    866                     continue 
    867                 name = '-' 
    868                 if data is not None and data.is_data: 
    869                     name = str(data.name) 
    870                 data_list.append(name) 
    871  
    872                 model = fitproblem.get_model() 
    873                 if model is None: 
    874                     continue 
    875                 model_list.append(model) 
    876  
    877             if len(model_list) == 0: 
    878                 continue 
    879             # Draw sizer 
    880             ix = 0 
    881             iy += 1 
    882             model = model_list[0] 
    883             name = '_' 
    884             if model is not None: 
    885                 name = str(model.name) 
    886             cb = wx.CheckBox(self, wx.ID_ANY, name) 
    887             cb.SetValue(False) 
    888             cb.Enable(model is not None and data.is_data) 
    889             sizer.Add(cb, (iy, ix), (1, 1), 
    890                       wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    891             wx.EVT_CHECKBOX(self, cb.GetId(), self.check_model_name) 
    892             ix += 2 
    893             model_type = wx.StaticText(self, wx.ID_ANY, 
    894                                        model.__class__.__name__) 
    895             sizer.Add(model_type, (iy, ix), (1, 1), 
    896                       wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    897             if self.batch_on: 
    898                 data_used = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY) 
    899                 data_used.AppendItems(data_list) 
    900                 data_used.SetSelection(0) 
    901             else: 
    902                 data_used = wx.StaticText(self, wx.ID_ANY, data_list[0]) 
    903  
    904             ix += 1 
    905             sizer.Add(data_used, (iy, ix), (1, 1), 
    906                       wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    907             ix += 1 
    908             caption = value.get_fit_tab_caption() 
    909             tab_caption_used = wx.StaticText(self, wx.ID_ANY, str(caption)) 
    910             sizer.Add(tab_caption_used, (iy, ix), (1, 1), 
    911                       wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    912  
    913             self.model_list.append([cb, value, id, model]) 
    914  
    915         iy += 1 
    916         sizer.Add((20, 20), (iy, ix), (1, 1), 
    917                   wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    918         sizer.Layout() 
    919  
    920943    def on_set_focus(self, event=None): 
    921944        """ 
Note: See TracChangeset for help on using the changeset viewer.