]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/filesys.i
merged in the fix for printing \% on PS DC
[wxWidgets.git] / wxPython / src / filesys.i
CommitLineData
c368d904
RD
1/////////////////////////////////////////////////////////////////////////////
2// Name: filesys.i
3// Purpose: SWIG definitions of the wxFileSystem family of classes
4//
5// Author: Joerg Baumann
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 filesys
14
15%{
16#include "helpers.h"
17#include <wx/filesys.h>
18#include <wx/fs_inet.h>
19#include <wx/fs_mem.h>
20#include <wx/fs_zip.h>
21%}
22
23//----------------------------------------------------------------------
24
25%include typemaps.i
26%include my_typemaps.i
27
28// Import some definitions of other classes, etc.
29%import _defs.i
30%import utils.i
31%import image.i
32%import streams.i
33
34%pragma(python) code = "import wx"
35%pragma(python) code = "import string"
36
37//---------------------------------------------------------------------------
38
39// // typemaps for wxInputStream: Note wxFSFile object has to do the delete
40// // of wxInputStream *
41// %typemap(python,in) wxInputStream *stream {
42// if (PyInstance_Check($source)) {
43// wxPyInputStream* ptr;
44// if (SWIG_GetPtrObj($source, (void **) &ptr,"_wxPyInputStream_p")) {
45// PyErr_SetString(PyExc_TypeError,"Expected _wxInputStream_p.");
46// return NULL;
47// }
48// $target = ptr->wxi;
49// } else {
50// PyErr_SetString(PyExc_TypeError,"Expected _wxInputStream_p.");
51// return NULL;
52// }
53// }
54
55
56// // typemaps for wxInputStream: Note wxFSFile object has to do the delete
57// // of wxInputStream *
58// %typemap(python,out) wxInputStream* {
59// wxPyInputStream * _ptr = NULL;
60
61// if ($source) {
62// _ptr = new wxPyInputStream($source);
63// }
64// if (_ptr) {
65// char swigptr[64];
66// SWIG_MakePtr(swigptr, _ptr, "_wxPyInputStream_p");
67
68// PyObject* classobj = PyDict_GetItemString(wxPython_dict, "wxInputStreamPtr");
69// if (! classobj) {
70// Py_INCREF(Py_None);
71// $target = Py_None;
72// } else {
73// PyObject* arg = Py_BuildValue("(s)", swigptr);
74// $target = PyInstance_New(classobj, arg, NULL);
75// Py_DECREF(arg);
76
77// // set ThisOwn
78// PyObject_SetAttrString($target, "thisown", PyInt_FromLong(1));
79// }
80// } else {
81// Py_INCREF(Py_None);
82// $target = Py_None;
83// }
84// }
85
86
87
88class wxFSFile {
89public:
90 wxFSFile(wxInputStream *stream, const wxString& loc,
91 const wxString& mimetype, const wxString& anchor,
92 wxDateTime modif);
93
94 wxInputStream *GetStream();
95 const wxString& GetMimeType();
96 const wxString& GetLocation();
97 const wxString& GetAnchor();
98 wxDateTime GetModificationTime();
99};
100
101
102// clear typemaps
103%typemap(python,in) wxInputStream *stream;
104%typemap(python,out) wxInputStream *;
105
106
107//---------------------------------------------------------------------------
108
109%{
110// wxPyFileSystemHandler will be the Python class wxFileSystemHandler and handling
111// the callback functions
112class wxPyFileSystemHandler : public wxFileSystemHandler {
113public:
114 wxPyFileSystemHandler() : wxFileSystemHandler() {}
115
116 DEC_PYCALLBACK_BOOL_STRING_pure(CanOpen);
117 DEC_PYCALLBACK_FSF_FSSTRING_pure(OpenFile);
118 DEC_PYCALLBACK_STRING_STRINGINT_pure(FindFirst);
119 DEC_PYCALLBACK_STRING__pure(FindNext);
120
121 wxString GetProtocol(const wxString& location) {
122 return wxFileSystemHandler::GetProtocol(location);
123 }
124
125 wxString GetLeftLocation(const wxString& location) {
126 return wxFileSystemHandler::GetLeftLocation(location);
127 }
128
129 wxString GetAnchor(const wxString& location) {
130 return wxFileSystemHandler::GetAnchor(location);
131 }
132
133 wxString GetRightLocation(const wxString& location) {
134 return wxFileSystemHandler::GetRightLocation(location);
135 }
136
137 wxString GetMimeTypeFromExt(const wxString& location){
138 return wxFileSystemHandler::GetMimeTypeFromExt(location);
139 }
140
141 PYPRIVATE;
142};
143
144
145IMP_PYCALLBACK_BOOL_STRING_pure(wxPyFileSystemHandler, wxFileSystemHandler, CanOpen);
146IMP_PYCALLBACK_FSF_FSSTRING_pure(wxPyFileSystemHandler, wxFileSystemHandler, OpenFile);
147IMP_PYCALLBACK_STRING_STRINGINT_pure(wxPyFileSystemHandler, wxFileSystemHandler, FindFirst);
148IMP_PYCALLBACK_STRING__pure(wxPyFileSystemHandler, wxFileSystemHandler, FindNext);
149%}
150
151
152%name(wxCPPFileSystemHandler)class wxFileSystemHandler {
153 wxFileSystemHandler();
154}
155
156%name(wxFileSystemHandler)class wxPyFileSystemHandler : public wxFileSystemHandler {
157public:
158 wxPyFileSystemHandler();
159
160 void _setSelf(PyObject* self, PyObject* _class);
161 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxFileSystemHandler)"
162
163 bool CanOpen(const wxString& location);
164 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
165 wxString FindFirst(const wxString& spec, int flags = 0);
166 wxString FindNext();
167
168 wxString GetProtocol(const wxString& location);
169 wxString GetLeftLocation(const wxString& location);
170 wxString GetAnchor(const wxString& location);
171 wxString GetRightLocation(const wxString& location) const;
172 wxString GetMimeTypeFromExt(const wxString& location);
173};
174
175//---------------------------------------------------------------------------
176
177class wxFileSystem {
178public:
179 wxFileSystem();
180
181 void ChangePathTo(const wxString& location, bool is_dir = FALSE);
182 wxString GetPath();
183
184 wxFSFile* OpenFile(const wxString& location);
185
186 wxString FindFirst(const wxString& spec, int flags = 0);
187 wxString FindNext();
188
189 static void AddHandler(wxFileSystemHandler *handler);
190 static void CleanUpHandlers();
191};
192
193//---------------------------------------------------------------------------
194
195class wxInternetFSHandler : public wxFileSystemHandler {
196public:
197 wxInternetFSHandler();
198 bool CanOpen(const wxString& location);
199 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
200};
201
202
203//---------------------------------------------------------------------------
204class wxZipFSHandler : public wxFileSystemHandler {
205public:
206 wxZipFSHandler();
207
208 bool CanOpen(const wxString& location);
209 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
210 wxString FindFirst(const wxString& spec, int flags = 0);
211 wxString FindNext();
212};
213
214//---------------------------------------------------------------------------
215
216class wxMemoryFSHandler : public wxFileSystemHandler {
217public:
218 wxMemoryFSHandler();
219
220 // Remove file from memory FS and free occupied memory
221 static void RemoveFile(const wxString& filename);
222
223 bool CanOpen(const wxString& location);
224 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
225 wxString FindFirst(const wxString& spec, int flags = 0);
226 virtual wxString FindNext();
227};
228
229
230// getting the overloaded static AddFile method right
231%inline %{
232void __wxMemoryFSHandler_AddFile_wxImage(const wxString& filename,
233 wxImage& image,
234 long type) {
235 wxMemoryFSHandler::AddFile(filename, image, type);
236}
237
238void __wxMemoryFSHandler_AddFile_wxBitmap(const wxString& filename,
239 const wxBitmap& bitmap,
240 long type) {
241 wxMemoryFSHandler::AddFile(filename, bitmap, type);
242}
243
244// void __wxMemoryFSHandler_AddFile_wxString(const wxString& filename,
245// const wxString& textdata) {
246// wxMemoryFSHandler::AddFile(filename, textdata);
247// }
248
249void __wxMemoryFSHandler_AddFile_Data(const wxString& filename,
250 PyObject* data) {
251
252 wxMemoryFSHandler::AddFile(filename,
253 (void*)PyString_AsString(data),
254 (size_t)PyString_Size(data));
255}
256%}
257
258
259// case switch for overloading
260%pragma(python) code = "
261import types
262def wxMemoryFSHandler_AddFile(filename, a, b=''):
263 if isinstance(a, wxImage):
264 __wxMemoryFSHandler_AddFile_wxImage(filename, a, b)
265 elif isinstance(a, wxBitmap):
266 __wxMemoryFSHandler_AddFile_wxBitmap(filename, a, b)
267 elif type(a) == types.StringType:
268 #__wxMemoryFSHandler_AddFile_wxString(filename, a)
269 __wxMemoryFSHandler_AddFile_Data(filename, a)
270 else: raise TypeError, 'wxImage, wxBitmap or string expected'
271"
272
273
274//---------------------------------------------------------------------------