X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/bd07485ce310b193d1a678b3bcd6d63e3d8bac19..3a9604b42b150d20382faa819ffdf38c3bba33b6:/wxPython/src/helpers.cpp diff --git a/wxPython/src/helpers.cpp b/wxPython/src/helpers.cpp index cac45b0cbc..a1a20b66fa 100644 --- a/wxPython/src/helpers.cpp +++ b/wxPython/src/helpers.cpp @@ -126,6 +126,8 @@ wxPyApp::wxPyApp() { wxPyApp::~wxPyApp() { + wxPythonApp = NULL; + wxApp::SetInstance(NULL); } @@ -408,11 +410,11 @@ void wxPyApp::_BootstrapApp() if (sysargv != NULL && executable != NULL) { argc = PyList_Size(sysargv) + 1; argv = new char*[argc+1]; - argv[0] = PyString_AsString(executable); + argv[0] = strdup(PyString_AsString(executable)); int x; for(x=1; xargc = 0; + this->argv = NULL; + } + // It's now ok to generate exceptions for assertion errors. wxPythonApp->SetStartupComplete(true); @@ -994,6 +1001,7 @@ void wxPyPtrTypeMap_Add(const char* commonName, const char* ptrName) { PyObject* wxPyMake_wxObject(wxObject* source, bool setThisOwn, bool checkEvtHandler) { PyObject* target = NULL; bool isEvtHandler = false; + bool isSizer = false; if (source) { // If it's derived from wxEvtHandler then there may @@ -1010,6 +1018,18 @@ PyObject* wxPyMake_wxObject(wxObject* source, bool setThisOwn, bool checkEvtHan } } + // Also check for wxSizer + if (!target && wxIsKindOf(source, wxSizer)) { + isSizer = true; + wxSizer* sz = (wxSizer*)source; + wxPyOORClientData* data = (wxPyOORClientData*)sz->GetClientObject(); + if (data) { + target = data->m_obj; + if (target) + Py_INCREF(target); + } + } + if (! target) { // Otherwise make it the old fashioned way by making a new shadow // object and putting this pointer in it. Look up the class @@ -1027,6 +1047,8 @@ PyObject* wxPyMake_wxObject(wxObject* source, bool setThisOwn, bool checkEvtHan target = wxPyConstructObject((void*)source, name, setThisOwn); if (target && isEvtHandler) ((wxEvtHandler*)source)->SetClientObject(new wxPyOORClientData(target)); + if (target && isSizer) + ((wxSizer*)source)->SetClientObject(new wxPyOORClientData(target)); } else { wxString msg(wxT("wxPython class not found for ")); msg += source->GetClassInfo()->GetClassName(); @@ -1042,25 +1064,8 @@ PyObject* wxPyMake_wxObject(wxObject* source, bool setThisOwn, bool checkEvtHan PyObject* wxPyMake_wxSizer(wxSizer* source, bool setThisOwn) { - PyObject* target = NULL; - if (source && wxIsKindOf(source, wxSizer)) { - // If it's derived from wxSizer then there may already be a pointer to - // a Python object that we can use in the OOR data. - wxSizer* sz = (wxSizer*)source; - wxPyOORClientData* data = (wxPyOORClientData*)sz->GetClientObject(); - if (data) { - target = data->m_obj; - if (target) - Py_INCREF(target); - } - } - if (! target) { - target = wxPyMake_wxObject(source, setThisOwn, false); - if (target != Py_None) - ((wxSizer*)source)->SetClientObject(new wxPyOORClientData(target)); - } - return target; + return wxPyMake_wxObject(source, setThisOwn); } @@ -1162,6 +1167,9 @@ void wxPyEndAllowThreads(PyThreadState* saved) { wxPyBlock_t wxPyBeginBlockThreads() { #ifdef WXP_WITH_THREAD + if (! Py_IsInitialized()) { + return (wxPyBlock_t)0; + } #if wxPyUSE_GIL_STATE PyGILState_STATE state = PyGILState_Ensure(); return state; @@ -1180,13 +1188,16 @@ wxPyBlock_t wxPyBeginBlockThreads() { return blocked; #endif #else - return false; + return (wxPyBlock_t)0; #endif } void wxPyEndBlockThreads(wxPyBlock_t blocked) { #ifdef WXP_WITH_THREAD + if (! Py_IsInitialized()) { + return; + } #if wxPyUSE_GIL_STATE PyGILState_Release(blocked); #else