X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/822e03eeffe940efdcae10f44f46bd49e6f76131..3a9becbd5439254a77e7dbc0278d80117a397264:/wxPython/src/helpers.cpp?ds=sidebyside diff --git a/wxPython/src/helpers.cpp b/wxPython/src/helpers.cpp index 2a568e3e38..a1a20b66fa 100644 --- a/wxPython/src/helpers.cpp +++ b/wxPython/src/helpers.cpp @@ -97,6 +97,7 @@ PyObject* wxPyPtrTypeMap = NULL; // This gets run when the DLL is loaded. We just need to save a handle. //---------------------------------------------------------------------- +extern "C" BOOL WINAPI DllMain( HINSTANCE hinstDLL, // handle to DLL module DWORD fdwReason, // reason for calling function @@ -125,6 +126,8 @@ wxPyApp::wxPyApp() { wxPyApp::~wxPyApp() { + wxPythonApp = NULL; + wxApp::SetInstance(NULL); } @@ -400,14 +403,18 @@ void wxPyApp::_BootstrapApp() int argc = 0; char** argv = NULL; blocked = wxPyBeginBlockThreads(); + PyObject* sysargv = PySys_GetObject("argv"); - if (sysargv != NULL) { - argc = PyList_Size(sysargv); + PyObject* executable = PySys_GetObject("executable"); + + if (sysargv != NULL && executable != NULL) { + argc = PyList_Size(sysargv) + 1; argv = new char*[argc+1]; + argv[0] = strdup(PyString_AsString(executable)); int x; - for(x=0; xargc = 0; + this->argv = NULL; + } + // It's now ok to generate exceptions for assertion errors. wxPythonApp->SetStartupComplete(true); @@ -987,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 @@ -1003,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 @@ -1020,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(); @@ -1035,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); } @@ -1155,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; @@ -1173,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