Skip to content

Commit e32d690

Browse files
committed
This version worked! The main playback loop is done in foreground.
1 parent d387b49 commit e32d690

File tree

4 files changed

+315
-270
lines changed

4 files changed

+315
-270
lines changed

GSASII/GSASIIctrlGUI.py

Lines changed: 57 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2001,15 +2001,19 @@ def Filter(self,event):
20012001
self._ShowSelections()
20022002
self.OKbtn.Enable(True)
20032003

2004-
def ShowModal(self,*args,**kwargs):
2005-
print('Show Modal called')
2006-
if hasattr(self.G2frame,'Playback') and self.G2frame.Playback:
2007-
#raise Exception('needs work to replace ShowModal')
2008-
#print('in playback')
2009-
ShowAsNonModal(self)
2010-
2011-
else:
2012-
wx.Dialog.ShowModal(self,*args,**kwargs)
2004+
# this was used to make a modal dialog into a non-modal one
2005+
# while in playback mode when trying to playback in a thread.
2006+
# I have given up on threads for now.
2007+
#
2008+
# def ShowModal(self,*args,**kwargs):
2009+
# print('Show Modal called')
2010+
# if hasattr(self.G2frame,'Playback') and self.G2frame.Playback:
2011+
# #raise Exception('needs work to replace ShowModal')
2012+
# #print('in playback')
2013+
# ShowAsNonModal(self)
2014+
#
2015+
# else:
2016+
# wx.Dialog.ShowModal(self,*args,**kwargs)
20132017

20142018
############################################### Multichoice in a sizer with set all, toggle & filter options
20152019
class G2MultiChoiceWindow(wx.BoxSizer):
@@ -10148,52 +10152,50 @@ def SelectPkgInstall(event):
1014810152
G2fil.openInNewTerm(project)
1014910153
print ('exiting GSAS-II')
1015010154
sys.exit()
10151-
10152-
dlgResults = {}
10153-
def ShowAsNonModal(dlg):
10154-
'''For playback of commands, use this in place of wx.Dialog.ShowModal
10155-
because ShowModal should not be used inside a wx.CallAfter call
10156-
10157-
This retrieves the results of the dialog and places them
10158-
into dlgResults['selected']
10159-
'''
10160-
def handle_dialog_end_ok():
10161-
dlgResults['selected'] = dlg.GetSelections()
10162-
print('Selected:', dlgResults['selected'])
10163-
dlg.Destroy()
10164-
parent.Enable()
10165-
def handle_dialog_end_cancel():
10166-
dlgResults['selected'] = None
10167-
dlg.Destroy()
10168-
parent.Enable()
10169-
raise Exception("Cancel button pressed")
10170-
10171-
def on_ok(event):
10172-
event.Skip()
10173-
handle_dialog_end_ok()
10174-
10175-
def on_cancel(event):
10176-
event.Skip()
10177-
handle_dialog_end_cancel()
10178-
10179-
def on_close(event):
10180-
event.Skip()
10181-
handle_dialog_end_cancel()
10182-
10183-
# Bind to both button events and window close
10184-
dlg.Bind(wx.EVT_BUTTON, on_ok, id=wx.ID_OK)
10185-
dlg.Bind(wx.EVT_BUTTON, on_cancel, id=wx.ID_CANCEL)
10186-
dlg.Bind(wx.EVT_CLOSE, on_close)
10187-
10188-
parent = dlg.GetParent()
10189-
parent.Disable() # Disable main window while dialog is open
10190-
dlg.Show()
10191-
# time.sleep(0.1)
10192-
# count = 0
10193-
# while len(asyncResults) == 0:
10194-
# count += 1
10195-
# time.sleep(0.05)
10196-
# if count > 1000: raise Exception('too many waits')
10155+
10156+
# this was used to make a modal dialog into a non-modal one,
10157+
# but have the OK etc buttons trigger things anyway. I'm not 100% sure
10158+
# why this was needed.
10159+
#
10160+
# dlgResults = {}
10161+
# def ShowAsNonModal(dlg):
10162+
# '''For playback of commands, use this in place of wx.Dialog.ShowModal
10163+
# because ShowModal should not be used inside a wx.CallAfter call
10164+
#
10165+
# This retrieves the results of the dialog and places them
10166+
# into dlgResults['selected']
10167+
# '''
10168+
# def handle_dialog_end_ok():
10169+
# dlgResults['selected'] = dlg.GetSelections()
10170+
# print('Selected:', dlgResults['selected'])
10171+
# dlg.Destroy()
10172+
# parent.Enable()
10173+
# def handle_dialog_end_cancel():
10174+
# dlgResults['selected'] = None
10175+
# dlg.Destroy()
10176+
# parent.Enable()
10177+
# raise Exception("Cancel button pressed")
10178+
#
10179+
# def on_ok(event):
10180+
# event.Skip()
10181+
# handle_dialog_end_ok()
10182+
#
10183+
# def on_cancel(event):
10184+
# event.Skip()
10185+
# handle_dialog_end_cancel()
10186+
#
10187+
# def on_close(event):
10188+
# event.Skip()
10189+
# handle_dialog_end_cancel()
10190+
#
10191+
# # Bind to both button events and window close
10192+
# dlg.Bind(wx.EVT_BUTTON, on_ok, id=wx.ID_OK)
10193+
# dlg.Bind(wx.EVT_BUTTON, on_cancel, id=wx.ID_CANCEL)
10194+
# dlg.Bind(wx.EVT_CLOSE, on_close)
10195+
#
10196+
# parent = dlg.GetParent()
10197+
# parent.Disable() # Disable main window while dialog is open
10198+
# dlg.Show()
1019710199

1019810200

1019910201
if __name__ == '__main__':

GSASII/GSASIIdataGUI.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3259,9 +3259,10 @@ def ExitNow(event): # hacking for playback
32593259
print (traceback.format_exc())
32603260
elif any('SPYDER' in name for name in os.environ):
32613261
self.OnFileReopen(None)
3262-
import playback
3263-
import threading
3264-
threading.Thread(target=playback.Playback, args=(self,)).start()
3262+
# import playback
3263+
# import threading
3264+
# threading.Thread(target=playback.Playback, args=(self,)).start()
3265+
# playback.Playback(self)
32653266

32663267
def GetTreeItemsList(self,item):
32673268
''' returns a list of all GSAS-II tree items
@@ -4403,12 +4404,11 @@ def GetGPX():
44034404
print ('\nError opening file '+filename)
44044405
import traceback
44054406
print (traceback.format_exc())
4406-
# Playback after read of .gpx
4407-
import playback
4408-
import threading
4409-
threading.Thread(target=playback.Playback, args=(self,)).start()
4410-
#wx.CallAfter(doAfterFileLoad,G2frame) # logging playback test
4411-
#wx.CallAfter(self.doAfterFileLoad) # place automatic playback here
4407+
# Playback after read of .gpx from menu command
4408+
#import playback
4409+
#import threading
4410+
#threading.Thread(target=playback.Playback, args=(self,)).start()
4411+
#playback.Playback(self)
44124412

44134413
def OnFileBrowse(self, event):
44144414
'''Gets a GSAS-II .gpx project using the GPX browser, in response
@@ -6318,8 +6318,9 @@ def startPlayback(self,event):
63186318
from importlib import reload
63196319
import playback
63206320
reload(playback)
6321-
import threading
6322-
threading.Thread(target=playback.Playback, args=(self,)).start()
6321+
#import threading
6322+
#threading.Thread(target=playback.Playback, args=(self,)).start()
6323+
playback.Playback(self)
63236324

63246325
#### Data window side of main GUI; menu definitions here #########################
63256326
class G2DataWindow(wx.ScrolledWindow): #wxscroll.ScrolledPanel):

0 commit comments

Comments
 (0)