]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/streams.i
moved OnActivate() logic from wxFrame to wxDialog -- this fixes infinite loop when...
[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 // #if wxUSE_UNICODE
78 // PyList_SetItem($target, i, PyUnicode_FromUnicode(s->c_str(), s->Len()));
79 // #else
80 // PyList_SetItem($target, i, PyString_FromStringAndSize(s->c_str(), s->Len()));
81 // #endif
82 // node = node->GetNext();
83 // delete s;
84 // }
85 // delete $source;
86 // }
87 // else
88 // $target=0;
89 // }
90
91
92
93
94 %name(wxInputStream) class wxPyInputStream {
95 public:
96 %addmethods {
97 wxPyInputStream(PyObject* p) {
98 wxInputStream* wxis = wxPyCBInputStream::create(p);
99 if (wxis)
100 return new wxPyInputStream(wxis);
101 else
102 return NULL;
103 }
104 }
105 void close();
106 void flush();
107 bool eof();
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);
112 int tell();
113
114 /*
115 bool isatty();
116 int fileno();
117 void truncate(int size=-1);
118 void write(wxString data);
119 void writelines(wxStringPtrList);
120 */
121 }
122
123
124
125 // TODO: make a more fully implemented file interface...
126 class wxOutputStream {
127 public:
128 /*
129 void close();
130 void flush();
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);
135 int tell();
136 bool isatty();
137 int fileno();
138 void truncate(int size=-1);
139 void write(wxString data);
140 void writelines(wxStringPtrList);
141 */
142
143 %addmethods {
144 void write(PyObject* obj) {
145 // We use only strings for the streams, not unicode
146 PyObject* str = PyObject_Str(obj);
147 if (! str) {
148 PyErr_SetString(PyExc_TypeError, "Unable to convert to string");
149 return;
150 }
151 self->Write(PyString_AS_STRING(str),
152 PyString_GET_SIZE(str));
153 Py_DECREF(str);
154 }
155 }
156 };
157
158
159 // restore except and typemaps
160 %typemap(python,out) wxStringPtrList*;
161 %typemap(python,out) wxPyInputStream*;
162
163
164 //----------------------------------------------------------------------
165
166 %init %{
167 wxPyPtrTypeMap_Add("wxInputStream", "wxPyInputStream");
168 %}
169
170 //----------------------------------------------------------------------