+ // Rebuild the .this swigified pointer with the new value of the C++ pointer
+ ptrobj = wxPyMakeSwigPtr(ptr, wxString(classname, *wxConvCurrent));
+ PyObject_SetAttrString(obj, "this", ptrobj);
+ Py_DECREF(ptrobj);
+}
+
+
+
+void wxPy_ReinitStockObjects(int pass)
+{
+
+#define REINITOBJ(name, classname) \
+ if (pass == 1) { name = (classname*)0xC0C0C0C0; } \
+ else if (pass == 2) { rsoPass2(#name); } \
+ else if (pass == 3) { rsoPass3(#name, #classname, (void*)name); }
+
+
+#define REINITOBJ2(name, classname) \
+ if (pass == 1) { } \
+ else if (pass == 2) { rsoPass2(#name); } \
+ else if (pass == 3) { rsoPass3(#name, #classname, (void*)&name); }
+
+
+ REINITOBJ(wxNORMAL_FONT, wxFont);
+ REINITOBJ(wxSMALL_FONT, wxFont);
+ REINITOBJ(wxITALIC_FONT, wxFont);
+ REINITOBJ(wxSWISS_FONT, wxFont);
+
+ REINITOBJ(wxRED_PEN, wxPen);
+ REINITOBJ(wxCYAN_PEN, wxPen);
+ REINITOBJ(wxGREEN_PEN, wxPen);
+ REINITOBJ(wxBLACK_PEN, wxPen);
+ REINITOBJ(wxWHITE_PEN, wxPen);
+ REINITOBJ(wxTRANSPARENT_PEN, wxPen);
+ REINITOBJ(wxBLACK_DASHED_PEN, wxPen);
+ REINITOBJ(wxGREY_PEN, wxPen);
+ REINITOBJ(wxMEDIUM_GREY_PEN, wxPen);
+ REINITOBJ(wxLIGHT_GREY_PEN, wxPen);
+
+ REINITOBJ(wxBLUE_BRUSH, wxBrush);
+ REINITOBJ(wxGREEN_BRUSH, wxBrush);
+ REINITOBJ(wxWHITE_BRUSH, wxBrush);
+ REINITOBJ(wxBLACK_BRUSH, wxBrush);
+ REINITOBJ(wxTRANSPARENT_BRUSH, wxBrush);
+ REINITOBJ(wxCYAN_BRUSH, wxBrush);
+ REINITOBJ(wxRED_BRUSH, wxBrush);
+ REINITOBJ(wxGREY_BRUSH, wxBrush);
+ REINITOBJ(wxMEDIUM_GREY_BRUSH, wxBrush);
+ REINITOBJ(wxLIGHT_GREY_BRUSH, wxBrush);
+
+ REINITOBJ(wxBLACK, wxColour);
+ REINITOBJ(wxWHITE, wxColour);
+ REINITOBJ(wxRED, wxColour);
+ REINITOBJ(wxBLUE, wxColour);
+ REINITOBJ(wxGREEN, wxColour);
+ REINITOBJ(wxCYAN, wxColour);
+ REINITOBJ(wxLIGHT_GREY, wxColour);
+
+ REINITOBJ(wxSTANDARD_CURSOR, wxCursor);
+ REINITOBJ(wxHOURGLASS_CURSOR, wxCursor);
+ REINITOBJ(wxCROSS_CURSOR, wxCursor);
+
+ REINITOBJ2(wxNullBitmap, wxBitmap);
+ REINITOBJ2(wxNullIcon, wxIcon);
+ REINITOBJ2(wxNullCursor, wxCursor);
+ REINITOBJ2(wxNullPen, wxPen);
+ REINITOBJ2(wxNullBrush, wxBrush);
+ REINITOBJ2(wxNullPalette, wxPalette);
+ REINITOBJ2(wxNullFont, wxFont);
+ REINITOBJ2(wxNullColour, wxColour);
+
+ REINITOBJ(wxTheFontList, wxFontList);
+ REINITOBJ(wxThePenList, wxPenList);
+ REINITOBJ(wxTheBrushList, wxBrushList);
+ REINITOBJ(wxTheColourDatabase, wxColourDatabase);
+
+
+ REINITOBJ(wxTheClipboard, wxClipboard);
+ REINITOBJ2(wxDefaultValidator, wxValidator);
+ REINITOBJ2(wxNullImage, wxImage);
+ REINITOBJ2(wxNullAcceleratorTable, wxAcceleratorTable);
+
+#undef REINITOBJ
+#undef REINITOBJ2
+}
+
+//---------------------------------------------------------------------------
+
+void wxPyClientData_dtor(wxPyClientData* self) {
+ if (! wxPyDoingCleanup) { // Don't do it during cleanup as Python
+ // may have already garbage collected the object...
+ wxPyBeginBlockThreads();
+ Py_DECREF(self->m_obj);
+ self->m_obj = NULL;
+ wxPyEndBlockThreads();
+ }
+}
+
+void wxPyUserData_dtor(wxPyUserData* self) {
+ if (! wxPyDoingCleanup) {
+ wxPyBeginBlockThreads();
+ Py_DECREF(self->m_obj);
+ self->m_obj = NULL;
+ wxPyEndBlockThreads();
+ }
+}
+
+
+// This is called when an OOR controled object is being destroyed. Although
+// the C++ object is going away there is no way to force the Python object
+// (and all references to it) to die too. This causes problems (crashes) in
+// wxPython when a python shadow object attempts to call a C++ method using
+// the now bogus pointer... So to try and prevent this we'll do a little black
+// magic and change the class of the python instance to a class that will
+// raise an exception for any attempt to call methods with it. See
+// _wxPyDeadObject in _core_ex.py for the implementation of this class.
+void wxPyOORClientData_dtor(wxPyOORClientData* self) {
+
+ static PyObject* deadObjectClass = NULL;
+
+ wxPyBeginBlockThreads();
+ if (deadObjectClass == NULL) {
+ deadObjectClass = PyDict_GetItemString(wxPython_dict, "_wxPyDeadObject");
+ // TODO: Can not wxASSERT here because inside a wxPyBeginBlock Threads,
+ // will lead to a deadlock when it tries to aquire the GIL again.
+ //wxASSERT_MSG(deadObjectClass != NULL, wxT("Can't get _wxPyDeadObject class!"));
+ Py_INCREF(deadObjectClass);
+ }
+
+
+ // Only if there is more than one reference to the object
+ if ( !wxPyDoingCleanup && self->m_obj->ob_refcnt > 1 ) {
+ // bool isInstance = wxPyInstance_Check(self->m_obj);
+ // TODO same here
+ //wxASSERT_MSG(isInstance, wxT("m_obj not an instance!?!?!"));
+
+ // Call __del__, if there is one.
+ PyObject* func = PyObject_GetAttrString(self->m_obj, "__del__");
+ if (func) {
+ PyObject* rv = PyObject_CallMethod(self->m_obj, "__del__", NULL);
+ Py_XDECREF(rv);
+ Py_DECREF(func);
+ }
+ if (PyErr_Occurred())
+ PyErr_Clear(); // just ignore it for now
+
+
+ PyObject* dict = PyObject_GetAttrString(self->m_obj, "__dict__");
+ if (dict) {
+ // Clear the instance's dictionary
+ PyDict_Clear(dict);
+
+ // put the name of the old class into the instance, and then reset the
+ // class to be the dead class.
+ PyObject* klass = PyObject_GetAttrString(self->m_obj, "__class__");
+ PyObject* name = PyObject_GetAttrString(klass, "__name__");
+ PyDict_SetItemString(dict, "_name", name);
+ PyObject_SetAttrString(self->m_obj, "__class__", deadObjectClass);
+ //Py_INCREF(deadObjectClass);
+ Py_DECREF(klass);
+ Py_DECREF(name);
+ }
+ }
+
+ // m_obj is DECREF'd in the base class dtor...
+ wxPyEndBlockThreads();