]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_streams.i
Add ToggleWindowStyle
[wxWidgets.git] / wxPython / src / _streams.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: _streams.i
3 // Purpose: SWIG typemaps and wrappers for wxInputStream
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 25-Sept-2000
8 // RCS-ID: $Id$
9 // Copyright: (c) 2003 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 // Not a %module
14
15
16 //---------------------------------------------------------------------------
17
18 %{
19 #include "wx/wxPython/pyistream.h"
20 %}
21
22 //---------------------------------------------------------------------------
23 %newgroup
24
25
26 // Typemaps for wxInputStream
27 //
28 // We assume that input params taking a wxInputStream& will *not* take
29 // ownership of the stream and so we manage it in the typemaps. On the other
30 // hand, when a paramter expects a wxInputStream* then it does take ownership
31 // (such as wxFSFile) and so the typemap will make a copy of the stream object
32 // to give to it.
33
34 %typemap(in) wxInputStream& (wxPyInputStream* temp, bool created) {
35 if (wxPyConvertSwigPtr($input, (void **)&temp, wxT("wxPyInputStream"))) {
36 $1 = temp->m_wxis;
37 created = false;
38 } else {
39 PyErr_Clear(); // clear the failure of the wxPyConvert above
40 $1 = wxPyCBInputStream_create($input, false);
41 if ($1 == NULL) {
42 PyErr_SetString(PyExc_TypeError, "Expected wx.InputStream or Python file-like object.");
43 SWIG_fail;
44 }
45 created = true;
46 }
47 }
48 %typemap(freearg) wxInputStream& { if (created$argnum) delete $1; }
49
50
51 %typemap(in) wxInputStream* (wxPyInputStream* temp) {
52 if (wxPyConvertSwigPtr($input, (void **)&temp, wxT("wxPyInputStream"))) {
53 $1 = wxPyCBInputStream_copy((wxPyCBInputStream*)temp->m_wxis);
54 } else {
55 PyErr_Clear(); // clear the failure of the wxPyConvert above
56 $1 = wxPyCBInputStream_create($input, true);
57 if ($1 == NULL) {
58 PyErr_SetString(PyExc_TypeError, "Expected wx.InputStream or Python file-like object.");
59 SWIG_fail;
60 }
61 }
62 }
63
64
65
66 %typemap(out) wxInputStream* {
67 wxPyInputStream * _ptr = NULL;
68
69 if ($1) {
70 _ptr = new wxPyInputStream($1);
71 }
72 $result = wxPyConstructObject(_ptr, wxT("wxPyInputStream"), $owner);
73 }
74
75
76 //---------------------------------------------------------------------------
77
78 enum wxSeekMode
79 {
80 wxFromStart,
81 wxFromCurrent,
82 wxFromEnd
83 };
84
85
86 %rename(InputStream) wxPyInputStream;
87 class wxPyInputStream
88 {
89 public:
90 %extend {
91 wxPyInputStream(PyObject* p) {
92 wxInputStream* wxis = wxPyCBInputStream::create(p);
93 if (wxis)
94 return new wxPyInputStream(wxis);
95 else
96 return NULL;
97 }
98 }
99 ~wxPyInputStream();
100
101 void close();
102 void flush();
103 bool eof();
104 PyObject* read(int size=-1);
105 PyObject* readline(int size=-1);
106 PyObject* 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 char Peek();
119 char GetC();
120 size_t LastRead();
121 bool CanRead();
122 bool Eof();
123 bool Ungetch(char c);
124
125 long SeekI(long pos, wxSeekMode mode = wxFromStart);
126 long TellI();
127 };
128
129
130
131 // TODO: make a more fully implemented file interface...
132 class wxOutputStream {
133 public:
134 /*
135 void close();
136 void flush();
137 wxString* read(int size=-1);
138 wxString* readline(int size=-1);
139 wxStringPtrList* readlines(int sizehint=-1);
140 void seek(int offset, int whence=0);
141 int tell();
142 bool isatty();
143 int fileno();
144 void truncate(int size=-1);
145 void write(wxString data);
146 void writelines(wxStringPtrList);
147 */
148
149 %extend {
150 void write(PyObject* obj) {
151 // We use only strings for the streams, not unicode
152 PyObject* str = PyObject_Str(obj);
153 if (! str) {
154 PyErr_SetString(PyExc_TypeError, "Unable to convert to string");
155 return;
156 }
157 self->Write(PyString_AS_STRING(str),
158 PyString_GET_SIZE(str));
159 Py_DECREF(str);
160 }
161 }
162 size_t LastWrite() const;
163 };
164
165
166 //---------------------------------------------------------------------------
167 %init %{
168 wxPyPtrTypeMap_Add("wxInputStream", "wxPyInputStream");
169 %}
170 //---------------------------------------------------------------------------