Ignore:
Timestamp:
Oct 21, 2015 6:35:00 AM (9 years ago)
Author:
Paul Kienzle <pkienzle@…>
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:
85130cb
Parents:
2d88fc4
Message:

clean up wx id handling in fitting perspective

File:
1 edited

Legend:

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

    r2c8dc19 r6f16e25  
    1515from wx.lib.scrolledpanel import ScrolledPanel 
    1616from sas.guiframe.panel_base import PanelBase 
    17 from sas.guiframe.utils import format_number, check_float 
     17from sas.guiframe.utils import format_number, check_float, IdList 
    1818from sas.guiframe.events import PanelOnFocusEvent 
    1919from sas.guiframe.events import StatusEvent 
     
    5757    ## Title to appear on top of the window 
    5858    window_caption = "Fit Page " 
     59    # These two buttons have specific IDs since they seem to be created more 
     60    # frequently than they need to.  In particular, set_dispers_sizer() is 
     61    # called by _on_select_model 
     62    ID_BOOKMARK = wx.NewId() 
     63    ID_DISPERSER_HELP = wx.NewId() 
     64    _id_pool = IdList() 
    5965 
    6066    def __init__(self, parent, color='blue', **kwargs): 
     
    6672        #Set window's font size 
    6773        self.SetWindowVariant(variant=FONT_VARIANT) 
    68  
    6974        self.SetBackgroundColour(color) 
     75 
     76        self._ids = iter(self._id_pool) 
    7077        ## parent of the page 
    7178        self.parent = parent 
     
    199206        self.popUpMenu = wx.Menu() 
    200207 
    201         id = wx.NewId() 
    202         self._keep = wx.MenuItem(self.popUpMenu, id, "Add bookmark", 
     208        wx_id = self._ids.next() 
     209        self._keep = wx.MenuItem(self.popUpMenu, wx_id, "Add bookmark", 
    203210                                 " Keep the panel status to recall it later") 
    204211        self.popUpMenu.AppendItem(self._keep) 
     
    206213        self._set_bookmark_flag(False) 
    207214        self._set_save_flag(False) 
    208         wx.EVT_MENU(self, id, self.on_bookmark) 
     215        wx.EVT_MENU(self, wx_id, self.on_bookmark) 
    209216        self.popUpMenu.AppendSeparator() 
    210217 
     
    594601        fill sizer containing dispersity info 
    595602        """ 
     603        #print "==== entering set_dispers_sizer ===" 
    596604        self.sizer4.Clear(True) 
    597605        name = "Polydispersity and Orientational Distribution" 
    598         box_description = wx.StaticBox(self, -1, name) 
     606        box_description = wx.StaticBox(self, wx.ID_ANY, name) 
    599607        box_description.SetForegroundColour(wx.BLUE) 
    600608        boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 
    601609        #---------------------------------------------------- 
    602         self.disable_disp = wx.RadioButton(self, -1, 'Off', (10, 10), 
     610        self.disable_disp = wx.RadioButton(self, wx.ID_ANY, 'Off', (10, 10), 
    603611                                           style=wx.RB_GROUP) 
    604         self.enable_disp = wx.RadioButton(self, -1, 'On', (10, 30)) 
     612        self.enable_disp = wx.RadioButton(self, wx.ID_ANY, 'On', (10, 30)) 
    605613        # best size for MAC and PC 
    606614        if ON_MAC: 
     
    608616        else: 
    609617            size_q = (20, 15) 
    610         self.disp_help_bt = wx.Button(self, wx.NewId(), '?', 
     618        self.disp_help_bt = wx.Button(self, self.ID_DISPERSER_HELP, '?', 
    611619                                      style=wx.BU_EXACTFIT, 
    612620                                      size=size_q) 
     
    624632        sizer_dispersion.Add((20, 20)) 
    625633        name = ""  # Polydispersity and \nOrientational Distribution " 
    626         sizer_dispersion.Add(wx.StaticText(self, -1, name)) 
     634        sizer_dispersion.Add(wx.StaticText(self, wx.ID_ANY, name)) 
    627635        sizer_dispersion.Add(self.enable_disp) 
    628636        sizer_dispersion.Add((20, 20)) 
     
    795803        wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 
    796804 
    797         id = wx.NewId() 
    798         self.popUpMenu.Append(id, name, str(msg)) 
    799         wx.EVT_MENU(self, id, self.onResetModel) 
     805        self.popUpMenu.Append(self.ID_BOOKMARK, name, str(msg)) 
     806        wx.EVT_MENU(self, self.ID_BOOKMARK, self.onResetModel) 
    800807        wx.PostEvent(self._manager.parent, 
    801808                     AppendBookmarkEvent(title=name, 
     
    14381445        reset the context menu 
    14391446        """ 
     1447        ids = iter(self._id_pool)  # Reusing ids for context menu 
    14401448        for name, _ in self.state.saved_states.iteritems(): 
    14411449            self.number_saved_state += 1 
    14421450            ## Add item in the context menu 
    1443             id = wx.NewId() 
     1451            wx_id = ids.next() 
    14441452            msg = 'Save model and state %g' % self.number_saved_state 
    1445             self.popUpMenu.Append(id, name, msg) 
    1446             wx.EVT_MENU(self, id, self.onResetModel) 
     1453            self.popUpMenu.Append(wx_id, name, msg) 
     1454            wx.EVT_MENU(self, wx_id, self.onResetModel) 
    14471455 
    14481456    def _reset_plotting_range(self, state): 
     
    18311839        sld_data.name = 'SLD' 
    18321840        sld_data.axes = self.sld_axes 
    1833         self.panel = SLDPanel(self, data=sld_data, axes=self.sld_axes, id= -1) 
     1841        self.panel = SLDPanel(self, data=sld_data, axes=self.sld_axes, 
     1842                              id=wx.ID_ANY) 
    18341843        self.panel.ShowModal() 
    18351844 
     
    24212430        self.sizer4_4.Clear(True) 
    24222431        text = "No polydispersity available for this model" 
    2423         model_disp = wx.StaticText(self, -1, text) 
     2432        model_disp = wx.StaticText(self, wx.ID_ANY, text) 
    24242433        self.sizer4_4.Add(model_disp, (iy, ix), (1, 1), 
    24252434                          wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 10) 
     
    28512860            name = self.formfactorbox.GetValue() 
    28522861            _PageAnchor = '#' + name.lower() 
    2853             _doc_viewer = DocumentationWindow(self, -1, _TreeLocation, 
     2862            _doc_viewer = DocumentationWindow(self, wx.ID_ANY, _TreeLocation, 
    28542863                                              _PageAnchor, name + " Help") 
    28552864        else: 
    2856             _doc_viewer = DocumentationWindow(self, -1, _TreeLocation, "", 
    2857                                                 "General Model Help") 
     2865            _doc_viewer = DocumentationWindow(self, wx.ID_ANY, _TreeLocation, 
     2866                                              "", "General Model Help") 
    28582867 
    28592868 
     
    29062915 
    29072916        _TreeLocation = "_images/M_angles_pic.bmp" 
    2908         _doc_viewer = DocumentationWindow(self, -1, _TreeLocation, "", 
     2917        _doc_viewer = DocumentationWindow(self, wx.ID_ANY, _TreeLocation, "", 
    29092918                                          "Magnetic Angle Defintions") 
    29102919 
     
    29262935 
    29272936        _TreeLocation = "user/perspectives/fitting/mag_help.html" 
    2928         _doc_viewer = DocumentationWindow(self, -1, _TreeLocation, "", 
     2937        _doc_viewer = DocumentationWindow(self, wx.ID_ANY, _TreeLocation, "", 
    29292938                                          "Polarized Beam/Magnetc Help") 
    29302939 
     
    29732982        _TreeLocation = "user/perspectives/fitting/pd_help.html" 
    29742983        _PageAnchor = "" 
    2975         _doc_viewer = DocumentationWindow(self, -1, _TreeLocation, 
     2984        _doc_viewer = DocumentationWindow(self, wx.ID_ANY, _TreeLocation, 
    29762985                                          _PageAnchor, "Polydispersity Help") 
    29772986 
     
    35173526        fill sizer containing model info 
    35183527        """ 
     3528        # This should only be called once per fit tab 
     3529        #print "==== Entering _fill_model_sizer" 
    35193530        ##Add model function Details button in fitpanel. 
    35203531        ##The following 3 lines are for Mac. Let JHC know before modifying... 
     
    35223533        self.formfactorbox = None 
    35233534        self.multifactorbox = None 
    3524         self.mbox_description = wx.StaticBox(self, -1, str(title)) 
     3535        self.mbox_description = wx.StaticBox(self, wx.ID_ANY, str(title)) 
    35253536        boxsizer1 = wx.StaticBoxSizer(self.mbox_description, wx.VERTICAL) 
    35263537        sizer_cat = wx.BoxSizer(wx.HORIZONTAL) 
    35273538        self.mbox_description.SetForegroundColour(wx.RED) 
    3528         id = wx.NewId() 
    3529         self.model_func = wx.Button(self, id, 'Help', size=(80, 23)) 
    3530         self.model_func.Bind(wx.EVT_BUTTON, self.on_function_help_clicked, id=id) 
     3539        wx_id = self._ids.next() 
     3540        self.model_func = wx.Button(self, wx_id, 'Help', size=(80, 23)) 
     3541        self.model_func.Bind(wx.EVT_BUTTON, self.on_function_help_clicked, 
     3542                             id=wx_id) 
    35313543        self.model_func.SetToolTipString("Full Model Function Help") 
    3532         id = wx.NewId() 
    3533         self.model_help = wx.Button(self, id, 'Description', size=(80, 23)) 
    3534         self.model_help.Bind(wx.EVT_BUTTON, self.on_model_help_clicked, id=id) 
     3544        wx_id = self._ids.next() 
     3545        self.model_help = wx.Button(self, wx_id, 'Description', size=(80, 23)) 
     3546        self.model_help.Bind(wx.EVT_BUTTON, self.on_model_help_clicked, 
     3547                             id=wx_id) 
    35353548        self.model_help.SetToolTipString("Short Model Function Description") 
    3536         id = wx.NewId() 
    3537         self.model_view = wx.Button(self, id, "Show 2D", size=(80, 23)) 
    3538         self.model_view.Bind(wx.EVT_BUTTON, self._onModel2D, id=id) 
     3549        wx_id = self._ids.next() 
     3550        self.model_view = wx.Button(self, wx_id, "Show 2D", size=(80, 23)) 
     3551        self.model_view.Bind(wx.EVT_BUTTON, self._onModel2D, id=wx_id) 
    35393552        hint = "toggle view of model from 1D to 2D  or 2D to 1D" 
    35403553        self.model_view.SetToolTipString(hint) 
    35413554 
    3542         cat_set_box = wx.StaticBox(self, -1, 'Category') 
     3555        cat_set_box = wx.StaticBox(self, wx.ID_ANY, 'Category') 
    35433556        sizer_cat_box = wx.StaticBoxSizer(cat_set_box, wx.HORIZONTAL) 
    35443557        sizer_cat_box.SetMinSize((200, 50)) 
    3545         self.categorybox = wx.ComboBox(self, -1, style=wx.CB_READONLY) 
     3558        self.categorybox = wx.ComboBox(self, wx.ID_ANY, 
     3559                                       style=wx.CB_READONLY) 
    35463560        self.categorybox.SetToolTip(wx.ToolTip("Select a Category/Type")) 
    35473561        self._populate_listbox() 
    3548         wx.EVT_COMBOBOX(self.categorybox, -1, self._show_combox) 
    3549         #self.shape_rbutton = wx.RadioButton(self, -1, 'Shapes', 
     3562        wx.EVT_COMBOBOX(self.categorybox, wx.ID_ANY, self._show_combox) 
     3563        #self.shape_rbutton = wx.RadioButton(self, wx.ID_ANY, 'Shapes', 
    35503564        #                                     style=wx.RB_GROUP) 
    3551         #self.shape_indep_rbutton = wx.RadioButton(self, -1, 
     3565        #self.shape_indep_rbutton = wx.RadioButton(self, wx.ID_ANY, 
    35523566        #                                          "Shape-Independent") 
    3553         #self.struct_rbutton = wx.RadioButton(self, -1, "Structure Factor ") 
    3554         #self.plugin_rbutton = wx.RadioButton(self, -1, "Uncategorized") 
     3567        #self.struct_rbutton = wx.RadioButton(self, wx.ID_ANY, 
     3568        #                                     "Structure Factor ") 
     3569        #self.plugin_rbutton = wx.RadioButton(self, wx.ID_ANY, 
     3570        #                                     "Uncategorized") 
    35553571 
    35563572        #self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, 
     
    35643580        #MAC needs SetValue 
    35653581 
    3566         show_cat_button = wx.Button(self, -1, "Modify") 
     3582        show_cat_button = wx.Button(self, wx.ID_ANY, "Modify") 
    35673583        cat_tip = "Modify model categories \n" 
    35683584        cat_tip += "(also accessible from the menu bar)." 
     
    35903606        mutifactor_selection = wx.BoxSizer(wx.HORIZONTAL) 
    35913607 
    3592         self.text1 = wx.StaticText(self, -1, "") 
    3593         self.text2 = wx.StaticText(self, -1, "P(Q)*S(Q)") 
    3594         self.mutifactor_text = wx.StaticText(self, -1, "No. of Shells: ") 
    3595         self.mutifactor_text1 = wx.StaticText(self, -1, "") 
    3596         self.show_sld_button = wx.Button(self, -1, "Show SLD Profile") 
     3608        self.text1 = wx.StaticText(self, wx.ID_ANY, "") 
     3609        self.text2 = wx.StaticText(self, wx.ID_ANY, "P(Q)*S(Q)") 
     3610        self.mutifactor_text = wx.StaticText(self, wx.ID_ANY, "No. of Shells: ") 
     3611        self.mutifactor_text1 = wx.StaticText(self, wx.ID_ANY, "") 
     3612        self.show_sld_button = wx.Button(self, wx.ID_ANY, "Show SLD Profile") 
    35973613        self.show_sld_button.Bind(wx.EVT_BUTTON, self._on_show_sld) 
    35983614 
    3599         self.formfactorbox = wx.ComboBox(self, -1, style=wx.CB_READONLY) 
     3615        self.formfactorbox = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY) 
    36003616        self.formfactorbox.SetToolTip(wx.ToolTip("Select a Model")) 
    36013617        if self.model != None: 
    36023618            self.formfactorbox.SetValue(self.model.name) 
    3603         self.structurebox = wx.ComboBox(self, -1, style=wx.CB_READONLY) 
    3604         self.multifactorbox = wx.ComboBox(self, -1, style=wx.CB_READONLY) 
     3619        self.structurebox = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY) 
     3620        self.multifactorbox = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY) 
    36053621        self.initialize_combox() 
    3606         wx.EVT_COMBOBOX(self.formfactorbox, -1, self._on_select_model) 
    3607  
    3608         wx.EVT_COMBOBOX(self.structurebox, -1, self._on_select_model) 
    3609         wx.EVT_COMBOBOX(self.multifactorbox, -1, self._on_select_model) 
     3622        wx.EVT_COMBOBOX(self.formfactorbox, wx.ID_ANY, self._on_select_model) 
     3623 
     3624        wx.EVT_COMBOBOX(self.structurebox, wx.ID_ANY, self._on_select_model) 
     3625        wx.EVT_COMBOBOX(self.multifactorbox, wx.ID_ANY, self._on_select_model) 
    36103626        ## check model type to show sizer 
    36113627        if self.model != None: 
Note: See TracChangeset for help on using the changeset viewer.