X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/98bc3dcf46f3639269afe6f8cbe27a300f80fe8e..ad3fca675f77c2903cafd096bbda8baa2e7689ff:/wxPython/src/helpers.cpp?ds=sidebyside diff --git a/wxPython/src/helpers.cpp b/wxPython/src/helpers.cpp index 5629feac3e..edb5a91791 100644 --- a/wxPython/src/helpers.cpp +++ b/wxPython/src/helpers.cpp @@ -29,6 +29,7 @@ #include #include #define GetXWindow(wxwin) GDK_WINDOW_XWINDOW((wxwin)->m_widget->window) +#include #endif #ifdef __WXX11__ @@ -78,6 +79,7 @@ wxMutex* wxPyTMutex = NULL; static PyObject* wxPython_dict = NULL; static PyObject* wxPyAssertionError = NULL; +static PyObject* wxPyNoAppError = NULL; PyObject* wxPyPtrTypeMap = NULL; @@ -398,15 +400,28 @@ void wxPyApp::_BootstrapApp() } wxPyEndBlockThreads(blocked); + // Initialize wxWidgets result = wxEntryStart(argc, argv); delete [] argv; blocked = wxPyBeginBlockThreads(); if (! result) { - PyErr_SetString(PyExc_SystemError, "wxEntryStart failed!"); + PyErr_SetString(PyExc_SystemError, + "wxEntryStart failed, unable to initialize wxWidgets!" +#ifdef __WXGTK__ + " (Is DISPLAY set properly?)" +#endif + ); goto error; } + // On wxGTK the locale will be changed to match the system settings, but + // Python needs to have LC_NUMERIC set to "C" in order for the floating + // point conversions and such to work right. +#ifdef __WXGTK__ + setlocale(LC_NUMERIC, "C"); +#endif + // The stock objects were all NULL when they were loaded into // SWIG generated proxies, so re-init those now... wxPy_ReinitStockObjects(3); @@ -437,7 +452,6 @@ void wxPyApp::_BootstrapApp() result = True; } - if (! result) { PyErr_SetString(PyExc_SystemExit, "OnInit returned False, exiting..."); } @@ -498,8 +512,8 @@ inline const char* dropwx(const char* name) { //---------------------------------------------------------------------- -// This function is called when the wxc module is imported to do some initial -// setup. (Before there is a wxApp object.) The rest happens in +// This function is called when the wx._core_ module is imported to do some +// initial setup. (Before there is a wxApp object.) The rest happens in // wxPyApp::_BootstrapApp void __wxPyPreStart(PyObject* moduleDict) { @@ -523,6 +537,8 @@ void __wxPyPreStart(PyObject* moduleDict) // Init the stock objects to a non-NULL value so SWIG doesn't create them as None wxPy_ReinitStockObjects(1); + + wxInitAllImageHandlers(); } @@ -543,7 +559,7 @@ void __wxPyCleanup() { } -// Save a reference to the dictionary of the wx.core module, and inject +// Save a reference to the dictionary of the wx._core module, and inject // a few more things into it. PyObject* __wxPySetDictionary(PyObject* /* self */, PyObject* args) { @@ -552,7 +568,8 @@ PyObject* __wxPySetDictionary(PyObject* /* self */, PyObject* args) return NULL; if (!PyDict_Check(wxPython_dict)) { - PyErr_SetString(PyExc_TypeError, "_wxPySetDictionary must have dictionary object!"); + PyErr_SetString(PyExc_TypeError, + "_wxPySetDictionary must have dictionary object!"); return NULL; } @@ -561,10 +578,16 @@ PyObject* __wxPySetDictionary(PyObject* /* self */, PyObject* args) PyDict_SetItemString(wxPython_dict, "__wxPyPtrTypeMap", wxPyPtrTypeMap); // Create an exception object to use for wxASSERTions - wxPyAssertionError = PyErr_NewException("wx.core.PyAssertionError", + wxPyAssertionError = PyErr_NewException("wx._core.PyAssertionError", PyExc_AssertionError, NULL); PyDict_SetItemString(wxPython_dict, "PyAssertionError", wxPyAssertionError); + // Create an exception object to use when the app object hasn't been created yet + wxPyNoAppError = PyErr_NewException("wx._core.PyNoAppError", + PyExc_RuntimeError, NULL); + PyDict_SetItemString(wxPython_dict, "PyNoAppError", wxPyNoAppError); + + #ifdef __WXMOTIF__ #define wxPlatform "__WXMOTIF__" @@ -621,7 +644,12 @@ PyObject* __wxPySetDictionary(PyObject* /* self */, PyObject* args) _AddInfoString("gtk1"); #endif #endif - +#ifdef __WXDEBUG__ + _AddInfoString("wx-assertions-on"); +#else + _AddInfoString("wx-assertions-off"); +#endif + #undef _AddInfoString PyObject* PlatInfoTuple = PyList_AsTuple(PlatInfo); @@ -650,20 +678,20 @@ bool wxPySwigInstance_Check(PyObject* obj) { //--------------------------------------------------------------------------- -// The stock objects are no longer created when the wxc module is imported, -// but only after the app object has been created. The +// The stock objects are no longer created when the wx._core_ module is +// imported, but only after the app object has been created. The // wxPy_ReinitStockObjects function will be called 3 times to pass the stock // objects though various stages of evolution: // // pass 1: Set all the pointers to a non-NULL value so the Python proxy -// object will be created (otherwise it will just use None.) +// object will be created (otherwise SWIG will just use None.) // // pass 2: After the module has been imported and the python proxys have // been created, then set the __class__ to be _wxPyUnbornObject so // it will catch any access to the object and will raise an exception. // -// pass 3: Finally, from OnInit patch things up so the stock objects can -// be used. +// pass 3: Finally, from BootstrapApp patch things up so the stock objects +// can be used. PyObject* __wxPyFixStockObjects(PyObject* /* self */, PyObject* args) @@ -720,6 +748,17 @@ static void rsoPass3(const char* name, const char* classname, void* ptr) void wxPy_ReinitStockObjects(int pass) { + // If there is already an App object then wxPython is probably embedded in + // a wx C++ application, so there is no need to do all this. + static bool embedded = false; + if ((pass == 1 || pass == 2) && wxTheApp) { + embedded = true; + return; + } + if (pass == 3 && embedded) + return; + + #define REINITOBJ(name, classname) \ if (pass == 1) { name = (classname*)0xC0C0C0C0; } \ else if (pass == 2) { rsoPass2(#name); } \ @@ -730,17 +769,7 @@ void wxPy_ReinitStockObjects(int pass) if (pass == 1) { } \ else if (pass == 2) { rsoPass2(#name); } \ else if (pass == 3) { rsoPass3(#name, #classname, (void*)&name); } - - // If there is already an App object then wxPython is probably embedded in - // a wx C++ application, so there is no need to do all this. - static bool embedded = false; - if ((pass == 1 || pass == 2) && wxTheApp) { - embedded = true; - return; - } - if (pass == 3 && embedded) - return; - + REINITOBJ(wxNORMAL_FONT, wxFont); REINITOBJ(wxSMALL_FONT, wxFont); @@ -807,6 +836,22 @@ void wxPy_ReinitStockObjects(int pass) //--------------------------------------------------------------------------- +// Check for existence of a wxApp, setting an exception if there isn't one. +// This doesn't need to aquire the GIL because it should only be called from +// an %exception before the lock is released. + +bool wxPyCheckForApp() { + if (wxTheApp != NULL) + return true; + else { + PyErr_SetString(wxPyNoAppError, "The wx.App object must be created first!"); + return false; + } +} + +//--------------------------------------------------------------------------- + + void wxPyClientData_dtor(wxPyClientData* self) { if (! wxPyDoingCleanup) { // Don't do it during cleanup as Python // may have already garbage collected the object... @@ -1818,7 +1863,8 @@ long wxPyGetWinHandle(wxWindow* win) { #endif #ifdef __WXMAC__ - return (long)MAC_WXHWND(win->MacGetRootWindow()); + //return (long)MAC_WXHWND(win->MacGetTopLevelWindowRef()); + return (long)win->GetHandle(); #endif return 0;