]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/streams.i
implement wxColourDialog::Move() (patch 548048)
[wxWidgets.git] / wxPython / src / streams.i
CommitLineData
c368d904
RD
1/////////////////////////////////////////////////////////////////////////////
2// Name: streams.i
3// Purpose: SWIG definitions of the wxFileSystem family of classes
4//
cbf60e09 5// Author: Joerg Baumann and Robin Dunn
c368d904
RD
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"
cbf60e09 17#include "pyistream.h"
c368d904
RD
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
f74ff5ef
RD
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.");
c368d904
RD
45 return NULL;
46 }
f74ff5ef 47 created = TRUE;
c368d904
RD
48 }
49}
50
f74ff5ef
RD
51%typemap(python, freearg) wxInputStream * {
52 if (created)
53 delete $source;
54}
55
c368d904
RD
56
57// typemaps for wxInputStream
58%typemap(python,out) wxInputStream* {
59 wxPyInputStream * _ptr = NULL;
60
61 if ($source) {
62 _ptr = new wxPyInputStream($source);
63 }
9416aa89 64 $target = wxPyConstructObject(_ptr, "wxInputStream", TRUE);
c368d904
RD
65}
66
67//----------------------------------------------------------------------
68
c368d904 69
a541c325
RD
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// }
c368d904
RD
90
91
c368d904
RD
92
93
94%name(wxInputStream) class wxPyInputStream {
95public:
96 %addmethods {
97 wxPyInputStream(PyObject* p) {
f74ff5ef
RD
98 wxInputStream* wxis = wxPyCBInputStream::create(p);
99 if (wxis)
100 return new wxPyInputStream(wxis);
c368d904
RD
101 else
102 return NULL;
103 }
104 }
105 void close();
106 void flush();
107 bool eof();
a541c325
RD
108 PyObject* read(int size=-1);
109 PyObject* readline(int size=-1);
110 PyObject* readlines(int sizehint=-1);
c368d904
RD
111 void seek(int offset, int whence=0);
112 int tell();
f74ff5ef 113
c368d904
RD
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...
126class wxOutputStream {
127public:
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 {
a541c325
RD
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);
c368d904
RD
154 }
155 }
156};
157
158
159// restore except and typemaps
160%typemap(python,out) wxStringPtrList*;
161%typemap(python,out) wxPyInputStream*;
c368d904
RD
162
163
9416aa89
RD
164//----------------------------------------------------------------------
165
166%init %{
167 wxPyPtrTypeMap_Add("wxInputStream", "wxPyInputStream");
168%}
169
170//----------------------------------------------------------------------