+#----------------------------------------------------------------------------
+_wxCallAfterId = None
+
+def wxCallAfter(callable, *args, **kw):
+ """
+ Call the specified function after the current and pending event
+ handlers have been completed. This is also good for making GUI
+ method calls from non-GUI threads.
+ """
+ app = wxGetApp()
+ assert app, 'No wxApp created yet'
+
+ global _wxCallAfterId
+ if _wxCallAfterId is None:
+ _wxCallAfterId = wxNewId()
+ app.Connect(-1, -1, _wxCallAfterId,
+ lambda event: apply(event.callable, event.args, event.kw) )
+ evt = wxPyEvent()
+ evt.SetEventType(_wxCallAfterId)
+ evt.callable = callable
+ evt.args = args
+ evt.kw = kw
+ wxPostEvent(app, evt)
+
+#----------------------------------------------------------------------
+
+class wxPyDeadObjectError(AttributeError):
+ pass
+
+class _wxPyDeadObject:
+ """
+ Instances of wx objects that are OOR capable will have their __class__
+ changed to this class when the C++ object is deleted. This should help
+ prevent crashes due to referencing a bogus C++ pointer.
+ """
+ reprStr = "wxPython wrapper for DELETED %s object! (The C++ object no longer exists.)"
+ attrStr = "The C++ part of the %s object has been deleted, attribute access no longer allowed."
+
+ def __repr__( self ):
+ if not hasattr(self, "_name"):
+ self._name = "[unknown]"
+ return self.reprStr % self._name
+
+ def __getattr__( self, *args ):
+ if not hasattr(self, "_name"):
+ self._name = "[unknown]"
+ raise wxPyDeadObjectError( self.attrStr % self._name )
+
+ def __nonzero__(self):
+ return 0
+
+