@@ -99,6 +99,11 @@ def new_util_find_library( name ):
9999commonNames = ['abc' ,'bca' ,'cab' ,'a-cb' ,'ba-c' ,'-cba' ,'P->A' ,'A->P' ,'P->B' ,'B->P' ,'P->C' ,'C->P' ,
100100 'P->I' ,'I->P' ,'P->F' ,'F->P' ,'H->R' ,'R->H' ,'R->O' ,'O->R' ,'abc*' ,'setting 1->2' ] #don't put any new ones after the setting one!
101101
102+ loggingExitCommands = []
103+ # clear out any old commamnds in the file
104+ with open ('/tmp/G2logging.txt' ,'w' ) as fp :
105+ fp .write (f'# GSAS-II event logging file { time .ctime ()} \n ' )
106+
102107def GetDisplay (pos ):
103108 '''Gets display number (0=main display) for window position (pos). If pos outside all displays
104109 returns None
@@ -617,6 +622,7 @@ def GSASIImain(application):
617622 dlg .ShowModal ()
618623 finally :
619624 dlg .Destroy ()
625+ for cmd in loggingExitCommands : cmd () # cleanup logging
620626 sys .exit ()
621627
622628 application .main = GSASII (None ) # application.main is the main wx.Frame (G2frame in most places)
@@ -634,6 +640,11 @@ def GSASIImain(application):
634640class G2EventLogger (wx .EvtHandler ):
635641 '''This is used to record all wx events
636642 '''
643+ def log2File (self ,txt ):
644+ with open ('/tmp/G2logging.txt' ,'a' ) as fp :
645+ fp .write (txt )
646+ fp .write ('\n ' )
647+
637648 def ProcessEvent (self , event ):
638649 # how to log "action" widgets (checkbuttons, buttons, etc.)?
639650 # How to log info supplied in dialogs
@@ -650,6 +661,7 @@ def ShowTreeSelection(tree):
650661 txt = tree .GetItemText (sel )
651662 print (' parent' ,txt )
652663 print ('Tree selection (after)' ,l )
664+ self .log2File (f'Tree_selection: { l } ' )
653665 #fp = open('/tmp/events.txt','a')
654666 #print(f"Event {event.GetEventType()} Obj {event.GetEventObject()}")
655667 #fp.write(f"Event {event.GetEventType()} Obj {event.GetEventObject()}\n")
@@ -710,11 +722,12 @@ def logFrame(self,frame):
710722 self .eventLog = {}
711723 self .start = time .time ()
712724 self .G2frame = frame
713- frame .PushEventHandler (self )
725+ self .G2frame .PushEventHandler (self )
726+ loggingExitCommands .append (self .unlogFrame )
714727 def unlogFrame (self ):
715728 # note that we need to do a PopEventHandler before the
716729 # frame is deleted
717- frame . PopEventHandler (self )
730+ self . G2frame . PopEventHandler ()
718731
719732#### Create main frame (window) for GUI; main menu items here #######################################
720733class GSASII (wx .Frame ):
@@ -2448,6 +2461,7 @@ def OnPreferences(self,event):
24482461 project = None
24492462 G2fil .openInNewTerm (project )
24502463 print ('exiting GSAS-II' )
2464+ for cmd in loggingExitCommands : cmd () # cleanup logging
24512465 sys .exit ()
24522466
24532467 def _Add_ImportMenu_smallangle (self ,parent ):
@@ -4684,6 +4698,7 @@ def ExitMain(self, event):
46844698 self .G2plotNB .Destroy ()
46854699 if self .undofile and os .path .exists (self .undofile ):
46864700 os .remove (self .undofile )
4701+ for cmd in loggingExitCommands : cmd () # cleanup logging
46874702 sys .exit ()
46884703
46894704 def OnExportMTZ (self ,event ):
0 commit comments