Changeset 1512


Ignore:
Timestamp:
Oct 1, 2014 10:35:23 PM (8 years ago)
Author:
toby
Message:

implement logging and config storage

Location:
trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASII.py

    r1508 r1512  
    7777import GSASIIobj as G2obj
    7878import GSASIIlattice as G2lat
     79import GSASIIlog as log
    7980
    8081#wx inspector - use as needed
     
    116117    '''Define the main GSAS-II frame and its associated menu items
    117118    '''
     119    def MenuBinding(self,event):
     120        '''Called when a menu is clicked upon; looks up the binding in table
     121        '''
     122        log.InvokeMenuCommand(event.GetId(),self,event)
     123           
     124    def Bind(self,eventtype,handler,*args,**kwargs):
     125        '''Override the Bind function so that we can wrap calls that will be logged.
     126       
     127        N.B. This is a bit kludgy. Menu bindings with an id are wrapped and
     128        menu bindings with an object and no id are not.
     129        '''
     130        if eventtype == wx.EVT_MENU and 'id' in kwargs:
     131            menulabels = log.SaveMenuCommand(kwargs['id'],self,handler)
     132            if menulabels:
     133                wx.Frame.Bind(self,eventtype,self.MenuBinding,*args,**kwargs)
     134                return
     135        wx.Frame.Bind(self,eventtype,handler,*args,**kwargs)     
    118136   
    119137    def _Add_FileMenuItems(self, parent):
     
    16421660        return # success
    16431661
     1662    def OnMacroRecordStatus(self,event,setvalue=None):
     1663        '''Called when the record macro menu item is used which toggles the
     1664        value. Alternately a value to be set can be provided. Note that this
     1665        routine is made more complex because on the Mac there are lots of menu
     1666        items (listed in self.MacroStatusList) and this loops over all of them.
     1667        '''
     1668        nextvalue = log.ShowLogStatus() != True
     1669        if setvalue is not None:
     1670            nextvalue = setvalue
     1671        if nextvalue:
     1672            log.LogOn()
     1673            set2 = True
     1674        else:
     1675            log.LogOff()
     1676            set2 = False
     1677        for menuitem in self.MacroStatusList:
     1678            menuitem.Check(set2)
     1679
     1680    def _init_Macro(self):
     1681        '''Define the items in the macro menu.
     1682        '''
     1683        menu = self.MacroMenu
     1684        item = menu.Append(
     1685                help='Start or stop recording of menu actions, etc.', id=wx.ID_ANY,
     1686                kind=wx.ITEM_CHECK,text='Record actions')
     1687        self.MacroStatusList.append(item)
     1688        item.Check(log.ShowLogStatus())
     1689        self.Bind(wx.EVT_MENU, self.OnMacroRecordStatus, item)
     1690
     1691        # this may only be of value for development work
     1692        item = menu.Append(
     1693            help='Show logged commands', id=wx.ID_ANY,
     1694            kind=wx.ITEM_NORMAL,text='Show log')
     1695        def OnShowLog(event):
     1696            print 70*'='
     1697            print 'List of logged actions'
     1698            for i,line in enumerate(log.G2logList):
     1699                if line: print i,line
     1700            print 70*'='
     1701        self.Bind(wx.EVT_MENU, OnShowLog, item)
     1702
     1703        item = menu.Append(
     1704            help='Clear logged commands', id=wx.ID_ANY,
     1705            kind=wx.ITEM_NORMAL,text='Clear log')
     1706        def OnClearLog(event): log.G2logList=[None]
     1707        self.Bind(wx.EVT_MENU, OnClearLog, item)
     1708       
     1709        item = menu.Append(
     1710            help='Save logged commands to file', id=wx.ID_ANY,
     1711            kind=wx.ITEM_NORMAL,text='Save log')
     1712        def OnSaveLog(event):
     1713            import cPickle
     1714            defnam = os.path.splitext(
     1715                os.path.split(self.GSASprojectfile)[1]
     1716                )[0]+'.gcmd'
     1717            dlg = wx.FileDialog(self,
     1718                'Choose an file to save past actions', '.', defnam,
     1719                'GSAS-II cmd output (*.gcmd)|*.gcmd',
     1720                wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT|wx.CHANGE_DIR)
     1721            dlg.CenterOnParent()
     1722            try:
     1723                if dlg.ShowModal() == wx.ID_OK:
     1724                    filename = dlg.GetPath()
     1725                    # make sure extension is correct
     1726                    filename = os.path.splitext(filename)[0]+'.gcmd'
     1727                else:
     1728                    filename = None
     1729            finally:
     1730                dlg.Destroy()
     1731            if filename:
     1732                fp = open(filename,'wb')
     1733                fp.write(str(len(log.G2logList)-1)+'\n')
     1734                for item in log.G2logList:
     1735                    if item: cPickle.dump(item,fp)
     1736                fp.close()
     1737        self.Bind(wx.EVT_MENU, OnSaveLog, item)
     1738
     1739        item = menu.Append(
     1740            help='Load logged commands from file', id=wx.ID_ANY,
     1741            kind=wx.ITEM_NORMAL,text='Load log')
     1742        def OnLoadLog(event):
     1743            # this appends. Perhaps we should ask to clear?
     1744            import cPickle
     1745            defnam = os.path.splitext(
     1746                os.path.split(self.GSASprojectfile)[1]
     1747                )[0]+'.gcmd'
     1748            dlg = wx.FileDialog(self,
     1749                'Choose an file to read saved actions', '.', defnam,
     1750                'GSAS-II cmd output (*.gcmd)|*.gcmd',
     1751                wx.OPEN|wx.CHANGE_DIR)
     1752            dlg.CenterOnParent()
     1753            try:
     1754                if dlg.ShowModal() == wx.ID_OK:
     1755                    filename = dlg.GetPath()
     1756                    # make sure extension is correct
     1757                    filename = os.path.splitext(filename)[0]+'.gcmd'
     1758                else:
     1759                    filename = None
     1760            finally:
     1761                dlg.Destroy()
     1762            if filename and os.path.exists(filename):
     1763                fp = open(filename,'rb')
     1764                lines = fp.readline()
     1765                for i in range(int(lines)):
     1766                    log.G2logList.append(cPickle.load(fp))
     1767                fp.close()
     1768        self.Bind(wx.EVT_MENU, OnLoadLog, item)
     1769
     1770        item = menu.Append(
     1771            help='Replay saved commands', id=wx.ID_ANY,
     1772            kind=wx.ITEM_NORMAL,text='Replay log')
     1773        self.Bind(wx.EVT_MENU, log.ReplayLog, item)
     1774
    16441775    def _init_Exports(self,menu):
    16451776        '''Find exporter routines and add them into menus
     
    17921923
    17931924    def FillMainMenu(self,menubar):
    1794         '''Define contents of the main GSAS-II menu for the (main) data tree window
    1795         in the mac, used also for the data item windows as well.
     1925        '''Define contents of the main GSAS-II menu for the (main) data tree window.
     1926        For the mac, this is also called for the data item windows as well so that
     1927        the main menu items are data menu as well.
    17961928        '''
    17971929        File = wx.Menu(title='')
     
    18491981        self._init_Exports(self.ExportMenu)
    18501982        self._Add_ExportMenuItems(self.ExportMenu)
     1983        if GSASIIpath.GetConfigValue('Enable_logging'):
     1984            self.MacroMenu = wx.Menu(title='')
     1985            menubar.Append(menu=self.MacroMenu, title='Macro')
     1986            self._init_Macro()
    18511987        HelpMenu=G2gd.MyHelp(self,helpType='Data tree',
    18521988            morehelpitems=[('&Tutorials','Tutorials')])
     
    18732009        #
    18742010        self.GSASIIMenu = wx.MenuBar()
     2011        # create a list of all dataframe menus (appended in PrefillDataMenu)
     2012        self.dataMenuBars = [self.GSASIIMenu]
     2013        self.MacroStatusList = []
    18752014        self.FillMainMenu(self.GSASIIMenu)
    18762015        self.SetMenuBar(self.GSASIIMenu)
     
    18802019       
    18812020        wxID_PATTERNTREE = wx.NewId()
    1882         self.PatternTree = wx.TreeCtrl(id=wxID_PATTERNTREE,
     2021        #self.PatternTree = wx.TreeCtrl(id=wxID_PATTERNTREE, # replaced for logging
     2022        self.PatternTree = G2gd.G2TreeCtrl(id=wxID_PATTERNTREE,
    18832023            parent=self.mainPanel, pos=wx.Point(0, 0),style=wx.TR_DEFAULT_STYLE )
    1884         self.PatternTree.Bind(wx.EVT_TREE_SEL_CHANGED,
    1885             self.OnPatternTreeSelChanged, id=wxID_PATTERNTREE)
     2024        self.PatternTree.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnPatternTreeSelChanged)
    18862025        self.PatternTree.Bind(wx.EVT_TREE_ITEM_COLLAPSED,
    18872026            self.OnPatternTreeItemCollapsed, id=wxID_PATTERNTREE)
     
    18962035        self.PatternTree.Bind(wx.EVT_TREE_END_DRAG,
    18972036            self.OnPatternTreeEndDrag, id=wxID_PATTERNTREE)       
    1898         self.root = self.PatternTree.AddRoot('Loaded Data: ')
     2037        #self.root = self.PatternTree.AddRoot('Loaded Data: ')
     2038        self.root = self.PatternTree.root
    18992039        plotFrame = wx.Frame(None,-1,'GSASII Plots',size=wx.Size(700,600), \
    19002040            style=wx.DEFAULT_FRAME_STYLE ^ wx.CLOSE_BOX)
  • trunk/GSASIIconstrGUI.py

    r1417 r1512  
    18271827
    18281828    G2gd.SetDataMenuBar(G2frame,G2frame.dataFrame.RigidBodyMenu)
    1829     G2frame.dataFrame.Bind(wx.EVT_MENU, OnAddRigidBody, id=G2gd.wxID_RIGIDBODYADD)   
    1830     G2frame.dataFrame.Bind(wx.EVT_MENU, OnImportRigidBody, id=G2gd.wxID_RIGIDBODYIMPORT)
    1831     G2frame.dataFrame.Bind(wx.EVT_MENU, OnDefineTorsSeq, id=G2gd.wxID_RESIDUETORSSEQ)
     1829    G2frame.dataFrame.Bind(wx.EVT_MENU, OnAddRigidBody, id=G2gd.wxID_RIGIDBODYADD)
     1830    # no menu items yet   
     1831    #G2frame.dataFrame.Bind(wx.EVT_MENU, OnImportRigidBody, id=G2gd.wxID_RIGIDBODYIMPORT)
     1832    #G2frame.dataFrame.Bind(wx.EVT_MENU, OnDefineTorsSeq, id=G2gd.wxID_RESIDUETORSSEQ)
    18321833    G2frame.dataDisplay = G2gd.GSNoteBook(parent=G2frame.dataFrame,size=G2frame.dataFrame.GetClientSize())
    18331834
  • trunk/GSASIIgrid.py

    r1506 r1512  
    4545import GSASIIobj as G2obj
    4646import GSASIIexprGUI as G2exG
     47import GSASIIlog as log
    4748
    4849# trig functions in degrees
     
    153154] = [wx.NewId() for item in range(7)]
    154155
     156[ wxID_MCRON,wxID_MCRLIST,wxID_MCRSAVE,wxID_MCRPLAY,
     157] = [wx.NewId() for item in range(4)]
     158
    155159VERY_LIGHT_GREY = wx.Colour(235,235,235)
    156160################################################################################
    157161#### GSAS-II class definitions
    158162################################################################################
    159        
     163
     164class G2TreeCtrl(wx.TreeCtrl):
     165    '''Create a wrapper around the standard TreeCtrl so we can "wrap"
     166    various events.
     167   
     168    This logs when a tree item is selected (in :meth:`onSelectionChanged`)
     169
     170    This also wraps lists and dicts pulled out of the tree to track where
     171    they were retrieved from.
     172    '''
     173    def __init__(self,parent=None,*args,**kwargs):
     174        super(self.__class__,self).__init__(parent=parent,*args,**kwargs)
     175        self.G2frame = parent.GetParent()
     176        self.root = self.AddRoot('Loaded Data: ')
     177        self.SelectionChanged = None
     178        log.LogInfo['Tree'] = self
     179
     180    def _getTreeItemsList(self,item):
     181        '''Get the full tree hierarchy from a reference to a tree item.
     182        Note that this effectively hard-codes phase and histogram names in the
     183        returned list. We may want to make these names relative in the future.
     184        '''
     185        textlist = [self.GetItemText(item)]
     186        parent = self.GetItemParent(item)
     187        while parent:
     188            if parent == self.root: break
     189            textlist.insert(0,self.GetItemText(parent))
     190            parent = self.GetItemParent(parent)
     191        return textlist
     192
     193    def onSelectionChanged(self,event):
     194        '''Log each press on a tree item here.
     195        '''
     196        if self.SelectionChanged:
     197            textlist = self._getTreeItemsList(event.GetItem())
     198            if log.LogInfo['Logging'] and event.GetItem() != self.root:
     199                textlist[0] = self.GetRelativeHistNum(textlist[0])
     200                if textlist[0] == "Phases" and len(textlist) > 1:
     201                    textlist[1] = self.GetRelativePhaseNum(textlist[1])
     202                log.MakeTreeLog(textlist)
     203            self.SelectionChanged(event)
     204
     205    def Bind(self,eventtype,handler,*args,**kwargs):
     206        '''Override the Bind() function so that page change events can be trapped
     207        '''
     208        if eventtype == wx.EVT_TREE_SEL_CHANGED:
     209            self.SelectionChanged = handler
     210            wx.TreeCtrl.Bind(self,eventtype,self.onSelectionChanged)
     211            return
     212        wx.TreeCtrl.Bind(self,eventtype,handler,*args,**kwargs)
     213
     214    def GetItemPyData(self,*args,**kwargs):
     215        '''Override the standard method to wrap the contents
     216        so that the source can be tracked
     217        '''
     218        data = super(self.__class__,self).GetItemPyData(*args,**kwargs)
     219        textlist = self._getTreeItemsList(args[0])
     220        if type(data) is dict:
     221            return log.dictLogged(data,textlist)
     222        if type(data) is list:
     223            return log.listLogged(data,textlist)
     224        if type(data) is tuple: #N.B. tuples get converted to lists
     225            return log.listLogged(list(data),textlist)
     226        return data
     227
     228    def GetRelativeHistNum(self,histname):
     229        '''Returns list with a histogram type and a relative number for that
     230        histogram, or the original string if not a histogram
     231        '''
     232        histtype = histname.split()[0]
     233        if histtype != histtype.upper(): # histograms (only) have a keyword all in caps
     234            return histname
     235        item, cookie = self.GetFirstChild(self.root)
     236        i = 0
     237        while item:
     238            itemtext = self.GetItemText(item)
     239            if itemtext == histname:
     240                return histtype,i
     241            elif itemtext.split()[0] == histtype:
     242                i += 1
     243            item, cookie = self.GetNextChild(self.root, cookie)
     244        else:
     245            raise Exception("Histogram not found: "+histname)
     246
     247    def ConvertRelativeHistNum(self,histtype,histnum):
     248        '''Converts a histogram type and relative histogram number to a
     249        histogram name in the current project
     250        '''
     251        item, cookie = self.GetFirstChild(self.root)
     252        i = 0
     253        while item:
     254            itemtext = self.GetItemText(item)
     255            if itemtext.split()[0] == histtype:
     256                if i == histnum: return itemtext
     257                i += 1
     258            item, cookie = self.GetNextChild(self.root, cookie)
     259        else:
     260            raise Exception("Histogram #'+str(histnum)+' of type "+histtype+' not found')
     261       
     262    def GetRelativePhaseNum(self,phasename):
     263        '''Returns a phase number if the string matches a phase name
     264        or else returns the original string
     265        '''
     266        item, cookie = self.GetFirstChild(self.root)
     267        while item:
     268            itemtext = self.GetItemText(item)
     269            if itemtext == "Phases":
     270                parent = item
     271                item, cookie = self.GetFirstChild(parent)
     272                i = 0
     273                while item:
     274                    itemtext = self.GetItemText(item)
     275                    if itemtext == phasename:
     276                        return i
     277                    item, cookie = self.GetNextChild(parent, cookie)
     278                    i += 1
     279                else:
     280                    return phasename # not a phase name
     281            item, cookie = self.GetNextChild(self.root, cookie)
     282        else:
     283            raise Exception("No phases found ")
     284
     285    def ConvertRelativePhaseNum(self,phasenum):
     286        '''Converts relative phase number to a phase name in
     287        the current project
     288        '''
     289        item, cookie = self.GetFirstChild(self.root)
     290        while item:
     291            itemtext = self.GetItemText(item)
     292            if itemtext == "Phases":
     293                parent = item
     294                item, cookie = self.GetFirstChild(parent)
     295                i = 0
     296                while item:
     297                    if i == phasenum:
     298                        return self.GetItemText(item)
     299                    item, cookie = self.GetNextChild(parent, cookie)
     300                    i += 1
     301                else:
     302                    raise Exception("Phase "+str(phasenum)+" not found")
     303            item, cookie = self.GetNextChild(self.root, cookie)
     304        else:
     305            raise Exception("No phases found ")
     306#===========================================================================
     307class G2LoggedButton(wx.Button):
     308    '''A version of wx.Button that creates logging events. Bindings are saved
     309    in the object, and are looked up rather than directly set with a bind.
     310    An index to these buttons is saved as log.ButtonBindingLookup
     311    '''
     312    def __init__(self,parent,id,label,locationcode,handler,*args,**kwargs):
     313        super(self.__class__,self).__init__(parent,id,label,*args,**kwargs)
     314        self.label = label
     315        self.handler = handler
     316        self.locationcode = locationcode
     317        key = locationcode + '+' + label # hash code to find button
     318        self.Bind(wx.EVT_BUTTON,self.onPress)
     319        log.ButtonBindingLookup[key] = self
     320    def onPress(self,event):
     321        'create log event and call handler'
     322        log.MakeButtonLog(self.locationcode,self.label)
     323        self.handler(event)
     324#===========================================================================
    160325class ValidatedTxtCtrl(wx.TextCtrl):
    161326    '''Create a TextCtrl widget that uses a validator to prevent the
     
    322487        if self.result is not None: # note that this bypasses formatting
    323488            self.result[self.key] = val
     489            log.LogVarChange(self.result,self.key)
    324490        self._setValue(val)
    325491
     
    411577        else:
    412578            self.result[self.key] = val
     579        log.LogVarChange(self.result,self.key)
    413580
    414581    def _GetStringValue(self,event):
     
    425592        else:
    426593            self.result[self.key] = val
     594        log.LogVarChange(self.result,self.key)
    427595
    428596    def _onLoseFocus(self,event):
     
    541709            if val == '?' or val == '.':
    542710                self.result[self.key] = val
     711                log.LogVarChange(self.result,self.key)
    543712                return
    544713        try:
     
    569738        if self.key is not None and self.result is not None and not tc.invalid:
    570739            self.result[self.key] = val
     740            log.LogVarChange(self.result,self.key)
    571741
    572742    def ShowValidity(self,tc):
     
    684854        '''
    685855        self.result[self.key] = tc.GetValue().encode('ascii','replace')
     856        log.LogVarChange(self.result,self.key)
    686857
    687858    def OnChar(self, event):
     
    789960    def _OnCheckBox(self,event):
    790961        self.loc[self.key] = self.GetValue()
     962        log.LogVarChange(self.loc,self.key)
    791963################################################################################
    792964class G2ChoiceButton(wx.Choice):
     
    794966    the control to match a supplied value and saves the choice directly
    795967    into an array or list. Optionally a function can be called each time a
    796     choice is selected.
     968    choice is selected. The widget can be used with an array item that is set to
     969    to the choice by number (``indLoc[indKey]``) or by string value
     970    (``strLoc[strKey]``) or both. The initial value is taken from ``indLoc[indKey]``
     971    if not None or ``strLoc[strKey]`` if not None.
    797972
    798973    :param wx.Panel parent: name of panel or frame that will be
     
    800975    :param list choiceList: a list or tuple of choices to offer the user.
    801976    :param dict/list indLoc: a dict or list with the initial value to be
    802       placed in the Choice button.
     977      placed in the Choice button. If this is None, this is ignored.
    803978    :param int/str indKey: the dict key or the list index for the value to be
    804       edited by the Choice button. The ``indLoc[indKey]`` element must exist.
    805       The value for this should be None or an integer in range(len(choiceList)).
    806       The Choice button will be initialized to the choice corresponding to the
    807       value in this element if not None.
     979      edited by the Choice button. If indLoc is not None then this
     980      must be specified and the ``indLoc[indKey]`` will be set. If the value
     981      for ``indLoc[indKey]`` is not None, it should be an integer in
     982      range(len(choiceList)). The Choice button will be initialized to the
     983      choice corresponding to the value in this element if not None.
    808984    :param dict/list strLoc: a dict or list with the string value corresponding to
    809985      indLoc/indKey. Default (None) means that this is not used.
    810986    :param int/str strKey: the dict key or the list index for the string value
    811987      The ``strLoc[strKey]`` element must exist or strLoc must be None (default).
    812     :param function onChoice: name of a  
     988    :param function onChoice: name of a function to call when the choice is made.
    813989    '''
    814     def __init__(self,parent,choiceList,indLoc,indKey,strLoc=None,strKey=None,
     990    def __init__(self,parent,choiceList,indLoc=None,indKey=None,strLoc=None,strKey=None,
    815991                 onChoice=None,**kwargs):
    816992        wx.Choice.__init__(self,parent,choices=choiceList,id=wx.ID_ANY,**kwargs)
     
    821997        self.strKey = strKey
    822998        self.onChoice = None
    823         if self.indLoc[self.indKey] is not None:
     999        self.SetSelection(wx.NOT_FOUND)
     1000        if self.indLoc is not None and self.indLoc.get(self.indKey) is not None:
    8241001            self.SetSelection(self.indLoc[self.indKey])
    825         else:
    826             self.SetSelection(wx.NOT_FOUND)
     1002            if self.strLoc is not None:
     1003                self.strLoc[self.strKey] = self.GetStringSelection()
     1004                log.LogVarChange(self.strLoc,self.strKey)
     1005        elif self.strLoc is not None and self.strLoc.get(self.strKey) is not None:
     1006            try:
     1007                self.SetSelection(choiceList.index(self.strLoc[self.strKey]))
     1008                if self.indLoc is not None:
     1009                    self.indLoc[self.indKey] = self.GetSelection()
     1010                    log.LogVarChange(self.indLoc,self.indKey)
     1011            except ValueError:
     1012                pass
    8271013        self.Bind(wx.EVT_CHOICE, self._OnChoice)
    828         if self.strLoc is not None: # make sure strLoc gets initialized
    829             self._OnChoice(None) # note that onChoice will not be called
     1014        #if self.strLoc is not None: # make sure strLoc gets initialized
     1015        #    self._OnChoice(None) # note that onChoice will not be called
    8301016        self.onChoice = onChoice
    8311017    def _OnChoice(self,event):
    832         self.indLoc[self.indKey] = self.GetSelection()
     1018        if self.indLoc is not None:
     1019            self.indLoc[self.indKey] = self.GetSelection()
     1020            log.LogVarChange(self.indLoc,self.indKey)
    8331021        if self.strLoc is not None:
    8341022            self.strLoc[self.strKey] = self.GetStringSelection()
     1023            log.LogVarChange(self.strLoc,self.strKey)
    8351024        if self.onChoice:
    8361025            self.onChoice()
     
    26382827    where the functions to be called are defined.
    26392828    '''
    2640     def Bind(self,*args,**kwargs):
     2829    def Bind(self,eventtype,handler,*args,**kwargs):
    26412830        '''Override the Bind() function: on the Mac the binding is to
    26422831        the main window, so that menus operate with any window on top.
    2643         For other platforms, call the default wx.Frame Bind()
     2832        For other platforms, either wrap calls that will be logged
     2833        or call the default wx.Frame Bind() to bind to the menu item directly.
     2834
     2835        Note that bindings can be made to objects by Id or by direct reference to the
     2836        object. As a convention, when bindings are to objects, they are not logged
     2837        but when bindings are by Id, they are logged.
    26442838        '''
    26452839        if sys.platform == "darwin": # mac
    2646             self.G2frame.Bind(*args,**kwargs)
    2647         else:
    2648             wx.Frame.Bind(self,*args,**kwargs)     
     2840            self.G2frame.Bind(eventtype,handler,*args,**kwargs)
     2841            return
     2842        if eventtype == wx.EVT_MENU and 'id' in kwargs:
     2843            menulabels = log.SaveMenuCommand(kwargs['id'],self.G2frame,handler)
     2844            if menulabels:
     2845                #print 'intercepting bind for',handler,menulabels,kwargs['id']
     2846                wx.Frame.Bind(self,eventtype,self.G2frame.MenuBinding,*args,**kwargs)
     2847                return
     2848            wx.Frame.Bind(self,eventtype,handler,*args,**kwargs)     
    26492849       
    26502850    def PrefillDataMenu(self,menu,helpType,helpLbl=None,empty=False):
     
    26542854        '''
    26552855        self.datamenu = menu
     2856        self.G2frame.dataMenuBars.append(menu)
    26562857        self.helpType = helpType
    26572858        self.helpLbl = helpLbl
     
    34013602                                    wx.aui.AUI_NB_SCROLL_BUTTONS)
    34023603        if size: self.SetSize(size)
     3604        self.parent = parent
     3605        self.PageChangeHandler = None
     3606       
     3607    def PageChangeEvent(self,event):
     3608        G2frame = self.parent.G2frame
     3609        page = event.GetSelection()
     3610        if self.PageChangeHandler:
     3611            if log.LogInfo['Logging']:
     3612                log.MakeTabLog(
     3613                    G2frame.dataFrame.GetTitle(),
     3614                    G2frame.dataDisplay.GetPageText(page)
     3615                    )
     3616            self.PageChangeHandler(event)
     3617           
     3618    def Bind(self,eventtype,handler,*args,**kwargs):
     3619        '''Override the Bind() function so that page change events can be trapped
     3620        '''
     3621        if eventtype == wx.aui.EVT_AUINOTEBOOK_PAGE_CHANGED:
     3622            self.PageChangeHandler = handler
     3623            wx.aui.AuiNotebook.Bind(self,eventtype,self.PageChangeEvent)
     3624            return
     3625        wx.aui.AuiNotebook.Bind(self,eventtype,handler,*args,**kwargs)
    34033626                                                     
    34043627    def Clear(self):       
  • trunk/GSASIIpath.py

    r1413 r1512  
    6060if newpath not in sys.path: sys.path.append(newpath)
    6161
     62# setup read of config.py, if present
     63try:
     64    import config
     65    configDict = config.__dict__
     66    import inspect
     67    vals = [True for i in inspect.getmembers(config) if '__' not in i[0]]
     68    print str(len(vals))+' values read from config file '+os.path.abspath(config.__file__)
     69except ImportError:
     70    configDict = {}
     71   
     72def GetConfigValue(key):
     73    'Return the configuration file value for key or None if not present'
     74    return configDict.get(key)
     75
    6276# routines for looking a version numbers in files
    6377version = -1
  • trunk/GSASIIpwdGUI.py

    r1507 r1512  
    17221722            dlg.Destroy()
    17231723
    1724     def OnHistoType(event):
    1725         Obj = event.GetEventObject()
    1726         data['Type'] = Obj.GetValue()
    1727         if data['Type'] == 'Bragg-Brentano' and 'Shift' not in data:    #set up defaults for new type(s)
    1728             data['Shift'] = [0.0,False]
    1729             data['Transparency'] = [0.0,False]
     1724    def OnHistoChange():
     1725        '''Called when the histogram type is changed to refresh the window
     1726        '''
    17301727        wx.CallAfter(UpdateSampleGrid,G2frame,data)
    17311728       
     
    18191816    if 'SlitLen' not in data and 'SASD' in histName:
    18201817        data['SlitLen'] = 0.0
     1818    if 'Shift' not in data:
     1819        data['Shift'] = [0.0,False]
     1820    if 'Transparency' not in data:
     1821        data['Transparency'] = [0.0,False]
    18211822    data['InstrName'] = data.get('InstrName','')
    18221823#patch end
     
    18521853        else:
    18531854            choices = ['Debye-Scherrer','Bragg-Brentano',]
    1854         histoType = wx.ComboBox(G2frame.dataDisplay,wx.ID_ANY,value=data['Type'],choices=choices,
    1855             style=wx.CB_READONLY|wx.CB_DROPDOWN)
    1856         histoType.Bind(wx.EVT_COMBOBOX, OnHistoType)
     1855        histoType = G2gd.G2ChoiceButton(G2frame.dataDisplay,choices,
     1856                    strLoc=data,strKey='Type',
     1857                    onChoice=OnHistoChange)
    18571858        nameSizer.Add(histoType)
    18581859        mainSizer.Add(nameSizer,0,wx.EXPAND,1)
Note: See TracChangeset for help on using the changeset viewer.