%newgroup
-// typemaps for wxInputStream
-%typemap(in) wxInputStream* (wxPyInputStream* temp, bool created) {
+// Typemaps for wxInputStream
+//
+// We assume that input params taking a wxInputStream& will *not* take
+// ownership of the stream and so we manage it in the typemaps. On the other
+// hand, when a paramter expects a wxInputStream* then it does take ownership
+// (such as wxFSFile) and so the typemap will make a copy of the stream object
+// to give to it.
+
+%typemap(in) wxInputStream& (wxPyInputStream* temp, bool created) {
if (wxPyConvertSwigPtr($input, (void **)&temp, wxT("wxPyInputStream"))) {
$1 = temp->m_wxis;
created = false;
PyErr_Clear(); // clear the failure of the wxPyConvert above
$1 = wxPyCBInputStream_create($input, false);
if ($1 == NULL) {
- PyErr_SetString(PyExc_TypeError, "Expected wxInputStream or Python file-like object.");
+ PyErr_SetString(PyExc_TypeError, "Expected wx.InputStream or Python file-like object.");
SWIG_fail;
}
created = true;
}
}
-%typemap(freearg) wxInputStream* {
- if (created$argnum)
- delete $1;
-}
+%typemap(freearg) wxInputStream& { if (created$argnum) delete $1; }
+
+%typemap(in) wxInputStream* (wxPyInputStream* temp) {
+ if (wxPyConvertSwigPtr($input, (void **)&temp, wxT("wxPyInputStream"))) {
+ $1 = wxPyCBInputStream_copy((wxPyCBInputStream*)temp->m_wxis);
+ } else {
+ PyErr_Clear(); // clear the failure of the wxPyConvert above
+ $1 = wxPyCBInputStream_create($input, true);
+ if ($1 == NULL) {
+ PyErr_SetString(PyExc_TypeError, "Expected wx.InputStream or Python file-like object.");
+ SWIG_fail;
+ }
+ }
+}
-%typemap(in) wxInputStream& = wxInputStream*;
-%typemap(freearg) wxInputStream& = wxInputStream*;
%typemap(out) wxInputStream* {
PyObject* retval = NULL;
PyObject* pyint = NULL;
-
+
// Only initialize wxWidgets once
if (! haveInitialized) {
-
+
// Get any command-line args passed to this program from the sys module
int argc = 0;
char** argv = NULL;
#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);
wxPyEndBlockThreads(blocked);
haveInitialized = true;
}
-
+
// It's now ok to generate exceptions for assertion errors.
wxPythonApp->SetStartupComplete(true);
#ifdef __WXMSW__
// wxCrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF
// | _CRTDBG_CHECK_ALWAYS_DF
-// | _CRTDBG_DELAY_FREE_MEM_DF
+// | _CRTDBG_DELAY_FREE_MEM_DF
// );
#endif
wxPyNoAppError = PyErr_NewException("wx._core.PyNoAppError",
PyExc_RuntimeError, NULL);
PyDict_SetItemString(wxPython_dict, "PyNoAppError", wxPyNoAppError);
-
+
#ifdef __WXMOTIF__
#else
_AddInfoString("wx-assertions-off");
#endif
-
+
#undef _AddInfoString
PyObject* PlatInfoTuple = PyList_AsTuple(PlatInfo);
Py_DECREF(PlatInfo);
PyDict_SetItemString(wxPython_dict, "PlatformInfo", PlatInfoTuple);
-
+
RETURN_NONE();
}
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);
// (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;
}
bool wxPyBeginBlockThreads() {
#ifdef WXP_WITH_THREAD
// This works in for 2.3, maybe a good alternative to find the needed tstate?
- // PyThreadState *check = PyGILState_GetThisThreadState();
+ // PyThreadState *check = PyGILState_GetThisThreadState();
PyThreadState *current = _PyThreadState_Current;
bool blocked = wxPyBeginBlockThreads();
pylist = PyList_New(0);
wxPyEndBlockThreads(blocked);
-
+
if (!pylist) {
bool blocked = wxPyBeginBlockThreads();
PyErr_NoMemory();
: wxInputStream(), m_read(r), m_seek(s), m_tell(t), m_block(block)
{}
+wxPyCBInputStream::wxPyCBInputStream(const wxPyCBInputStream& other)
+{
+ m_read = other.m_read;
+ m_seek = other.m_seek;
+ m_tell = other.m_tell;
+ m_block = other.m_block;
+ Py_INCREF(m_read);
+ Py_INCREF(m_seek);
+ Py_INCREF(m_tell);
+}
+
wxPyCBInputStream::~wxPyCBInputStream() {
bool blocked=false;
return wxPyCBInputStream::create(py, block);
}
+wxPyCBInputStream* wxPyCBInputStream_copy(wxPyCBInputStream* other) {
+ return new wxPyCBInputStream(*other);
+}
+
PyObject* wxPyCBInputStream::getMethod(PyObject* py, char* name) {
if (!PyObject_HasAttrString(py, name))
return NULL;
PyTuple_SET_ITEM(arglist, 1, PyInt_FromLong(mode));
-
+
PyObject* result = PyEval_CallObject(m_seek, arglist);
Py_DECREF(arglist);
Py_XDECREF(result);
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);
PyErr_Clear(); // Just in case...
} else {
PyErr_Print();
- }
+ }
}
-
+
// Call the event handler, passing the event object
tuple = PyTuple_New(1);
PyTuple_SET_ITEM(tuple, 0, arg); // steals ref to arg
PyErr_Clear(); // Just in case...
} else {
PyErr_Print();
- }
+ }
}
if ( checkSkip ) {
#if defined(__WXGTK__) || defined(__WXX11)
return (long)GetXWindow(win);
#endif
-
+
#ifdef __WXMAC__
//return (long)MAC_WXHWND(win->MacGetTopLevelWindowRef());
return (long)win->GetHandle();
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);
-
+
if (!PyString_Check(source))
Py_DECREF(str);
#endif // wxUSE_UNICODE
-
+
return target;
}
if (!PyUnicode_Check(source)) {
uni = PyUnicode_FromEncodedObject(source, wxPyDefaultEncoding, "strict");
if (PyErr_Occurred()) return wxEmptyString; // TODO: should we PyErr_Clear?
- }
+ }
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
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);
-
+
if (!PyString_Check(source))
Py_DECREF(str);
#endif // wxUSE_UNICODE