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