]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_filesys.i
Updating with Vadim's API changes.
[wxWidgets.git] / wxPython / src / _filesys.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: _filesys.i
3 // Purpose: SWIG definitions of the wxFileSystem family of classes
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 class wxFSFile : public wxObject
27 {
28 public:
29 %typemap(out) wxFSFile*; // turn off this typemap
30
31 wxFSFile(wxInputStream *stream, const wxString& loc,
32 const wxString& mimetype, const wxString& anchor,
33 wxDateTime modif);
34
35 // Turn it back on.
36 %typemap(out) wxFSFile* { $result = wxPyMake_wxObject($1, $owner); }
37
38 ~wxFSFile();
39
40 wxInputStream *GetStream();
41 void DetachStream();
42
43 const wxString& GetMimeType();
44 const wxString& GetLocation();
45 const wxString& GetAnchor();
46 wxDateTime GetModificationTime();
47
48 %property(Anchor, GetAnchor, doc="See `GetAnchor`");
49 %property(Location, GetLocation, doc="See `GetLocation`");
50 %property(MimeType, GetMimeType, doc="See `GetMimeType`");
51 %property(ModificationTime, GetModificationTime, doc="See `GetModificationTime`");
52 %property(Stream, GetStream, doc="See `GetStream`");
53
54 };
55
56
57 //---------------------------------------------------------------------------
58
59 %{
60 class wxPyFileSystemHandler : public wxFileSystemHandler
61 {
62 public:
63 wxPyFileSystemHandler() : wxFileSystemHandler() {}
64
65 DEC_PYCALLBACK_BOOL_STRING_pure(CanOpen);
66 DEC_PYCALLBACK_FSF_FSSTRING_pure(OpenFile);
67 DEC_PYCALLBACK_STRING_STRINGINT_pure(FindFirst);
68 DEC_PYCALLBACK_STRING__pure(FindNext);
69
70 wxString GetProtocol(const wxString& location) {
71 return wxFileSystemHandler::GetProtocol(location);
72 }
73
74 wxString GetLeftLocation(const wxString& location) {
75 return wxFileSystemHandler::GetLeftLocation(location);
76 }
77
78 wxString GetAnchor(const wxString& location) {
79 return wxFileSystemHandler::GetAnchor(location);
80 }
81
82 wxString GetRightLocation(const wxString& location) {
83 return wxFileSystemHandler::GetRightLocation(location);
84 }
85
86 wxString GetMimeTypeFromExt(const wxString& location) {
87 return wxFileSystemHandler::GetMimeTypeFromExt(location);
88 }
89
90 PYPRIVATE;
91 };
92
93
94 IMP_PYCALLBACK_BOOL_STRING_pure(wxPyFileSystemHandler, wxFileSystemHandler, CanOpen);
95 IMP_PYCALLBACK_FSF_FSSTRING_pure(wxPyFileSystemHandler, wxFileSystemHandler, OpenFile);
96 IMP_PYCALLBACK_STRING_STRINGINT_pure(wxPyFileSystemHandler, wxFileSystemHandler, FindFirst);
97 IMP_PYCALLBACK_STRING__pure(wxPyFileSystemHandler, wxFileSystemHandler, FindNext);
98 %}
99
100
101
102 %rename(CPPFileSystemHandler) wxFileSystemHandler;
103 class wxFileSystemHandler //: public wxObject
104 {
105 public:
106 //wxFileSystemHandler();
107 ~wxFileSystemHandler();
108 };
109
110
111
112 %rename(FileSystemHandler) wxPyFileSystemHandler;
113 class wxPyFileSystemHandler : public wxFileSystemHandler
114 {
115 public:
116 %pythonAppend wxPyFileSystemHandler setCallbackInfo(FileSystemHandler)
117
118 wxPyFileSystemHandler();
119
120 void _setCallbackInfo(PyObject* self, PyObject* _class);
121
122 bool CanOpen(const wxString& location);
123 %newobject OpenFile;
124 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
125 wxString FindFirst(const wxString& spec, int flags = 0);
126 wxString FindNext();
127
128 wxString GetProtocol(const wxString& location);
129 wxString GetLeftLocation(const wxString& location);
130 wxString GetAnchor(const wxString& location);
131 wxString GetRightLocation(const wxString& location);
132 wxString GetMimeTypeFromExt(const wxString& location);
133
134 %property(Anchor, GetAnchor, doc="See `GetAnchor`");
135 %property(LeftLocation, GetLeftLocation, doc="See `GetLeftLocation`");
136 %property(MimeTypeFromExt, GetMimeTypeFromExt, doc="See `GetMimeTypeFromExt`");
137 %property(Protocol, GetProtocol, doc="See `GetProtocol`");
138 %property(RightLocation, GetRightLocation, doc="See `GetRightLocation`");
139 };
140
141
142 // //---------------------------------------------------------------------------
143
144
145 class wxFileSystem : public wxObject {
146 public:
147 // turn off this typemap
148 %typemap(out) wxFileSystem*;
149
150 wxFileSystem();
151 ~wxFileSystem();
152
153 // Turn it back on again
154 %typemap(out) wxFileSystem* { $result = wxPyMake_wxObject($1, $owner); }
155
156 void ChangePathTo(const wxString& location, bool is_dir = false);
157 wxString GetPath();
158
159 %newobject OpenFile;
160 wxFSFile* OpenFile(const wxString& location);
161
162 wxString FindFirst(const wxString& spec, int flags = 0);
163 wxString FindNext();
164
165 %disownarg(wxFileSystemHandler *handler);
166 static void AddHandler(wxFileSystemHandler *handler);
167 %cleardisown(wxFileSystemHandler *handler);
168
169 // Removes FS handler
170 %newobject RemoveHandler;
171 static wxFileSystemHandler* RemoveHandler(wxFileSystemHandler *handler);
172
173 static void CleanUpHandlers();
174
175 // Returns the file URL for a native path
176 static wxString FileNameToURL(const wxString& filename);
177
178 // Returns the native path for a file URL
179 //static wxFileName URLToFileName(const wxString& url);
180 %extend {
181 static wxString URLToFileName(const wxString& url) {
182 wxFileName fname = wxFileSystem::URLToFileName(url);
183 return fname.GetFullPath();
184 }
185 }
186
187 %property(Path, GetPath, doc="See `GetPath`");
188 };
189
190
191
192 //---------------------------------------------------------------------------
193
194 class wxInternetFSHandler : public wxFileSystemHandler {
195 public:
196 wxInternetFSHandler();
197 bool CanOpen(const wxString& location);
198 %newobject OpenFile;
199 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
200 };
201
202
203 //---------------------------------------------------------------------------
204
205 class wxZipFSHandler : public wxFileSystemHandler {
206 public:
207 wxZipFSHandler();
208
209 bool CanOpen(const wxString& location);
210 %newobject OpenFile;
211 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
212 wxString FindFirst(const wxString& spec, int flags = 0);
213 wxString FindNext();
214 };
215
216 //---------------------------------------------------------------------------
217
218 // TODO: Use SWIG's overloading feature to fix this mess?
219
220 // getting the overloaded static AddFile method right
221 %inline %{
222 void __wxMemoryFSHandler_AddFile_wxImage(const wxString& filename,
223 wxImage& image,
224 long type) {
225 wxMemoryFSHandler::AddFile(filename, image, type);
226 }
227
228 void __wxMemoryFSHandler_AddFile_wxBitmap(const wxString& filename,
229 const wxBitmap& bitmap,
230 long type) {
231 wxMemoryFSHandler::AddFile(filename, bitmap, type);
232 }
233
234 void __wxMemoryFSHandler_AddFile_Data(const wxString& filename,
235 PyObject* data) {
236 if (! PyString_Check(data)) {
237 wxPyBLOCK_THREADS(PyErr_SetString(PyExc_TypeError,
238 "Expected string object"));
239 return;
240 }
241
242 wxPyBlock_t blocked = wxPyBeginBlockThreads();
243 void* ptr = (void*)PyString_AsString(data);
244 size_t size = PyString_Size(data);
245 wxPyEndBlockThreads(blocked);
246
247 wxMemoryFSHandler::AddFile(filename, ptr, size);
248 }
249 %}
250
251
252 // case switch for overloading
253 %pythoncode {
254 def MemoryFSHandler_AddFile(filename, dataItem, imgType=-1):
255 """
256 Add 'file' to the memory filesystem. The dataItem parameter can
257 either be a `wx.Bitmap`, `wx.Image` or a string that can contain
258 arbitrary data. If a bitmap or image is used then the imgType
259 parameter should specify what kind of image file it should be
260 written as, wx.BITMAP_TYPE_PNG, etc.
261 """
262 if isinstance(dataItem, wx.Image):
263 __wxMemoryFSHandler_AddFile_wxImage(filename, dataItem, imgType)
264 elif isinstance(dataItem, wx.Bitmap):
265 __wxMemoryFSHandler_AddFile_wxBitmap(filename, dataItem, imgType)
266 elif type(dataItem) == str:
267 __wxMemoryFSHandler_AddFile_Data(filename, dataItem)
268 else:
269 raise TypeError, 'wx.Image, wx.Bitmap or string expected'
270 }
271
272
273 class wxMemoryFSHandler : public wxFileSystemHandler {
274 public:
275 wxMemoryFSHandler();
276
277 // Remove file from memory FS and free occupied memory
278 static void RemoveFile(const wxString& filename);
279
280 // Add a file to the memory FS
281 %pythoncode { AddFile = staticmethod(MemoryFSHandler_AddFile) }
282
283 bool CanOpen(const wxString& location);
284 %newobject OpenFile;
285 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
286 wxString FindFirst(const wxString& spec, int flags = 0);
287 virtual wxString FindNext();
288 };
289
290
291 //---------------------------------------------------------------------------
292 %init %{
293 wxPyPtrTypeMap_Add("wxFileSystemHandler", "wxPyFileSystemHandler");
294 %}
295 //---------------------------------------------------------------------------