]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_streams.i
wxGridBahSizer support
[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 %typemap(in) wxInputStream* (wxPyInputStream* temp, bool created) {
28 if (wxPyConvertSwigPtr($input, (void **)&temp, wxT("wxPyInputStream"))) {
29 $1 = temp->m_wxis;
30 created = False;
31 } else {
32 PyErr_Clear(); // clear the failure of the wxPyConvert above
33 $1 = wxPyCBInputStream_create($input, False);
34 if ($1 == NULL) {
35 PyErr_SetString(PyExc_TypeError, "Expected wxInputStream or Python file-like object.");
36 SWIG_fail;
37 }
38 created = True;
39 }
40 }
41 %typemap(freearg) wxInputStream* {
42 if (created$argnum)
43 delete $1;
44 }
45
46
47 %typemap(in) wxInputStream& = wxInputStream*;
48 %typemap(freearg) wxInputStream& = wxInputStream*;
49
50
51 %typemap(out) wxInputStream* {
52 wxPyInputStream * _ptr = NULL;
53
54 if ($1) {
55 _ptr = new wxPyInputStream($1);
56 }
57 $result = wxPyConstructObject(_ptr, wxT("wxPyInputStream"), True);
58 }
59
60
61 //---------------------------------------------------------------------------
62
63 enum wxSeekMode
64 {
65 wxFromStart,
66 wxFromCurrent,
67 wxFromEnd
68 };
69
70
71 %name(InputStream) class wxPyInputStream {
72 public:
73 %extend {
74 wxPyInputStream(PyObject* p) {
75 wxInputStream* wxis = wxPyCBInputStream::create(p);
76 if (wxis)
77 return new wxPyInputStream(wxis);
78 else
79 return NULL;
80 }
81 }
82
83 void close();
84 void flush();
85 bool eof();
86 PyObject* read(int size=-1);
87 PyObject* readline(int size=-1);
88 PyObject* readlines(int sizehint=-1);
89 void seek(int offset, int whence=0);
90 int tell();
91
92 /*
93 bool isatty();
94 int fileno();
95 void truncate(int size=-1);
96 void write(wxString data);
97 void writelines(wxStringPtrList);
98 */
99
100 char Peek();
101 char GetC();
102 size_t LastRead();
103 bool CanRead();
104 bool Eof();
105 bool Ungetch(char c);
106
107 long SeekI(long pos, wxSeekMode mode = wxFromStart);
108 long TellI();
109 };
110
111
112
113 // TODO: make a more fully implemented file interface...
114 class wxOutputStream {
115 public:
116 /*
117 void close();
118 void flush();
119 wxString* read(int size=-1);
120 wxString* readline(int size=-1);
121 wxStringPtrList* readlines(int sizehint=-1);
122 void seek(int offset, int whence=0);
123 int tell();
124 bool isatty();
125 int fileno();
126 void truncate(int size=-1);
127 void write(wxString data);
128 void writelines(wxStringPtrList);
129 */
130
131 %extend {
132 void write(PyObject* obj) {
133 // We use only strings for the streams, not unicode
134 PyObject* str = PyObject_Str(obj);
135 if (! str) {
136 PyErr_SetString(PyExc_TypeError, "Unable to convert to string");
137 return;
138 }
139 self->Write(PyString_AS_STRING(str),
140 PyString_GET_SIZE(str));
141 Py_DECREF(str);
142 }
143 }
144 };
145
146
147 //---------------------------------------------------------------------------
148 %init %{
149 wxPyPtrTypeMap_Add("wxInputStream", "wxPyInputStream");
150 %}
151 //---------------------------------------------------------------------------