static PyObject* wxPython_dict = NULL;
static PyObject* wxPyAssertionError = NULL;
static PyObject* wxPyNoAppError = NULL;
static PyObject* wxPython_dict = NULL;
static PyObject* wxPyAssertionError = NULL;
static PyObject* wxPyNoAppError = NULL;
if (wxPyCBH_findCallback(m_myInst, "OnInitGui"))
rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("()"));
wxPyEndBlockThreads(blocked);
if (wxPyCBH_findCallback(m_myInst, "OnInitGui"))
rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("()"));
wxPyEndBlockThreads(blocked);
if (wxPyCBH_findCallback(m_myInst, "OnExit"))
rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("()"));
wxPyEndBlockThreads(blocked);
if (wxPyCBH_findCallback(m_myInst, "OnExit"))
rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("()"));
wxPyEndBlockThreads(blocked);
if ((found = wxPyCBH_findCallback(m_myInst, "OnAssert"))) {
PyObject* fso = wx2PyString(file);
PyObject* cso = wx2PyString(file);
if ((found = wxPyCBH_findCallback(m_myInst, "OnAssert"))) {
PyObject* fso = wx2PyString(file);
PyObject* cso = wx2PyString(file);
PyObject* s = wx2PyString(buf);
PyErr_SetObject(wxPyAssertionError, s);
Py_DECREF(s);
PyObject* s = wx2PyString(buf);
PyErr_SetObject(wxPyAssertionError, s);
Py_DECREF(s);
if (wxPyCBH_findCallback(m_myInst, "MacOpenFile")) {
PyObject* s = wx2PyString(fileName);
wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", s));
if (wxPyCBH_findCallback(m_myInst, "MacOpenFile")) {
PyObject* s = wx2PyString(fileName);
wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", s));
if (wxPyCBH_findCallback(m_myInst, "MacPrintFile")) {
PyObject* s = wx2PyString(fileName);
wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", s));
if (wxPyCBH_findCallback(m_myInst, "MacPrintFile")) {
PyObject* s = wx2PyString(fileName);
wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", s));
if (wxPyCBH_findCallback(m_myInst, "MacNewFile"))
wxPyCBH_callCallback(m_myInst, Py_BuildValue("()"));
wxPyEndBlockThreads(blocked);
if (wxPyCBH_findCallback(m_myInst, "MacNewFile"))
wxPyCBH_callCallback(m_myInst, Py_BuildValue("()"));
wxPyEndBlockThreads(blocked);
if (wxPyCBH_findCallback(m_myInst, "MacReopenApp"))
wxPyCBH_callCallback(m_myInst, Py_BuildValue("()"));
wxPyEndBlockThreads(blocked);
if (wxPyCBH_findCallback(m_myInst, "MacReopenApp"))
wxPyCBH_callCallback(m_myInst, Py_BuildValue("()"));
wxPyEndBlockThreads(blocked);
// Get any command-line args passed to this program from the sys module
int argc = 0;
char** argv = NULL;
blocked = wxPyBeginBlockThreads();
// Get any command-line args passed to this program from the sys module
int argc = 0;
char** argv = NULL;
blocked = wxPyBeginBlockThreads();
- for(x=0; x<argc; x++) {
- PyObject *pyArg = PyList_GetItem(sysargv, x);
+ for(x=1; x<argc; x++) {
+ PyObject *pyArg = PyList_GetItem(sysargv, x-1);
#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);
// Save the current (main) thread state in our array
PyThreadState* tstate = wxPyBeginAllowThreads();
wxPyEndAllowThreads(tstate);
// Save the current (main) thread state in our array
PyThreadState* tstate = wxPyBeginAllowThreads();
wxPyEndAllowThreads(tstate);
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...
- bool blocked = wxPyBeginBlockThreads();
+void wxPyUserData_dtor(wxPyUserData* self) {
+ if (! wxPyDoingCleanup) {
+ wxPyBlock_t blocked = wxPyBeginBlockThreads();
-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) {
+ wxPyBlock_t 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
if (deadObjectClass == NULL) {
deadObjectClass = PyDict_GetItemString(wxPython_dict, "_wxPyDeadObject");
// TODO: Can not wxASSERT here because inside a wxPyBeginBlock Threads,
if (deadObjectClass == NULL) {
deadObjectClass = PyDict_GetItemString(wxPython_dict, "_wxPyDeadObject");
// TODO: Can not wxASSERT here because inside a wxPyBeginBlock Threads,
- // 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...
PyThreadState* wxPyBeginAllowThreads() {
#ifdef WXP_WITH_THREAD
PyThreadState* saved = PyEval_SaveThread(); // Py_BEGIN_ALLOW_THREADS;
PyThreadState* wxPyBeginAllowThreads() {
#ifdef WXP_WITH_THREAD
PyThreadState* saved = PyEval_SaveThread(); // Py_BEGIN_ALLOW_THREADS;
// Calls from wxWindows back to Python code, or even any PyObject
// manipulations, PyDECREF's and etc. are wrapped in calls to these functions:
// Calls from wxWindows back to Python code, or even any PyObject
// manipulations, PyDECREF's and etc. are wrapped in calls to these functions:
PyThreadState *current = _PyThreadState_Current;
// Only block if there wasn't already a tstate, or if the current one is
// not the one we are wanting to change to. This should prevent deadlock
// if there are nested calls to wxPyBeginBlockThreads
PyThreadState *current = _PyThreadState_Current;
// Only block if there wasn't already a tstate, or if the current one is
// not the one we are wanting to change to. This should prevent deadlock
// if there are nested calls to wxPyBeginBlockThreads
wxPyThreadState* tstate = wxPyGetThreadState();
if (current != tstate->tstate) {
PyEval_RestoreThread(tstate->tstate);
wxPyThreadState* tstate = wxPyGetThreadState();
if (current != tstate->tstate) {
PyEval_RestoreThread(tstate->tstate);
// Only unblock if we blocked in the last call to wxPyBeginBlockThreads.
// The value of blocked passed in needs to be the same as that returned
// from wxPyBeginBlockThreads at the same nesting level.
// Only unblock if we blocked in the last call to wxPyBeginBlockThreads.
// The value of blocked passed in needs to be the same as that returned
// from wxPyBeginBlockThreads at the same nesting level.
PyErr_SetString(PyExc_IOError, "no valid C-wxInputStream");
wxPyEndBlockThreads(blocked);
return NULL;
PyErr_SetString(PyExc_IOError, "no valid C-wxInputStream");
wxPyEndBlockThreads(blocked);
return NULL;
wxStreamError err = m_wxis->GetLastError();
if (err != wxSTREAM_NO_ERROR && err != wxSTREAM_EOF) {
PyErr_SetString(PyExc_IOError,"IOError in wxInputStream");
wxStreamError err = m_wxis->GetLastError();
if (err != wxSTREAM_NO_ERROR && err != wxSTREAM_EOF) {
PyErr_SetString(PyExc_IOError,"IOError in wxInputStream");
PyErr_SetString(PyExc_IOError,"no valid C-wxInputStream");
wxPyEndBlockThreads(blocked);
return NULL;
PyErr_SetString(PyExc_IOError,"no valid C-wxInputStream");
wxPyEndBlockThreads(blocked);
return NULL;
wxStreamError err = m_wxis->GetLastError();
if (err != wxSTREAM_NO_ERROR && err != wxSTREAM_EOF) {
PyErr_SetString(PyExc_IOError,"IOError in wxInputStream");
wxStreamError err = m_wxis->GetLastError();
if (err != wxSTREAM_NO_ERROR && err != wxSTREAM_EOF) {
PyErr_SetString(PyExc_IOError,"IOError in wxInputStream");
PyErr_SetString(PyExc_IOError,"no valid C-wxInputStream");
wxPyEndBlockThreads(blocked);
return NULL;
}
// init list
PyErr_SetString(PyExc_IOError,"no valid C-wxInputStream");
wxPyEndBlockThreads(blocked);
return NULL;
}
// init list
for (i=0; (m_wxis->CanRead()) && ((sizehint < 0) || (i < sizehint));) {
PyObject* s = this->readline();
if (s == NULL) {
for (i=0; (m_wxis->CanRead()) && ((sizehint < 0) || (i < sizehint));) {
PyObject* s = this->readline();
if (s == NULL) {
PyList_Append(pylist, s);
i += PyString_Size(s);
wxPyEndBlockThreads(blocked);
PyList_Append(pylist, s);
i += PyString_Size(s);
wxPyEndBlockThreads(blocked);
Py_DECREF(pylist);
PyErr_SetString(PyExc_IOError,"IOError in wxInputStream");
wxPyEndBlockThreads(blocked);
Py_DECREF(pylist);
PyErr_SetString(PyExc_IOError,"IOError in wxInputStream");
wxPyEndBlockThreads(blocked);
: 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)
{}
if (block) blocked = wxPyBeginBlockThreads();
PyObject* read = getMethod(py, "read");
if (block) blocked = wxPyBeginBlockThreads();
PyObject* read = getMethod(py, "read");
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;
PyObject* arglist = Py_BuildValue("(i)", bufsize);
PyObject* result = PyEval_CallObject(m_read, arglist);
Py_DECREF(arglist);
PyObject* arglist = Py_BuildValue("(i)", bufsize);
PyObject* result = PyEval_CallObject(m_read, arglist);
Py_DECREF(arglist);
PyObject* arglist = Py_BuildValue("()");
PyObject* result = PyEval_CallObject(m_tell, arglist);
Py_DECREF(arglist);
PyObject* arglist = Py_BuildValue("()");
PyObject* result = PyEval_CallObject(m_tell, arglist);
Py_DECREF(arglist);
wxString className = event.GetClassInfo()->GetClassName();
// If the event is one of these types then pass the original
wxString className = event.GetClassInfo()->GetClassName();
// If the event is one of these types then pass the original
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 (m_cloned)
Py_DECREF(m_self);
wxPyEndBlockThreads(blocked);
}
void wxPyEvtSelfRef::SetSelf(PyObject* self, bool clone) {
if (m_cloned)
Py_DECREF(m_self);
wxPyEndBlockThreads(blocked);
}
void wxPyEvtSelfRef::SetSelf(PyObject* self, bool clone) {
- 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;
+}
+