1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG definitions of the wxFileSystem family of classes
5 // Author: Joerg Baumann and Robin Dunn
7 // Created: 25-Sept-2000
9 // Copyright: (c) 2000 by Joerg Baumann
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
17 #include "pyistream.h"
18 #include <wx/stream.h>
22 //----------------------------------------------------------------------
25 %include my_typemaps.i
27 // Import some definitions of other classes, etc.
30 %pragma(python) code = "import wx"
32 //----------------------------------------------------------------------
33 // typemaps for wxInputStream
36 %typemap(python,in) wxInputStream * (wxPyInputStream* temp, bool created) {
37 if (SWIG_GetPtrObj($source, (void **) &temp, "_wxPyInputStream_p") == 0) {
38 $target = temp->m_wxis;
41 $target = wxPyCBInputStream_create($source, FALSE);
42 if ($target == NULL) {
43 PyErr_SetString(PyExc_TypeError,"Expected _wxInputStream_p or Python file-like object.");
50 %typemap(python, freearg) wxInputStream * {
56 // typemaps for wxInputStream
57 %typemap(python,out) wxInputStream* {
58 wxPyInputStream * _ptr = NULL;
61 _ptr = new wxPyInputStream($source);
63 $target = wxPyConstructObject(_ptr, wxT("wxInputStream"), TRUE);
66 //----------------------------------------------------------------------
69 // // wxStringPtrList* to python list of strings typemap
70 // %typemap(python, out) wxStringPtrList* {
72 // $target = PyList_New($source->GetCount());
73 // wxStringPtrList::Node *node = $source->GetFirst();
74 // for (int i=0; node; i++) {
75 // wxString *s = node->GetData();
77 // PyList_SetItem($target, i, PyUnicode_FromUnicode(s->c_str(), s->Len()));
79 // PyList_SetItem($target, i, PyString_FromStringAndSize(s->c_str(), s->Len()));
81 // node = node->GetNext();
99 %name(wxInputStream) class wxPyInputStream {
102 wxPyInputStream(PyObject* p) {
103 wxInputStream* wxis = wxPyCBInputStream::create(p);
105 return new wxPyInputStream(wxis);
113 PyObject* read(int size=-1);
114 PyObject* readline(int size=-1);
115 PyObject* readlines(int sizehint=-1);
116 void seek(int offset, int whence=0);
122 void truncate(int size=-1);
123 void write(wxString data);
124 void writelines(wxStringPtrList);
132 bool Ungetch(char c);
134 long SeekI(long pos, wxSeekMode mode = wxFromStart);
140 // TODO: make a more fully implemented file interface...
141 class wxOutputStream {
146 wxString* read(int size=-1);
147 wxString* readline(int size=-1);
148 wxStringPtrList* readlines(int sizehint=-1);
149 void seek(int offset, int whence=0);
153 void truncate(int size=-1);
154 void write(wxString data);
155 void writelines(wxStringPtrList);
159 void write(PyObject* obj) {
160 // We use only strings for the streams, not unicode
161 PyObject* str = PyObject_Str(obj);
163 PyErr_SetString(PyExc_TypeError, "Unable to convert to string");
166 self->Write(PyString_AS_STRING(str),
167 PyString_GET_SIZE(str));
174 // restore except and typemaps
175 %typemap(python,out) wxStringPtrList*;
176 %typemap(python,out) wxPyInputStream*;
179 //----------------------------------------------------------------------
182 wxPyPtrTypeMap_Add("wxInputStream", "wxPyInputStream");
185 //----------------------------------------------------------------------