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"
31 %pragma(python) code = "import string"
33 //----------------------------------------------------------------------
34 // typemaps for wxInputStream
37 %typemap(python,in) wxInputStream * (wxPyInputStream* temp, bool created) {
38 if (SWIG_GetPtrObj($source, (void **) &temp, "_wxPyInputStream_p") == 0) {
39 $target = temp->m_wxis;
42 $target = wxPyCBInputStream_create($source, FALSE);
43 if ($target == NULL) {
44 PyErr_SetString(PyExc_TypeError,"Expected _wxInputStream_p or Python file-like object.");
51 %typemap(python, freearg) wxInputStream * {
57 // typemaps for wxInputStream
58 %typemap(python,out) wxInputStream* {
59 wxPyInputStream * _ptr = NULL;
62 _ptr = new wxPyInputStream($source);
64 $target = wxPyConstructObject(_ptr, "wxInputStream", TRUE);
67 //----------------------------------------------------------------------
70 // // wxStringPtrList* to python list of strings typemap
71 // %typemap(python, out) wxStringPtrList* {
73 // $target = PyList_New($source->GetCount());
74 // wxStringPtrList::Node *node = $source->GetFirst();
75 // for (int i=0; node; i++) {
76 // wxString *s = node->GetData();
78 // PyList_SetItem($target, i, PyUnicode_FromUnicode(s->c_str(), s->Len()));
80 // PyList_SetItem($target, i, PyString_FromStringAndSize(s->c_str(), s->Len()));
82 // node = node->GetNext();
94 %name(wxInputStream) class wxPyInputStream {
97 wxPyInputStream(PyObject* p) {
98 wxInputStream* wxis = wxPyCBInputStream::create(p);
100 return new wxPyInputStream(wxis);
108 PyObject* read(int size=-1);
109 PyObject* readline(int size=-1);
110 PyObject* readlines(int sizehint=-1);
111 void seek(int offset, int whence=0);
117 void truncate(int size=-1);
118 void write(wxString data);
119 void writelines(wxStringPtrList);
125 // TODO: make a more fully implemented file interface...
126 class wxOutputStream {
131 wxString* read(int size=-1);
132 wxString* readline(int size=-1);
133 wxStringPtrList* readlines(int sizehint=-1);
134 void seek(int offset, int whence=0);
138 void truncate(int size=-1);
139 void write(wxString data);
140 void writelines(wxStringPtrList);
144 void write(PyObject* obj) {
145 // We use only strings for the streams, not unicode
146 PyObject* str = PyObject_Str(obj);
148 PyErr_SetString(PyExc_TypeError, "Unable to convert to string");
151 self->Write(PyString_AS_STRING(str),
152 PyString_GET_SIZE(str));
159 // restore except and typemaps
160 %typemap(python,out) wxStringPtrList*;
161 %typemap(python,out) wxPyInputStream*;
164 //----------------------------------------------------------------------
167 wxPyPtrTypeMap_Add("wxInputStream", "wxPyInputStream");
170 //----------------------------------------------------------------------