#if defined(__WXGTK__) && PY_VERSION_HEX < 0x02040000
setlocale(LC_NUMERIC, "C");
#endif
#if defined(__WXGTK__) && PY_VERSION_HEX < 0x02040000
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);
// The stock objects were all NULL when they were loaded into
// SWIG generated proxies, so re-init those now...
wxPy_ReinitStockObjects(3);
wxPyNoAppError = PyErr_NewException("wx._core.PyNoAppError",
PyExc_RuntimeError, NULL);
PyDict_SetItemString(wxPython_dict, "PyNoAppError", wxPyNoAppError);
wxPyNoAppError = PyErr_NewException("wx._core.PyNoAppError",
PyExc_RuntimeError, NULL);
PyDict_SetItemString(wxPython_dict, "PyNoAppError", wxPyNoAppError);
#undef _AddInfoString
PyObject* PlatInfoTuple = PyList_AsTuple(PlatInfo);
Py_DECREF(PlatInfo);
PyDict_SetItemString(wxPython_dict, "PlatformInfo", PlatInfoTuple);
#undef _AddInfoString
PyObject* PlatInfoTuple = PyList_AsTuple(PlatInfo);
Py_DECREF(PlatInfo);
PyDict_SetItemString(wxPython_dict, "PlatformInfo", PlatInfoTuple);
if (pass == 1) { } \
else if (pass == 2) { rsoPass2(#name); } \
else if (pass == 3) { rsoPass3(#name, #classname, (void*)&name); }
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(wxNORMAL_FONT, wxFont);
REINITOBJ(wxSMALL_FONT, wxFont);
-
-void wxPyClientData_dtor(wxPyClientData* self) {
- if (! wxPyDoingCleanup) { // Don't do it during cleanup as Python
- // may have already garbage collected the object...
+void wxPyUserData_dtor(wxPyUserData* self) {
+ if (! wxPyDoingCleanup) {
-void wxPyUserData_dtor(wxPyUserData* self) {
- if (! wxPyDoingCleanup) {
- bool blocked = wxPyBeginBlockThreads();
- Py_DECREF(self->m_obj);
+
+void wxPyClientData_dtor(wxPyClientData* self) {
+ if (! wxPyDoingCleanup) { // Don't do it during cleanup as Python
+ // may have already garbage collected the object...
+ if (self->m_incRef) {
+ bool blocked = wxPyBeginBlockThreads();
+ Py_DECREF(self->m_obj);
+ wxPyEndBlockThreads(blocked);
+ }
// 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
// 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
- // Only if there is more than one reference to the object
- if ( !wxPyDoingCleanup && self->m_obj->ob_refcnt > 1 ) {
+ // Only if there is more than one reference to the object and we are
+ // holding the OOR reference:
+ if ( !wxPyDoingCleanup && self->m_obj->ob_refcnt > 1 && self->m_incRef) {
// bool isInstance = wxPyInstance_Check(self->m_obj);
// TODO same here
//wxASSERT_MSG(isInstance, wxT("m_obj not an instance!?!?!"));
// bool isInstance = wxPyInstance_Check(self->m_obj);
// TODO same here
//wxASSERT_MSG(isInstance, wxT("m_obj not an instance!?!?!"));
// (i.e. ActiveX controls) will (incorrectly IMHO) use a transient
// tstate which will then be garbage the next time we try to use
// it...
// (i.e. ActiveX controls) will (incorrectly IMHO) use a transient
// tstate which will then be garbage the next time we try to use
// it...
bool wxPyBeginBlockThreads() {
#ifdef WXP_WITH_THREAD
// This works in for 2.3, maybe a good alternative to find the needed tstate?
bool wxPyBeginBlockThreads() {
#ifdef WXP_WITH_THREAD
// This works in for 2.3, maybe a good alternative to find the needed tstate?
: wxInputStream(), m_read(r), m_seek(s), m_tell(t), m_block(block)
{}
: wxInputStream(), m_read(r), m_seek(s), m_tell(t), m_block(block)
{}
PyObject* wxPyCBInputStream::getMethod(PyObject* py, char* name) {
if (!PyObject_HasAttrString(py, name))
return NULL;
PyObject* wxPyCBInputStream::getMethod(PyObject* py, char* name) {
if (!PyObject_HasAttrString(py, name))
return NULL;
s_preName = PyString_FromString(wxPy_PRECALLINIT);
s_postName = PyString_FromString(wxPy_POSTCALLCLEANUP);
}
s_preName = PyString_FromString(wxPy_PRECALLINIT);
s_postName = PyString_FromString(wxPy_POSTCALLCLEANUP);
}
// Check if the event object needs some preinitialization
if (PyObject_HasAttr(arg, s_preName)) {
result = PyObject_CallMethodObjArgs(arg, s_preName, arg, NULL);
// Check if the event object needs some preinitialization
if (PyObject_HasAttr(arg, s_preName)) {
result = PyObject_CallMethodObjArgs(arg, s_preName, arg, NULL);
// Call the event handler, passing the event object
tuple = PyTuple_New(1);
PyTuple_SET_ITEM(tuple, 0, arg); // steals ref to arg
// Call the event handler, passing the event object
tuple = PyTuple_New(1);
PyTuple_SET_ITEM(tuple, 0, arg); // steals ref to arg
- if (!PyString_Check(source)) {
+ if (PyUnicode_Check(source)) {
+ str = PyUnicode_AsEncodedString(source, wxPyDefaultEncoding, "strict");
+ if (PyErr_Occurred()) return NULL;
+ }
+ else if (!PyString_Check(source)) {
str = PyObject_Str(source);
if (PyErr_Occurred()) return NULL;
}
char* tmpPtr; int tmpSize;
PyString_AsStringAndSize(str, &tmpPtr, &tmpSize);
target = new wxString(tmpPtr, tmpSize);
str = PyObject_Str(source);
if (PyErr_Occurred()) return NULL;
}
char* tmpPtr; int tmpSize;
PyString_AsStringAndSize(str, &tmpPtr, &tmpSize);
target = new wxString(tmpPtr, tmpSize);
// Convert to a unicode object, if not already, then to a wxString
PyObject* uni = source;
if (!PyUnicode_Check(source)) {
// Convert to a unicode object, if not already, then to a wxString
PyObject* uni = source;
if (!PyUnicode_Check(source)) {
size_t len = PyUnicode_GET_SIZE(uni);
if (len) {
PyUnicode_AsWideChar((PyUnicodeObject*)uni, target.GetWriteBuf(len), len);
target.UngetWriteBuf();
}
size_t len = PyUnicode_GET_SIZE(uni);
if (len) {
PyUnicode_AsWideChar((PyUnicodeObject*)uni, target.GetWriteBuf(len), len);
target.UngetWriteBuf();
}
if (!PyUnicode_Check(source))
Py_DECREF(uni);
#else
// Convert to a string object if it isn't already, then to wxString
PyObject* str = source;
if (!PyUnicode_Check(source))
Py_DECREF(uni);
#else
// Convert to a string object if it isn't already, then to wxString
PyObject* str = source;
- if (!PyString_Check(source)) {
+ if (PyUnicode_Check(source)) {
+ str = PyUnicode_AsEncodedString(source, wxPyDefaultEncoding, "strict");
+ if (PyErr_Occurred()) return wxEmptyString; // TODO: should we PyErr_Clear?
+ }
+ else if (!PyString_Check(source)) {
str = PyObject_Str(source);
if (PyErr_Occurred()) return wxEmptyString; // TODO: should we PyErr_Clear?
}
char* tmpPtr; int tmpSize;
PyString_AsStringAndSize(str, &tmpPtr, &tmpSize);
target = wxString(tmpPtr, tmpSize);
str = PyObject_Str(source);
if (PyErr_Occurred()) return wxEmptyString; // TODO: should we PyErr_Clear?
}
char* tmpPtr; int tmpSize;
PyString_AsStringAndSize(str, &tmpPtr, &tmpSize);
target = wxString(tmpPtr, tmpSize);
+
+void wxSetDefaultPyEncoding(const char* encoding)
+{
+ strncpy(wxPyDefaultEncoding, encoding, DEFAULTENCODING_SIZE);
+}
+
+const char* wxGetDefaultPyEncoding()
+{
+ return wxPyDefaultEncoding;
+}
+