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