From 4328dd4f63bd86affd30a62a833d325da5ea9b71 Mon Sep 17 00:00:00 2001 From: David Rose Date: Sat, 11 Jan 2003 00:58:58 +0000 Subject: [PATCH] support hooks on user exit --- direct/src/showbase/ShowBase.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/direct/src/showbase/ShowBase.py b/direct/src/showbase/ShowBase.py index 06b38b51b0..2e4ce161e5 100644 --- a/direct/src/showbase/ShowBase.py +++ b/direct/src/showbase/ShowBase.py @@ -59,6 +59,10 @@ class ShowBase(DirectObject.DirectObject): self.wantDIRECT = self.config.GetBool('want-directtools', 0) self.wantStats = self.config.GetBool('want-stats', 0) + # Fill this in with a function to invoke when the user "exits" + # the program by closing the main window. + self.exitFunc = None + taskMgr.taskTimerVerbose = self.config.GetBool('task-timer-verbose', 0) taskMgr.extendedExceptions = self.config.GetBool('extended-exceptions', 0) @@ -1061,8 +1065,8 @@ class ShowBase(DirectObject.DirectObject): if win == self.win: if not properties.getOpen(): # If the user closes the main window, we should exit. - self.notify.info("User closed main window, exiting.") - sys.exit() + self.notify.info("User closed main window.") + self.userExit() if properties.getMinimized() and not self.mainWinMinimized: # If the main window is minimized, throw an event to @@ -1075,7 +1079,13 @@ class ShowBase(DirectObject.DirectObject): # restart the music. self.mainWinMinimized = 0 messenger.send('PandaRestarted') - + + def userExit(self): + # The user has requested we exit the program. Deal with this. + if self.exitFunc: + self.exitFunc() + self.notify.info("Exiting ShowBase.") + sys.exit() def run(self): self.taskMgr.run()