From 95b101e7f336a984bc9a97664d20d3232d3a9879 Mon Sep 17 00:00:00 2001 From: David Rose Date: Tue, 4 Aug 2009 18:22:19 +0000 Subject: [PATCH] add stop() method --- direct/src/showutil/runp3d.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/direct/src/showutil/runp3d.py b/direct/src/showutil/runp3d.py index bcdbee8c12..8a38263440 100755 --- a/direct/src/showutil/runp3d.py +++ b/direct/src/showutil/runp3d.py @@ -78,6 +78,10 @@ class AppRunner(DirectObject): # of the plugin instance in the DOM. self.attributes = ScriptAttributes() + # By default, we publish a stop() method so the browser can + # easy stop the plugin. + self.attributes.stop = self.stop + # This will be the browser's toplevel window DOM object; # e.g. self.dom.document will be the document. self.dom = None @@ -103,6 +107,15 @@ class AppRunner(DirectObject): # call back to the main thread. self.accept('startIfReady', self.startIfReady) + def stop(self): + """ This method can be called by JavaScript to stop the + application. """ + + # We defer the actual exit for a few frames, so we don't raise + # an exception and invalidate the JavaScript call; and also to + # help protect against race conditions as the application + # shuts down. + taskMgr.doMethodLater(0.5, sys.exit, 'exit') def setSessionId(self, sessionId): """ This message should come in at startup. """