Better handling of the refcount of the wx.App object, so it now

destroyed when expected and also resets the current instance pointer
returned by wx.GetApp().


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@33515 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn 2005-04-11 19:14:34 +00:00
parent bcd882b35e
commit 69ac96fd0d
3 changed files with 13 additions and 8 deletions

View File

@ -48,8 +48,8 @@ class wxPyApp : public wxEvtHandler {
public: public:
%pythonAppend wxPyApp %pythonAppend wxPyApp
"self._setCallbackInfo(self, PyApp) "self._setCallbackInfo(self, PyApp, False)
self._setOORInfo(self)"; self._setOORInfo(self, False)";
%typemap(out) wxPyApp*; // turn off this typemap %typemap(out) wxPyApp*; // turn off this typemap
DocStr(wxPyApp, DocStr(wxPyApp,
@ -67,7 +67,7 @@ public:
%typemap(out) wxPyApp* { $result = wxPyMake_wxObject($1, $owner); } %typemap(out) wxPyApp* { $result = wxPyMake_wxObject($1, $owner); }
void _setCallbackInfo(PyObject* self, PyObject* _class); void _setCallbackInfo(PyObject* self, PyObject* _class, bool incref);
DocDeclStr( DocDeclStr(

View File

@ -176,9 +176,12 @@ your Mac."""
def __del__(self): def __del__(self):
try: try:
self.RestoreStdio() # Just in case the MainLoop was overridden self.RestoreStdio() # Just in case the MainLoop was overridden
except: finally:
pass wx.PyApp.__del__(self)
def Destroy(self):
wx.PyApp.Destroy(self)
self.thisown = 0
def SetTopWindow(self, frame): def SetTopWindow(self, frame):
"""Set the \"main\" top level window""" """Set the \"main\" top level window"""

View File

@ -126,6 +126,8 @@ wxPyApp::wxPyApp() {
wxPyApp::~wxPyApp() { wxPyApp::~wxPyApp() {
wxPythonApp = NULL;
wxApp::SetInstance(NULL);
} }
@ -408,11 +410,11 @@ void wxPyApp::_BootstrapApp()
if (sysargv != NULL && executable != NULL) { if (sysargv != NULL && executable != NULL) {
argc = PyList_Size(sysargv) + 1; argc = PyList_Size(sysargv) + 1;
argv = new char*[argc+1]; argv = new char*[argc+1];
argv[0] = PyString_AsString(executable); argv[0] = strdup(PyString_AsString(executable));
int x; int x;
for(x=1; x<argc; x++) { for(x=1; x<argc; x++) {
PyObject *pyArg = PyList_GetItem(sysargv, x-1); PyObject *pyArg = PyList_GetItem(sysargv, x-1);
argv[x] = PyString_AsString(pyArg); argv[x] = strdup(PyString_AsString(pyArg));
} }
argv[argc] = NULL; argv[argc] = NULL;
} }
@ -420,7 +422,7 @@ void wxPyApp::_BootstrapApp()
// Initialize wxWidgets // Initialize wxWidgets
result = wxEntryStart(argc, argv); result = wxEntryStart(argc, argv);
delete [] argv; // wxApp takes ownership of the argv array, don't delete it here
blocked = wxPyBeginBlockThreads(); blocked = wxPyBeginBlockThreads();
if (! result) { if (! result) {