]>
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 RD |
29 | %pythonAppend wxFSFile |
30 | "self.thisown = 0 # It will normally be deleted by the user of the wxFileSystem"; | |
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 | |
d14a1e28 RD |
91 | %name(CPPFileSystemHandler) class wxFileSystemHandler //: public wxObject |
92 | { | |
93 | public: | |
94 | //wxFileSystemHandler(); | |
95 | }; | |
96 | ||
97 | ||
98 | ||
99 | %name(FileSystemHandler) class wxPyFileSystemHandler : public wxFileSystemHandler | |
100 | { | |
c368d904 | 101 | public: |
2b9048c5 | 102 | %pythonAppend wxPyFileSystemHandler "self._setCallbackInfo(self, FileSystemHandler)"; |
d14a1e28 | 103 | |
c368d904 RD |
104 | wxPyFileSystemHandler(); |
105 | ||
0122b7e3 | 106 | void _setCallbackInfo(PyObject* self, PyObject* _class); |
c368d904 RD |
107 | |
108 | bool CanOpen(const wxString& location); | |
b87bfdb7 | 109 | %newobject OpenFile; |
c368d904 RD |
110 | wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location); |
111 | wxString FindFirst(const wxString& spec, int flags = 0); | |
112 | wxString FindNext(); | |
113 | ||
114 | wxString GetProtocol(const wxString& location); | |
115 | wxString GetLeftLocation(const wxString& location); | |
116 | wxString GetAnchor(const wxString& location); | |
d14a1e28 | 117 | wxString GetRightLocation(const wxString& location); |
c368d904 RD |
118 | wxString GetMimeTypeFromExt(const wxString& location); |
119 | }; | |
120 | ||
d14a1e28 RD |
121 | |
122 | // //--------------------------------------------------------------------------- | |
123 | ||
c368d904 | 124 | |
9416aa89 | 125 | class wxFileSystem : public wxObject { |
c368d904 RD |
126 | public: |
127 | wxFileSystem(); | |
d14a1e28 | 128 | ~wxFileSystem(); |
c368d904 | 129 | |
dd9f7fea | 130 | void ChangePathTo(const wxString& location, bool is_dir = False); |
c368d904 RD |
131 | wxString GetPath(); |
132 | ||
b87bfdb7 | 133 | %newobject OpenFile; |
c368d904 RD |
134 | wxFSFile* OpenFile(const wxString& location); |
135 | ||
136 | wxString FindFirst(const wxString& spec, int flags = 0); | |
137 | wxString FindNext(); | |
138 | ||
139 | static void AddHandler(wxFileSystemHandler *handler); | |
140 | static void CleanUpHandlers(); | |
1e4a197e | 141 | |
dd116e73 RD |
142 | // Returns the file URL for a native path |
143 | static wxString FileNameToURL(const wxString& filename); | |
1e4a197e | 144 | |
dd116e73 RD |
145 | // Returns the native path for a file URL |
146 | //static wxFileName URLToFileName(const wxString& url); *** See below | |
c368d904 RD |
147 | }; |
148 | ||
dd116e73 RD |
149 | |
150 | // Returns the native path for a file URL | |
151 | wxString wxFileSystem_URLToFileName(const wxString& url); | |
152 | %{ | |
153 | wxString wxFileSystem_URLToFileName(const wxString& url) { | |
154 | wxFileName fname = wxFileSystem::URLToFileName(url); | |
155 | return fname.GetFullPath(); | |
156 | } | |
157 | %} | |
158 | ||
d14a1e28 | 159 | |
c368d904 RD |
160 | //--------------------------------------------------------------------------- |
161 | ||
162 | class wxInternetFSHandler : public wxFileSystemHandler { | |
163 | public: | |
164 | wxInternetFSHandler(); | |
165 | bool CanOpen(const wxString& location); | |
b87bfdb7 | 166 | %newobject OpenFile; |
c368d904 RD |
167 | wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location); |
168 | }; | |
169 | ||
170 | ||
171 | //--------------------------------------------------------------------------- | |
d14a1e28 | 172 | |
c368d904 RD |
173 | class wxZipFSHandler : public wxFileSystemHandler { |
174 | public: | |
175 | wxZipFSHandler(); | |
176 | ||
177 | bool CanOpen(const wxString& location); | |
b87bfdb7 | 178 | %newobject OpenFile; |
c368d904 RD |
179 | wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location); |
180 | wxString FindFirst(const wxString& spec, int flags = 0); | |
181 | wxString FindNext(); | |
182 | }; | |
183 | ||
184 | //--------------------------------------------------------------------------- | |
185 | ||
d14a1e28 | 186 | // TODO: Use SWIG's overloading feature to fix this mess? |
c368d904 RD |
187 | |
188 | // getting the overloaded static AddFile method right | |
189 | %inline %{ | |
d14a1e28 RD |
190 | void __wxMemoryFSHandler_AddFile_wxImage(const wxString& filename, |
191 | wxImage& image, | |
192 | long type) { | |
193 | wxMemoryFSHandler::AddFile(filename, image, type); | |
194 | } | |
c368d904 | 195 | |
d14a1e28 RD |
196 | void __wxMemoryFSHandler_AddFile_wxBitmap(const wxString& filename, |
197 | const wxBitmap& bitmap, | |
198 | long type) { | |
199 | wxMemoryFSHandler::AddFile(filename, bitmap, type); | |
200 | } | |
c368d904 | 201 | |
d14a1e28 RD |
202 | void __wxMemoryFSHandler_AddFile_Data(const wxString& filename, |
203 | PyObject* data) { | |
204 | wxMemoryFSHandler::AddFile(filename, | |
205 | // TODO: Verify data type | |
206 | (void*)PyString_AsString(data), | |
207 | (size_t)PyString_Size(data)); | |
208 | } | |
c368d904 RD |
209 | %} |
210 | ||
211 | ||
212 | // case switch for overloading | |
d14a1e28 RD |
213 | %pythoncode { |
214 | def MemoryFSHandler_AddFile(filename, a, b=''): | |
215 | if isinstance(a, wx.Image): | |
c368d904 | 216 | __wxMemoryFSHandler_AddFile_wxImage(filename, a, b) |
d14a1e28 | 217 | elif isinstance(a, wx.Bitmap): |
c368d904 | 218 | __wxMemoryFSHandler_AddFile_wxBitmap(filename, a, b) |
d14a1e28 | 219 | elif type(a) == str: |
c368d904 | 220 | __wxMemoryFSHandler_AddFile_Data(filename, a) |
d14a1e28 RD |
221 | else: raise TypeError, 'wx.Image, wx.Bitmap or string expected' |
222 | } | |
c368d904 RD |
223 | |
224 | ||
d14a1e28 RD |
225 | class wxMemoryFSHandler : public wxFileSystemHandler { |
226 | public: | |
227 | wxMemoryFSHandler(); | |
228 | ||
229 | // Remove file from memory FS and free occupied memory | |
230 | static void RemoveFile(const wxString& filename); | |
231 | ||
232 | // Add a file to the memory FS | |
233 | %pythoncode { AddFile = staticmethod(MemoryFSHandler_AddFile) } | |
234 | ||
235 | bool CanOpen(const wxString& location); | |
b87bfdb7 | 236 | %newobject OpenFile; |
d14a1e28 RD |
237 | wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location); |
238 | wxString FindFirst(const wxString& spec, int flags = 0); | |
239 | virtual wxString FindNext(); | |
240 | }; | |
9416aa89 | 241 | |
d14a1e28 RD |
242 | |
243 | //--------------------------------------------------------------------------- | |
9416aa89 RD |
244 | %init %{ |
245 | wxPyPtrTypeMap_Add("wxFileSystemHandler", "wxPyFileSystemHandler"); | |
246 | %} | |
c368d904 | 247 | //--------------------------------------------------------------------------- |