]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/streams.i
Added VC++ project files for remaining Gizmo samples
[wxWidgets.git] / wxPython / src / streams.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: streams.i
3 // Purpose: SWIG definitions of the wxFileSystem family of classes
4 //
5 // Author: Joerg Baumann and Robin Dunn
6 //
7 // Created: 25-Sept-2000
8 // RCS-ID: $Id$
9 // Copyright: (c) 2000 by Joerg Baumann
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 %module streams
14
15 %{
16 #include "helpers.h"
17 #include "pyistream.h"
18 #include <wx/stream.h>
19 #include <wx/list.h>
20 %}
21
22 //----------------------------------------------------------------------
23
24 %include typemaps.i
25 %include my_typemaps.i
26
27 // Import some definitions of other classes, etc.
28 %import _defs.i
29
30 %pragma(python) code = "import wx"
31 %pragma(python) code = "import string"
32
33 //----------------------------------------------------------------------
34 // typemaps for wxInputStream
35
36
37 %typemap(python,in) wxInputStream * (wxPyInputStream* temp, bool created) {
38 if (SWIG_GetPtrObj($source, (void **) &temp, "_wxPyInputStream_p") == 0) {
39 $target = temp->m_wxis;
40 created = FALSE;
41 } else {
42 $target = wxPyCBInputStream::create($source, FALSE);
43 if ($target == NULL) {
44 PyErr_SetString(PyExc_TypeError,"Expected _wxInputStream_p or Python file-like object.");
45 return NULL;
46 }
47 created = TRUE;
48 }
49 }
50
51 %typemap(python, freearg) wxInputStream * {
52 if (created)
53 delete $source;
54 }
55
56
57 // typemaps for wxInputStream
58 %typemap(python,out) wxInputStream* {
59 wxPyInputStream * _ptr = NULL;
60
61 if ($source) {
62 _ptr = new wxPyInputStream($source);
63 }
64 $target = wxPyConstructObject(_ptr, "wxInputStream", TRUE);
65 }
66
67 //----------------------------------------------------------------------
68
69
70 // wxStringPtrList* to python list of strings typemap
71 %typemap(python, out) wxStringPtrList* {
72 if ($source) {
73 $target = PyList_New($source->GetCount());
74 wxStringPtrList::Node *node = $source->GetFirst();
75 for (int i=0; node; i++) {
76 wxString *s = node->GetData();
77 PyList_SetItem($target, i, PyString_FromStringAndSize(s->c_str(), s->Len()));
78 node = node->GetNext();
79 delete s;
80 }
81 delete $source;
82 }
83 else
84 $target=0;
85 }
86
87
88
89
90 %name(wxInputStream) class wxPyInputStream {
91 public:
92 %addmethods {
93 wxPyInputStream(PyObject* p) {
94 wxInputStream* wxis = wxPyCBInputStream::create(p);
95 if (wxis)
96 return new wxPyInputStream(wxis);
97 else
98 return NULL;
99 }
100 }
101 void close();
102 void flush();
103 bool eof();
104 wxString* read(int size=-1);
105 wxString* readline(int size=-1);
106 wxStringPtrList* readlines(int sizehint=-1);
107 void seek(int offset, int whence=0);
108 int tell();
109
110 /*
111 bool isatty();
112 int fileno();
113 void truncate(int size=-1);
114 void write(wxString data);
115 void writelines(wxStringPtrList);
116 */
117 }
118
119
120
121 // TODO: make a more fully implemented file interface...
122 class wxOutputStream {
123 public:
124 /*
125 void close();
126 void flush();
127 wxString* read(int size=-1);
128 wxString* readline(int size=-1);
129 wxStringPtrList* readlines(int sizehint=-1);
130 void seek(int offset, int whence=0);
131 int tell();
132 bool isatty();
133 int fileno();
134 void truncate(int size=-1);
135 void write(wxString data);
136 void writelines(wxStringPtrList);
137 */
138
139 %addmethods {
140 void write(const wxString& str) {
141 self->Write(str.c_str(), str.Length());
142 }
143 }
144 };
145
146
147 // restore except and typemaps
148 %typemap(python,out) wxStringPtrList*;
149 %typemap(python,out) wxPyInputStream*;
150
151
152 //----------------------------------------------------------------------
153
154 %init %{
155 wxPyPtrTypeMap_Add("wxInputStream", "wxPyInputStream");
156 %}
157
158 //----------------------------------------------------------------------