X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4acff284f9516e2a4f0fcfa7bcfa3f497b8005cc..9c46ea66472d59fe5fe623c456e540e47d922fcf:/wxPython/src/helpers.cpp diff --git a/wxPython/src/helpers.cpp b/wxPython/src/helpers.cpp index c3c52d2a6e..72f84096ac 100644 --- a/wxPython/src/helpers.cpp +++ b/wxPython/src/helpers.cpp @@ -47,6 +47,7 @@ int WXDLLEXPORT wxEntryInitGui(); void WXDLLEXPORT wxEntryCleanup(); wxPyApp* wxPythonApp = NULL; // Global instance of application object +bool wxPyDoCleanup = FALSE; #ifdef WXP_WITH_THREAD @@ -79,8 +80,11 @@ BOOL WINAPI DllMain( LPVOID lpvReserved // reserved ) { - wxSetInstance(hinstDLL); - return 1; + // If wxPython is embedded in another wxWindows app then + // the inatance has already been set. + if (! wxGetInstance()) + wxSetInstance(hinstDLL); + return TRUE; } #endif @@ -178,12 +182,13 @@ void __wxPreStart() wxPyTMutex = new wxMutex; #endif - // Bail out if there is already windows created. This means that the + // Bail out if there is already a wxApp created. This means that the // toolkit has already been initialized, as in embedding wxPython in - // a C++ wxWindows app. - if (wxTopLevelWindows.Number() > 0) + // a C++ wxWindows app, so we don't need to call wxEntryStart. + if (wxTheApp != NULL) { return; - + } + wxPyDoCleanup = TRUE; int argc = 0; char** argv = NULL; @@ -280,7 +285,8 @@ PyObject* __wxStart(PyObject* /* self */, PyObject* args) void __wxCleanup() { - wxEntryCleanup(); + if (wxPyDoCleanup) + wxEntryCleanup(); #ifdef WXP_WITH_THREAD delete wxPyTMutex; wxPyTMutex = NULL; @@ -524,8 +530,6 @@ PyObject* wxPyConstructObject(void* ptr, PyObject* wxPyConstructObject(void* ptr, const wxString& className, int setThisOwn) { - PyObject* obj; - if (!ptr) { Py_INCREF(Py_None); return Py_None; @@ -538,12 +542,10 @@ PyObject* wxPyConstructObject(void* ptr, PyObject* classobj = PyDict_GetItemString(wxPython_dict, buff); if (! classobj) { - char temp[128]; - sprintf(temp, - "*** Unknown class name %s, tell Robin about it please ***", - buff); - obj = PyString_FromString(temp); - return obj; + wxString msg(wxT("wxPython class not found for ")); + msg += className; + PyErr_SetString(PyExc_NameError, msg.mbc_str()); + return NULL; } return wxPyConstructObject(ptr, className, classobj, setThisOwn);