X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f74ff5efa5604fcde3cc5ba9009cb015a6f388cf..b9ac87bc5cbe46227195e32c44e25831f8206e3c:/wxPython/src/streams.i?ds=inline diff --git a/wxPython/src/streams.i b/wxPython/src/streams.i index 4122cf2fce..8bf7f2156d 100644 --- a/wxPython/src/streams.i +++ b/wxPython/src/streams.i @@ -2,7 +2,7 @@ // Name: streams.i // Purpose: SWIG definitions of the wxFileSystem family of classes // -// Author: Joerg Baumann +// Author: Joerg Baumann and Robin Dunn // // Created: 25-Sept-2000 // RCS-ID: $Id$ @@ -14,6 +14,7 @@ %{ #include "helpers.h" +#include "pyistream.h" #include #include %} @@ -27,7 +28,6 @@ %import _defs.i %pragma(python) code = "import wx" -%pragma(python) code = "import string" //---------------------------------------------------------------------- // typemaps for wxInputStream @@ -38,7 +38,7 @@ $target = temp->m_wxis; created = FALSE; } else { - $target = wxPyCBInputStream::create($source, FALSE); + $target = wxPyCBInputStream_create($source, FALSE); if ($target == NULL) { PyErr_SetString(PyExc_TypeError,"Expected _wxInputStream_p or Python file-like object."); return NULL; @@ -60,29 +60,39 @@ if ($source) { _ptr = new wxPyInputStream($source); } - $target = wxPyConstructObject(_ptr, "wxInputStream", TRUE); + $target = wxPyConstructObject(_ptr, wxT("wxInputStream"), TRUE); } //---------------------------------------------------------------------- -// wxStringPtrList* to python list of strings typemap -%typemap(python, out) wxStringPtrList* { - if ($source) { - $target = PyList_New($source->GetCount()); - wxStringPtrList::Node *node = $source->GetFirst(); - for (int i=0; node; i++) { - wxString *s = node->GetData(); - PyList_SetItem($target, i, PyString_FromStringAndSize(s->c_str(), s->Len())); - node = node->GetNext(); - delete s; - } - delete $source; - } - else - $target=0; -} - +// // wxStringPtrList* to python list of strings typemap +// %typemap(python, out) wxStringPtrList* { +// if ($source) { +// $target = PyList_New($source->GetCount()); +// wxStringPtrList::Node *node = $source->GetFirst(); +// for (int i=0; node; i++) { +// wxString *s = node->GetData(); +// #if wxUSE_UNICODE +// PyList_SetItem($target, i, PyUnicode_FromUnicode(s->c_str(), s->Len())); +// #else +// PyList_SetItem($target, i, PyString_FromStringAndSize(s->c_str(), s->Len())); +// #endif +// node = node->GetNext(); +// delete s; +// } +// delete $source; +// } +// else +// $target=0; +// } + +enum wxSeekMode +{ + wxFromStart, + wxFromCurrent, + wxFromEnd +}; @@ -100,9 +110,9 @@ public: void close(); void flush(); bool eof(); - wxString* read(int size=-1); - wxString* readline(int size=-1); - wxStringPtrList* readlines(int sizehint=-1); + PyObject* read(int size=-1); + PyObject* readline(int size=-1); + PyObject* readlines(int sizehint=-1); void seek(int offset, int whence=0); int tell(); @@ -113,6 +123,16 @@ public: void write(wxString data); void writelines(wxStringPtrList); */ + + char Peek(); + char GetC(); + size_t LastRead(); + bool CanRead(); + bool Eof(); + bool Ungetch(char c); + + long SeekI(long pos, wxSeekMode mode = wxFromStart); + long TellI(); } @@ -136,8 +156,16 @@ public: */ %addmethods { - void write(const wxString& str) { - self->Write(str.c_str(), str.Length()); + void write(PyObject* obj) { + // We use only strings for the streams, not unicode + PyObject* str = PyObject_Str(obj); + if (! str) { + PyErr_SetString(PyExc_TypeError, "Unable to convert to string"); + return; + } + self->Write(PyString_AS_STRING(str), + PyString_GET_SIZE(str)); + Py_DECREF(str); } } };