Changeset 1510 for branch/logging
- Timestamp:
- Oct 1, 2014 4:14:25 PM (9 years ago)
- Location:
- branch/logging
- Files:
-
- 2 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branch/logging/GSASII.py
r1509 r1510 76 76 import GSASIIobj as G2obj 77 77 import GSASIIlattice as G2lat 78 import GSASIIlog as log 78 79 79 80 #wx inspector - use as needed … … 124 125 ''' 125 126 def MenuBinding(self,event): 126 import log127 127 log.InvokeMenuCommand(event.GetId(),self,event) 128 128 … … 130 130 '''Override the Bind() function so that we can wrap calls that will be logged. 131 131 ''' 132 import log133 132 #print 'main frame bind',handler 134 133 if eventtype == wx.EVT_MENU and 'id' in kwargs: … … 1626 1625 1627 1626 def OnMacroRecordStatus(self,event,setvalue=None): 1628 import log1629 1627 nextvalue = log.ShowLogStatus() != True 1630 1628 if setvalue is not None: … … 1640 1638 1641 1639 def _init_Macro(self): 1642 import log1643 1640 menu = self.MacroMenu 1644 1641 item = menu.Append( … … 1653 1650 kind=wx.ITEM_NORMAL,text='Show log') 1654 1651 def OnShowLog(event): 1655 import log1656 1652 print 70*'=' 1657 1653 print 'List of logged actions' … … 1671 1667 kind=wx.ITEM_NORMAL,text='Save log') 1672 1668 def OnSaveLog(event): 1673 import log1674 1669 import cPickle 1675 1670 defnam = os.path.splitext( … … 1703 1698 def OnLoadLog(event): 1704 1699 # this appends. Perhaps we should ask to clear? 1705 import log1706 1700 import cPickle 1707 1701 defnam = os.path.splitext( … … 1979 1973 1980 1974 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 1983 1976 self.PatternTree = G2gd.G2TreeCtrl(id=wxID_PATTERNTREE, 1984 1977 parent=self.mainPanel, pos=wx.Point(0, 0),style=wx.TR_DEFAULT_STYLE ) -
branch/logging/GSASIIgrid.py
r1509 r1510 45 45 import GSASIIobj as G2obj 46 46 import GSASIIexprGUI as G2exG 47 import log47 import GSASIIlog as log 48 48 49 49 # trig functions in degrees … … 171 171 def __init__(self,parent=None,*args,**kwargs): 172 172 super(self.__class__,self).__init__(parent=parent,*args,**kwargs) 173 log.LogInfo['G2frame'] =self.G2frame = parent.GetParent()173 self.G2frame = parent.GetParent() 174 174 self.root = self.AddRoot('Loaded Data: ') 175 175 self.SelectionChanged = None … … 198 198 if textlist[0] == "Phases" and len(textlist) > 1: 199 199 textlist[1] = self.GetRelativePhaseNum(textlist[1]) 200 log. G2logList.append(log.TreeLogEntry(textlist))200 log.MakeTreeLog(textlist) 201 201 self.SelectionChanged(event) 202 202 … … 318 318 def onPress(self,event): 319 319 'create log event and call handler' 320 G2logList.append(log.ButtonLogEntry(self.locationcode,self.label))320 log.MakeButtonLog(self.locationcode,self.label) 321 321 self.handler(event) 322 322 … … 3597 3597 3598 3598 def PageChangeEvent(self,event): 3599 import log3600 3599 G2frame = self.parent.G2frame 3601 3600 page = event.GetSelection() 3602 3601 if self.PageChangeHandler: 3603 3602 if log.LogInfo['Logging']: 3604 log. G2logList.append(log.TabLogEntry(3603 log.MakeTabLog( 3605 3604 G2frame.dataFrame.GetTitle(), 3606 3605 G2frame.dataDisplay.GetPageText(page) 3607 ))3606 ) 3608 3607 self.PageChangeHandler(event) 3609 3608 … … 4135 4134 4136 4135 # DEBUG code: stick testing button on Controls page 4137 import log4138 4136 def TestButton(event): 4139 4137 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" 11 such as menu item, tree item, button press, value change and so on. 12 ''' 2 13 import wx 3 14 import GSASIIgrid as G2gd … … 8 19 G2logList = [None] 9 20 'Contains a list of logged actions; first item is ignored' 10 LogInfo = {'Logging':False, 'Tree':None, ' G2frame':None, 'LastPaintAction':None}21 LogInfo = {'Logging':False, 'Tree':None, 'LastPaintAction':None} 11 22 'Contains a dict with values that are needed in the module' 12 23 13 24 # TODO: 14 # might want to save the last displayed screen with some objects to make sure25 # Might want to save the last displayed screen with some objects to make sure 15 26 # 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 18 35 19 36 debug = True … … 28 45 return s 29 46 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): 47 class 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 75 class VarLogEntry(LogEntry): 40 76 'object that tracks changes to a variable' 41 77 def __init__(self,treeRefs,indexRefs,value): … … 73 109 data[self.indexRefs[-1]] = self.value 74 110 75 class MenuLogEntry( object):111 class MenuLogEntry(LogEntry): 76 112 'object that tracks when a menu command is executed' 77 113 def __init__(self,menulabellist): … … 101 137 raise Exception('No binding for menu item '+key) 102 138 103 class TabLogEntry( object):139 class TabLogEntry(LogEntry): 104 140 'Object to track when tabs are pressed in the DataFrame window' 105 141 def __init__(self,title,tabname): … … 131 167 PageNum in range(LogInfo['Tree'].G2frame.dataDisplay.GetPageCount())] 132 168 raise Exception('tab not found') 133 134 class TreeLogEntry(object): 169 def MakeTabLog(title,tabname): 170 'Create a TabLogEntry action log' 171 G2logList.append(TabLogEntry(title,tabname)) 172 173 class TreeLogEntry(LogEntry): 135 174 'Object to track when tree items are pressed in the main window' 136 175 def __init__(self,itemlist): … … 168 207 else: 169 208 LogInfo['Tree'].SelectItem(item) 170 171 class ButtonLogEntry(object): 209 def MakeTreeLog(textlist): 210 'Create a TreeLogEntry action log' 211 G2logList.append(TreeLogEntry(textlist)) 212 213 class ButtonLogEntry(LogEntry): 172 214 'Object to track button press' 173 215 def __init__(self,locationcode,label): … … 185 227 #btn.GetEventHandler().ProcessEvent(clickEvent) 186 228 btn.handler(clickEvent) 229 def MakeButtonLog(locationcode,label): 230 'Create a ButtonLogEntry action log' 231 G2logList.append(ButtonLogEntry(locationcode,label)) 232 187 233 188 234 def _wrapper(func): … … 382 428 routine "bind"ed to that menu item 383 429 ''' 384 menuLabelList = _getmenuinfo(id,G2frame,None)430 menuLabelList,menuobj = _getmenuinfo(id,G2frame,None) 385 431 key = '' 386 432 if menuLabelList: … … 437 483 wx.Yield() 438 484 if i >= len(G2logList)-1: 439 485 dlg.EndModal(wx.ID_OK) 440 486 else: 441 487 clb.DeselectAll() 442 488 clb.SetSelection(i) 443 if logstat: LogOn()444 489 if debug: print 70*'=' 445 490 # if the last command did not display a window, repaint it in … … 447 492 if item != LogInfo['LastPaintAction'] and hasattr(LogInfo['LastPaintAction'],'Repaint'): 448 493 LogInfo['LastPaintAction'].Repaint() 494 if logstat: LogOn() 449 495 450 496 def ReplayLog(event): … … 492 538 dlg.ShowModal() 493 539 dlg.Destroy() 540 LogInfo['Tree'].G2frame.OnMacroRecordStatus(None) # sync the menu checkmark(s) 494 541 return 495 542
Note: See TracChangeset
for help on using the changeset viewer.