]>
Commit | Line | Data |
---|---|---|
c368d904 | 1 | ///////////////////////////////////////////////////////////////////////////// |
d14a1e28 | 2 | // Name: _filesys.i |
c368d904 RD |
3 | // Purpose: SWIG definitions of the wxFileSystem family of classes |
4 | // | |
d14a1e28 | 5 | // Author: Robin Dunn |
c368d904 RD |
6 | // |
7 | // Created: 25-Sept-2000 | |
8 | // RCS-ID: $Id$ | |
d14a1e28 | 9 | // Copyright: (c) 2003 by Total Control Software |
c368d904 RD |
10 | // Licence: wxWindows license |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
d14a1e28 | 13 | // Not a %module |
c368d904 | 14 | |
c368d904 | 15 | |
d14a1e28 | 16 | //--------------------------------------------------------------------------- |
c368d904 | 17 | |
d14a1e28 RD |
18 | %{ |
19 | #include "wx/wxPython/pyistream.h" | |
20 | %} | |
c368d904 RD |
21 | |
22 | //--------------------------------------------------------------------------- | |
d14a1e28 | 23 | %newgroup |
c368d904 | 24 | |
c368d904 | 25 | |
d14a1e28 RD |
26 | class wxFSFile : public wxObject |
27 | { | |
c368d904 | 28 | public: |
b87bfdb7 | 29 | %pythonAppend wxFSFile |
d02ea46c RD |
30 | "self.thisown = 0 # It will normally be deleted by the user of the wx.FileSystem"; |
31 | ||
c368d904 RD |
32 | wxFSFile(wxInputStream *stream, const wxString& loc, |
33 | const wxString& mimetype, const wxString& anchor, | |
34 | wxDateTime modif); | |
b87bfdb7 RD |
35 | |
36 | ~wxFSFile(); | |
c368d904 RD |
37 | |
38 | wxInputStream *GetStream(); | |
39 | const wxString& GetMimeType(); | |
40 | const wxString& GetLocation(); | |
41 | const wxString& GetAnchor(); | |
42 | wxDateTime GetModificationTime(); | |
43 | }; | |
44 | ||
45 | ||
c368d904 RD |
46 | //--------------------------------------------------------------------------- |
47 | ||
48 | %{ | |
d14a1e28 RD |
49 | class wxPyFileSystemHandler : public wxFileSystemHandler |
50 | { | |
c368d904 RD |
51 | public: |
52 | wxPyFileSystemHandler() : wxFileSystemHandler() {} | |
53 | ||
54 | DEC_PYCALLBACK_BOOL_STRING_pure(CanOpen); | |
55 | DEC_PYCALLBACK_FSF_FSSTRING_pure(OpenFile); | |
56 | DEC_PYCALLBACK_STRING_STRINGINT_pure(FindFirst); | |
57 | DEC_PYCALLBACK_STRING__pure(FindNext); | |
58 | ||
59 | wxString GetProtocol(const wxString& location) { | |
60 | return wxFileSystemHandler::GetProtocol(location); | |
61 | } | |
62 | ||
63 | wxString GetLeftLocation(const wxString& location) { | |
64 | return wxFileSystemHandler::GetLeftLocation(location); | |
65 | } | |
66 | ||
67 | wxString GetAnchor(const wxString& location) { | |
68 | return wxFileSystemHandler::GetAnchor(location); | |
69 | } | |
70 | ||
71 | wxString GetRightLocation(const wxString& location) { | |
72 | return wxFileSystemHandler::GetRightLocation(location); | |
73 | } | |
74 | ||
e9159fe8 | 75 | wxString GetMimeTypeFromExt(const wxString& location) { |
c368d904 RD |
76 | return wxFileSystemHandler::GetMimeTypeFromExt(location); |
77 | } | |
78 | ||
79 | PYPRIVATE; | |
80 | }; | |
81 | ||
82 | ||
83 | IMP_PYCALLBACK_BOOL_STRING_pure(wxPyFileSystemHandler, wxFileSystemHandler, CanOpen); | |
84 | IMP_PYCALLBACK_FSF_FSSTRING_pure(wxPyFileSystemHandler, wxFileSystemHandler, OpenFile); | |
85 | IMP_PYCALLBACK_STRING_STRINGINT_pure(wxPyFileSystemHandler, wxFileSystemHandler, FindFirst); | |
86 | IMP_PYCALLBACK_STRING__pure(wxPyFileSystemHandler, wxFileSystemHandler, FindNext); | |
87 | %} | |
88 | ||
89 | ||
c368d904 | 90 | |
1b8c7ba6 RD |
91 | %rename(CPPFileSystemHandler) wxFileSystemHandler; |
92 | class wxFileSystemHandler //: public wxObject | |
d14a1e28 RD |
93 | { |
94 | public: | |
95 | //wxFileSystemHandler(); | |
cdd7b180 | 96 | ~wxFileSystemHandler(); |
d14a1e28 RD |
97 | }; |
98 | ||
99 | ||
100 | ||
1b8c7ba6 RD |
101 | %rename(FileSystemHandler) wxPyFileSystemHandler; |
102 | class wxPyFileSystemHandler : public wxFileSystemHandler | |
d14a1e28 | 103 | { |
c368d904 | 104 | public: |
2b9048c5 | 105 | %pythonAppend wxPyFileSystemHandler "self._setCallbackInfo(self, FileSystemHandler)"; |
d14a1e28 | 106 | |
c368d904 RD |
107 | wxPyFileSystemHandler(); |
108 | ||
0122b7e3 | 109 | void _setCallbackInfo(PyObject* self, PyObject* _class); |
c368d904 RD |
110 | |
111 | bool CanOpen(const wxString& location); | |
b87bfdb7 | 112 | %newobject OpenFile; |
c368d904 RD |
113 | wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location); |
114 | wxString FindFirst(const wxString& spec, int flags = 0); | |
115 | wxString FindNext(); | |
116 | ||
117 | wxString GetProtocol(const wxString& location); | |
118 | wxString GetLeftLocation(const wxString& location); | |
119 | wxString GetAnchor(const wxString& location); | |
d14a1e28 | 120 | wxString GetRightLocation(const wxString& location); |
c368d904 RD |
121 | wxString GetMimeTypeFromExt(const wxString& location); |
122 | }; | |
123 | ||
d14a1e28 RD |
124 | |
125 | // //--------------------------------------------------------------------------- | |
126 | ||
c368d904 | 127 | |
9416aa89 | 128 | class wxFileSystem : public wxObject { |
c368d904 RD |
129 | public: |
130 | wxFileSystem(); | |
d14a1e28 | 131 | ~wxFileSystem(); |
c368d904 | 132 | |
a72f4631 | 133 | void ChangePathTo(const wxString& location, bool is_dir = false); |
c368d904 RD |
134 | wxString GetPath(); |
135 | ||
b87bfdb7 | 136 | %newobject OpenFile; |
c368d904 RD |
137 | wxFSFile* OpenFile(const wxString& location); |
138 | ||
139 | wxString FindFirst(const wxString& spec, int flags = 0); | |
140 | wxString FindNext(); | |
141 | ||
cdd7b180 | 142 | %disownarg(wxFileSystemHandler *handler); |
c368d904 | 143 | static void AddHandler(wxFileSystemHandler *handler); |
cdd7b180 RD |
144 | %cleardisown(wxFileSystemHandler *handler); |
145 | ||
c368d904 | 146 | static void CleanUpHandlers(); |
1e4a197e | 147 | |
dd116e73 RD |
148 | // Returns the file URL for a native path |
149 | static wxString FileNameToURL(const wxString& filename); | |
1e4a197e | 150 | |
dd116e73 | 151 | // Returns the native path for a file URL |
7e6581d4 RD |
152 | //static wxFileName URLToFileName(const wxString& url); |
153 | %extend { | |
154 | static wxString URLToFileName(const wxString& url) { | |
155 | wxFileName fname = wxFileSystem::URLToFileName(url); | |
156 | return fname.GetFullPath(); | |
157 | } | |
158 | } | |
c368d904 RD |
159 | }; |
160 | ||
dd116e73 | 161 | |
d14a1e28 | 162 | |
c368d904 RD |
163 | //--------------------------------------------------------------------------- |
164 | ||
165 | class wxInternetFSHandler : public wxFileSystemHandler { | |
166 | public: | |
167 | wxInternetFSHandler(); | |
168 | bool CanOpen(const wxString& location); | |
b87bfdb7 | 169 | %newobject OpenFile; |
c368d904 RD |
170 | wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location); |
171 | }; | |
172 | ||
173 | ||
174 | //--------------------------------------------------------------------------- | |
d14a1e28 | 175 | |
c368d904 RD |
176 | class wxZipFSHandler : public wxFileSystemHandler { |
177 | public: | |
178 | wxZipFSHandler(); | |
179 | ||
180 | bool CanOpen(const wxString& location); | |
b87bfdb7 | 181 | %newobject OpenFile; |
c368d904 RD |
182 | wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location); |
183 | wxString FindFirst(const wxString& spec, int flags = 0); | |
184 | wxString FindNext(); | |
185 | }; | |
186 | ||
187 | //--------------------------------------------------------------------------- | |
188 | ||
d14a1e28 | 189 | // TODO: Use SWIG's overloading feature to fix this mess? |
c368d904 RD |
190 | |
191 | // getting the overloaded static AddFile method right | |
192 | %inline %{ | |
d14a1e28 RD |
193 | void __wxMemoryFSHandler_AddFile_wxImage(const wxString& filename, |
194 | wxImage& image, | |
195 | long type) { | |
196 | wxMemoryFSHandler::AddFile(filename, image, type); | |
197 | } | |
c368d904 | 198 | |
d14a1e28 RD |
199 | void __wxMemoryFSHandler_AddFile_wxBitmap(const wxString& filename, |
200 | const wxBitmap& bitmap, | |
201 | long type) { | |
202 | wxMemoryFSHandler::AddFile(filename, bitmap, type); | |
203 | } | |
c368d904 | 204 | |
d14a1e28 RD |
205 | void __wxMemoryFSHandler_AddFile_Data(const wxString& filename, |
206 | PyObject* data) { | |
7e6581d4 RD |
207 | if (! PyString_Check(data)) { |
208 | wxPyBLOCK_THREADS(PyErr_SetString(PyExc_TypeError, | |
209 | "Expected string object")); | |
210 | return; | |
211 | } | |
212 | ||
6e6b3557 | 213 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); |
7e6581d4 RD |
214 | void* ptr = (void*)PyString_AsString(data); |
215 | size_t size = PyString_Size(data); | |
216 | wxPyEndBlockThreads(blocked); | |
217 | ||
218 | wxMemoryFSHandler::AddFile(filename, ptr, size); | |
d14a1e28 | 219 | } |
c368d904 RD |
220 | %} |
221 | ||
222 | ||
223 | // case switch for overloading | |
d14a1e28 | 224 | %pythoncode { |
7e6581d4 RD |
225 | def MemoryFSHandler_AddFile(filename, dataItem, imgType=-1): |
226 | """ | |
227 | Add 'file' to the memory filesystem. The dataItem parameter can | |
228 | either be a `wx.Bitmap`, `wx.Image` or a string that can contain | |
229 | arbitrary data. If a bitmap or image is used then the imgType | |
230 | parameter should specify what kind of image file it should be | |
231 | written as, wx.BITMAP_TYPE_PNG, etc. | |
232 | """ | |
233 | if isinstance(dataItem, wx.Image): | |
234 | __wxMemoryFSHandler_AddFile_wxImage(filename, dataItem, imgType) | |
235 | elif isinstance(dataItem, wx.Bitmap): | |
236 | __wxMemoryFSHandler_AddFile_wxBitmap(filename, dataItem, imgType) | |
237 | elif type(dataItem) == str: | |
238 | __wxMemoryFSHandler_AddFile_Data(filename, dataItem) | |
239 | else: | |
240 | raise TypeError, 'wx.Image, wx.Bitmap or string expected' | |
d14a1e28 | 241 | } |
c368d904 RD |
242 | |
243 | ||
d14a1e28 RD |
244 | class wxMemoryFSHandler : public wxFileSystemHandler { |
245 | public: | |
246 | wxMemoryFSHandler(); | |
247 | ||
248 | // Remove file from memory FS and free occupied memory | |
249 | static void RemoveFile(const wxString& filename); | |
250 | ||
251 | // Add a file to the memory FS | |
252 | %pythoncode { AddFile = staticmethod(MemoryFSHandler_AddFile) } | |
253 | ||
254 | bool CanOpen(const wxString& location); | |
b87bfdb7 | 255 | %newobject OpenFile; |
d14a1e28 RD |
256 | wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location); |
257 | wxString FindFirst(const wxString& spec, int flags = 0); | |
258 | virtual wxString FindNext(); | |
259 | }; | |
9416aa89 | 260 | |
d14a1e28 RD |
261 | |
262 | //--------------------------------------------------------------------------- | |
9416aa89 RD |
263 | %init %{ |
264 | wxPyPtrTypeMap_Add("wxFileSystemHandler", "wxPyFileSystemHandler"); | |
265 | %} | |
c368d904 | 266 | //--------------------------------------------------------------------------- |