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

logging pretty well ready to roll

File:
1 moved

Legend:

Unmodified
Added
Removed
  • 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.