Changeset 1510 for branch/logging


Ignore:
Timestamp:
Oct 1, 2014 4:14:25 PM (9 years ago)
Author:
toby
Message:

logging pretty well ready to roll

Location:
branch/logging
Files:
2 edited
1 moved

Legend:

Unmodified
Added
Removed
  • branch/logging/GSASII.py

    r1509 r1510  
    7676import GSASIIobj as G2obj
    7777import GSASIIlattice as G2lat
     78import GSASIIlog as log
    7879
    7980#wx inspector - use as needed
     
    124125    '''
    125126    def MenuBinding(self,event):
    126         import log
    127127        log.InvokeMenuCommand(event.GetId(),self,event)
    128128           
     
    130130        '''Override the Bind() function so that we can wrap calls that will be logged.
    131131        '''
    132         import log
    133132        #print 'main frame bind',handler
    134133        if eventtype == wx.EVT_MENU and 'id' in kwargs:
     
    16261625       
    16271626    def OnMacroRecordStatus(self,event,setvalue=None):
    1628         import log
    16291627        nextvalue = log.ShowLogStatus() != True
    16301628        if setvalue is not None:
     
    16401638
    16411639    def _init_Macro(self):
    1642         import log
    16431640        menu = self.MacroMenu
    16441641        item = menu.Append(
     
    16531650            kind=wx.ITEM_NORMAL,text='Show log')
    16541651        def OnShowLog(event):
    1655             import log
    16561652            print 70*'='
    16571653            print 'List of logged actions'
     
    16711667            kind=wx.ITEM_NORMAL,text='Save log')
    16721668        def OnSaveLog(event):
    1673             import log
    16741669            import cPickle
    16751670            defnam = os.path.splitext(
     
    17031698        def OnLoadLog(event):
    17041699            # this appends. Perhaps we should ask to clear?
    1705             import log
    17061700            import cPickle
    17071701            defnam = os.path.splitext(
     
    19791973       
    19801974        wxID_PATTERNTREE = wx.NewId()
    1981         #self.PatternTree = wx.TreeCtrl(id=wxID_PATTERNTREE,
    1982         import log
     1975        #self.PatternTree = wx.TreeCtrl(id=wxID_PATTERNTREE, # replaced for logging
    19831976        self.PatternTree = G2gd.G2TreeCtrl(id=wxID_PATTERNTREE,
    19841977            parent=self.mainPanel, pos=wx.Point(0, 0),style=wx.TR_DEFAULT_STYLE )
  • branch/logging/GSASIIgrid.py

    r1509 r1510  
    4545import GSASIIobj as G2obj
    4646import GSASIIexprGUI as G2exG
    47 import log
     47import GSASIIlog as log
    4848
    4949# trig functions in degrees
     
    171171    def __init__(self,parent=None,*args,**kwargs):
    172172        super(self.__class__,self).__init__(parent=parent,*args,**kwargs)
    173         log.LogInfo['G2frame'] = self.G2frame = parent.GetParent()
     173        self.G2frame = parent.GetParent()
    174174        self.root = self.AddRoot('Loaded Data: ')
    175175        self.SelectionChanged = None
     
    198198                if textlist[0] == "Phases" and len(textlist) > 1:
    199199                    textlist[1] = self.GetRelativePhaseNum(textlist[1])
    200                 log.G2logList.append(log.TreeLogEntry(textlist))
     200                log.MakeTreeLog(textlist)
    201201            self.SelectionChanged(event)
    202202
     
    318318    def onPress(self,event):
    319319        'create log event and call handler'
    320         G2logList.append(log.ButtonLogEntry(self.locationcode,self.label))
     320        log.MakeButtonLog(self.locationcode,self.label)
    321321        self.handler(event)
    322322
     
    35973597
    35983598    def PageChangeEvent(self,event):
    3599         import log
    36003599        G2frame = self.parent.G2frame
    36013600        page = event.GetSelection()
    36023601        if self.PageChangeHandler:
    36033602            if log.LogInfo['Logging']:
    3604                 log.G2logList.append(log.TabLogEntry(
     3603                log.MakeTabLog(
    36053604                    G2frame.dataFrame.GetTitle(),
    36063605                    G2frame.dataDisplay.GetPageText(page)
    3607                 ))
     3606                    )
    36083607            self.PageChangeHandler(event)
    36093608           
     
    41354134
    41364135    # DEBUG code: stick testing button on Controls page
    4137     import log
    41384136    def TestButton(event):
    41394137        print 'TestButton'
  • branch/logging/GSASIIlog.py

    r1509 r1510  
    1 'Module to provide logging services'
     1# -*- coding: utf-8 -*-
     2#GSASIIlog - Routines used to track and replay "actions"
     3########### SVN repository information ###################
     4# $Date: $
     5# $Author: toby $
     6# $Revision: $
     7# $URL: $
     8# $Id: $
     9########### SVN repository information ###################
     10'''Module to provide logging services, e.g. track and replay "actions"
     11such as menu item, tree item, button press, value change and so on.
     12'''
    213import wx
    314import GSASIIgrid as G2gd
     
    819G2logList = [None]
    920'Contains a list of logged actions; first item is ignored'
    10 LogInfo = {'Logging':False, 'Tree':None, 'G2frame':None, 'LastPaintAction':None}
     21LogInfo = {'Logging':False, 'Tree':None, 'LastPaintAction':None}
    1122'Contains a dict with values that are needed in the module'
    1223
    1324# TODO:
    14 # might want to save the last displayed screen with some objects to make sure
     25# Might want to save the last displayed screen with some objects to make sure
    1526# the commands are executed in a sensible order
    16 
    17 # Problem: checks on Logging not set properly (still!)
     27# 1) save tree press under tab press item.
     28# 2) save tree & tab for button press
     29
     30# TODO:
     31# probably need an object for saving calls and arguments to call specific functions/methods.
     32# The items to be called need to register themselves so that they can be found
     33#   This needs to be done with a Register(function,'unique-string') call after every def
     34#   and then a LogCall('unique-string',pargs,kwargs) call inside the routine
    1835
    1936debug = True
     
    2845    return s
    2946
    30 # Define logging objects. These store information on events in a manner that can be
    31 # pickled and saved -- direct references to wx objects is not allowed.
    32 # each object should define:
    33 #     __init__: stores the information needed to log & later recreate the action
    34 #     __str__ : shows a nice ASCII string for each action
    35 #     Replay:   recreates the action when the log is played
    36 # optional
    37 #     Repaint:  redisplays the current window
    38 
    39 class VarLogEntry(object):
     47class LogEntry(object):
     48    '''Base class to define logging objects. These store information on events
     49    in a manner that can be pickled and saved -- direct references to wx objects
     50    is not allowed.
     51
     52    Each object must define:
     53   
     54     *  __init__: stores the information needed to log & later recreate the action
     55     *  __str__ : shows a nice ASCII string for each action
     56     *  Replay:   recreates the action when the log is played
     57     
     58    optional:
     59   
     60      * Repaint:  redisplays the current window
     61     
     62    '''
     63    def __init__(self):
     64        'Must be defined'
     65        raise Exception('No __init__ defined')
     66    def __str__(self):
     67        'Must be defined'
     68        raise Exception('No __str__ defined')
     69    def Replay(self):
     70        'Must be defined'
     71        raise Exception('No Replay defined')
     72    def Repaint(self):
     73        pass
     74
     75class VarLogEntry(LogEntry):
    4076    'object that tracks changes to a variable'
    4177    def __init__(self,treeRefs,indexRefs,value):
     
    73109        data[self.indexRefs[-1]] = self.value
    74110
    75 class MenuLogEntry(object):
     111class MenuLogEntry(LogEntry):
    76112    'object that tracks when a menu command is executed'
    77113    def __init__(self,menulabellist):
     
    101137            raise Exception('No binding for menu item '+key)       
    102138           
    103 class TabLogEntry(object):
     139class TabLogEntry(LogEntry):
    104140    'Object to track when tabs are pressed in the DataFrame window'
    105141    def __init__(self,title,tabname):
     
    131167                PageNum in range(LogInfo['Tree'].G2frame.dataDisplay.GetPageCount())]
    132168            raise Exception('tab not found')
    133 
    134 class TreeLogEntry(object):
     169def MakeTabLog(title,tabname):
     170    'Create a TabLogEntry action log'
     171    G2logList.append(TabLogEntry(title,tabname))
     172
     173class TreeLogEntry(LogEntry):
    135174    'Object to track when tree items are pressed in the main window'
    136175    def __init__(self,itemlist):
     
    168207        else:
    169208            LogInfo['Tree'].SelectItem(item)
    170 
    171 class ButtonLogEntry(object):
     209def MakeTreeLog(textlist):
     210    'Create a TreeLogEntry action log'
     211    G2logList.append(TreeLogEntry(textlist))
     212   
     213class ButtonLogEntry(LogEntry):
    172214    'Object to track button press'
    173215    def __init__(self,locationcode,label):
     
    185227            #btn.GetEventHandler().ProcessEvent(clickEvent)
    186228            btn.handler(clickEvent)
     229def MakeButtonLog(locationcode,label):
     230    'Create a ButtonLogEntry action log'
     231    G2logList.append(ButtonLogEntry(locationcode,label))
     232   
    187233           
    188234def _wrapper(func):
     
    382428    routine "bind"ed to that menu item
    383429    '''
    384     menuLabelList = _getmenuinfo(id,G2frame,None)
     430    menuLabelList,menuobj = _getmenuinfo(id,G2frame,None)
    385431    key = ''
    386432    if menuLabelList:
     
    437483        wx.Yield()
    438484    if i >= len(G2logList)-1:
    439          dlg.EndModal(wx.ID_OK)
     485        dlg.EndModal(wx.ID_OK)
    440486    else:
    441487        clb.DeselectAll()
    442488        clb.SetSelection(i)
    443         if logstat: LogOn()
    444489    if debug: print 70*'='
    445490    # if the last command did not display a window, repaint it in
     
    447492    if item != LogInfo['LastPaintAction'] and hasattr(LogInfo['LastPaintAction'],'Repaint'):
    448493        LogInfo['LastPaintAction'].Repaint()
     494    if logstat: LogOn()
    449495     
    450496def ReplayLog(event):
     
    492538    dlg.ShowModal()
    493539    dlg.Destroy()
     540    LogInfo['Tree'].G2frame.OnMacroRecordStatus(None) # sync the menu checkmark(s)
    494541    return
    495542
Note: See TracChangeset for help on using the changeset viewer.