X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4acff284f9516e2a4f0fcfa7bcfa3f497b8005cc..fd512ba2864a4ddf82ef70caf7a5b107d34906c8:/wxPython/src/helpers.cpp diff --git a/wxPython/src/helpers.cpp b/wxPython/src/helpers.cpp index c3c52d2a6e..e317a426be 100644 --- a/wxPython/src/helpers.cpp +++ b/wxPython/src/helpers.cpp @@ -10,7 +10,6 @@ // Licence: wxWindows license ///////////////////////////////////////////////////////////////////////////// -#include // get the correct definition of NULL #undef DEBUG #include @@ -29,7 +28,6 @@ #include #endif - //---------------------------------------------------------------------- #if PYTHON_API_VERSION <= 1007 && wxUSE_UNICODE @@ -47,6 +45,7 @@ int WXDLLEXPORT wxEntryInitGui(); void WXDLLEXPORT wxEntryCleanup(); wxPyApp* wxPythonApp = NULL; // Global instance of application object +bool wxPyDoCleanup = FALSE; #ifdef WXP_WITH_THREAD @@ -79,8 +78,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 @@ -90,11 +92,10 @@ BOOL WINAPI DllMain( wxPyApp::wxPyApp() { -// printf("**** ctor\n"); + SetUseBestVisual(TRUE); } wxPyApp::~wxPyApp() { -// printf("**** dtor\n"); } @@ -114,6 +115,10 @@ int wxPyApp::MainLoop() { #endif if (initialized) { + if ( m_exitOnFrameDelete == Later ) { + m_exitOnFrameDelete = Yes; + } + retval = wxApp::MainLoop(); OnExit(); } @@ -178,12 +183,15 @@ void __wxPreStart() wxPyTMutex = new wxMutex; #endif - // Bail out if there is already windows created. This means that the + wxApp::CheckBuildOptions(wxBuildOptions()); + + // 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; @@ -209,7 +217,6 @@ void __wxPreStart() } - // Start the user application, user App's OnInit method is a parameter here PyObject* __wxStart(PyObject* /* self */, PyObject* args) { @@ -221,13 +228,6 @@ PyObject* __wxStart(PyObject* /* self */, PyObject* args) if (!PyArg_ParseTuple(args, "O", &onInitFunc)) return NULL; -#if 0 // Try it out without this check, see how it does... - if (wxTopLevelWindows.Number() > 0) { - PyErr_SetString(PyExc_TypeError, "Only 1 wxApp per process!"); - return NULL; - } -#endif - // This is the next part of the wxEntry functionality... int argc = 0; wxChar** argv = NULL; @@ -280,7 +280,8 @@ PyObject* __wxStart(PyObject* /* self */, PyObject* args) void __wxCleanup() { - wxEntryCleanup(); + if (wxPyDoCleanup) + wxEntryCleanup(); #ifdef WXP_WITH_THREAD delete wxPyTMutex; wxPyTMutex = NULL; @@ -328,8 +329,15 @@ PyObject* __wxSetDictionary(PyObject* /* self */, PyObject* args) #define wxPlatform "__WXMAC__" #endif +#ifdef __WXDEBUG__ + int wxdebug = 1; +#else + int wxdebug = 0; +#endif + PyDict_SetItemString(wxPython_dict, "wxPlatform", PyString_FromString(wxPlatform)); PyDict_SetItemString(wxPython_dict, "wxUSE_UNICODE", PyInt_FromLong(wxUSE_UNICODE)); + PyDict_SetItemString(wxPython_dict, "__WXDEBUG__", PyInt_FromLong(wxdebug)); Py_INCREF(Py_None); return Py_None; @@ -524,8 +532,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 +544,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); @@ -592,7 +596,15 @@ void wxPySaveThreadState(PyThreadState* tstate) { for(size_t i=0; i < wxPyTStates->GetCount(); i++) { wxPyThreadState& info = wxPyTStates->Item(i); if (info.tid == ctid) { - info.tstate = tstate; +#if 0 + if (info.tstate != tstate) + wxLogMessage("*** tstate mismatch!???"); +#endif + // info.tstate = tstate; *** DO NOT update existing ones??? + // Normally it will never change, but apparently COM callbacks + // (i.e. ActiveX controls) will (incorrectly IMHO) use a transient + // tstate which will then be garbage the next time we try to use + // it... wxPyTMutex->Unlock(); return; } @@ -639,8 +651,9 @@ void wxPyBeginBlockThreads() { void wxPyEndBlockThreads() { #ifdef WXP_WITH_THREAD - PyThreadState* tstate = PyEval_SaveThread(); // Is there any need to save it again? + // PyThreadState* tstate = + PyEval_SaveThread(); #endif } @@ -823,6 +836,11 @@ wxPyCBInputStream* wxPyCBInputStream::create(PyObject *py, bool block) { return new wxPyCBInputStream(read, seek, tell, block); } + +wxPyCBInputStream* wxPyCBInputStream_create(PyObject *py, bool block) { + return wxPyCBInputStream::create(py, block); +} + PyObject* wxPyCBInputStream::getMethod(PyObject* py, char* name) { if (!PyObject_HasAttrString(py, name)) return NULL;