]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: filesys.i | |
3 | // Purpose: SWIG definitions of the wxFileSystem family of classes | |
4 | // | |
5 | // Author: Joerg Baumann and Robin Dunn | |
6 | // | |
7 | // Created: 25-Sept-2000 | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) 2000 by Joerg Baumann | |
10 | // Licence: wxWindows license | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | %module filesys | |
14 | ||
15 | %{ | |
16 | #include "helpers.h" | |
17 | #include "pyistream.h" | |
18 | #include <wx/filesys.h> | |
19 | #include <wx/fs_inet.h> | |
20 | #include <wx/fs_mem.h> | |
21 | #include <wx/fs_zip.h> | |
22 | %} | |
23 | ||
24 | //---------------------------------------------------------------------- | |
25 | ||
26 | %include typemaps.i | |
27 | %include my_typemaps.i | |
28 | ||
29 | // Import some definitions of other classes, etc. | |
30 | %import _defs.i | |
31 | %import utils.i | |
32 | %import image.i | |
33 | %import streams.i | |
34 | ||
35 | %pragma(python) code = "import wx" | |
36 | ||
37 | //--------------------------------------------------------------------------- | |
38 | ||
39 | ||
40 | class wxFSFile : public wxObject { | |
41 | public: | |
42 | wxFSFile(wxInputStream *stream, const wxString& loc, | |
43 | const wxString& mimetype, const wxString& anchor, | |
44 | wxDateTime modif); | |
45 | ||
46 | wxInputStream *GetStream(); | |
47 | const wxString& GetMimeType(); | |
48 | const wxString& GetLocation(); | |
49 | const wxString& GetAnchor(); | |
50 | wxDateTime GetModificationTime(); | |
51 | }; | |
52 | ||
53 | ||
54 | // clear typemaps | |
55 | %typemap(python,in) wxInputStream *stream; | |
56 | %typemap(python,out) wxInputStream *; | |
57 | ||
58 | ||
59 | //--------------------------------------------------------------------------- | |
60 | ||
61 | %{ | |
62 | // wxPyFileSystemHandler will be the Python class wxFileSystemHandler and handling | |
63 | // the callback functions | |
64 | class wxPyFileSystemHandler : public wxFileSystemHandler { | |
65 | public: | |
66 | wxPyFileSystemHandler() : wxFileSystemHandler() {} | |
67 | ||
68 | DEC_PYCALLBACK_BOOL_STRING_pure(CanOpen); | |
69 | DEC_PYCALLBACK_FSF_FSSTRING_pure(OpenFile); | |
70 | DEC_PYCALLBACK_STRING_STRINGINT_pure(FindFirst); | |
71 | DEC_PYCALLBACK_STRING__pure(FindNext); | |
72 | ||
73 | wxString GetProtocol(const wxString& location) { | |
74 | return wxFileSystemHandler::GetProtocol(location); | |
75 | } | |
76 | ||
77 | wxString GetLeftLocation(const wxString& location) { | |
78 | return wxFileSystemHandler::GetLeftLocation(location); | |
79 | } | |
80 | ||
81 | wxString GetAnchor(const wxString& location) { | |
82 | return wxFileSystemHandler::GetAnchor(location); | |
83 | } | |
84 | ||
85 | wxString GetRightLocation(const wxString& location) { | |
86 | return wxFileSystemHandler::GetRightLocation(location); | |
87 | } | |
88 | ||
89 | wxString GetMimeTypeFromExt(const wxString& location) { | |
90 | return wxFileSystemHandler::GetMimeTypeFromExt(location); | |
91 | } | |
92 | ||
93 | PYPRIVATE; | |
94 | }; | |
95 | ||
96 | ||
97 | IMP_PYCALLBACK_BOOL_STRING_pure(wxPyFileSystemHandler, wxFileSystemHandler, CanOpen); | |
98 | IMP_PYCALLBACK_FSF_FSSTRING_pure(wxPyFileSystemHandler, wxFileSystemHandler, OpenFile); | |
99 | IMP_PYCALLBACK_STRING_STRINGINT_pure(wxPyFileSystemHandler, wxFileSystemHandler, FindFirst); | |
100 | IMP_PYCALLBACK_STRING__pure(wxPyFileSystemHandler, wxFileSystemHandler, FindNext); | |
101 | %} | |
102 | ||
103 | ||
104 | %name(wxCPPFileSystemHandler)class wxFileSystemHandler : public wxObject { | |
105 | wxFileSystemHandler(); | |
106 | } | |
107 | ||
108 | %name(wxFileSystemHandler)class wxPyFileSystemHandler : public wxFileSystemHandler { | |
109 | public: | |
110 | wxPyFileSystemHandler(); | |
111 | ||
112 | void _setCallbackInfo(PyObject* self, PyObject* _class); | |
113 | %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxFileSystemHandler)" | |
114 | ||
115 | bool CanOpen(const wxString& location); | |
116 | wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location); | |
117 | wxString FindFirst(const wxString& spec, int flags = 0); | |
118 | wxString FindNext(); | |
119 | ||
120 | wxString GetProtocol(const wxString& location); | |
121 | wxString GetLeftLocation(const wxString& location); | |
122 | wxString GetAnchor(const wxString& location); | |
123 | wxString GetRightLocation(const wxString& location) const; | |
124 | wxString GetMimeTypeFromExt(const wxString& location); | |
125 | }; | |
126 | ||
127 | //--------------------------------------------------------------------------- | |
128 | ||
129 | class wxFileSystem : public wxObject { | |
130 | public: | |
131 | wxFileSystem(); | |
132 | ||
133 | void ChangePathTo(const wxString& location, bool is_dir = FALSE); | |
134 | wxString GetPath(); | |
135 | ||
136 | wxFSFile* OpenFile(const wxString& location); | |
137 | ||
138 | wxString FindFirst(const wxString& spec, int flags = 0); | |
139 | wxString FindNext(); | |
140 | ||
141 | static void AddHandler(wxFileSystemHandler *handler); | |
142 | static void CleanUpHandlers(); | |
143 | ||
144 | // // Returns the native path for a file URL | |
145 | // static wxFileName URLToFileName(const wxString& url); | |
146 | ||
147 | // // Returns the file URL for a native path | |
148 | // static wxString FileNameToURL(const wxFileName& filename); | |
149 | }; | |
150 | ||
151 | //--------------------------------------------------------------------------- | |
152 | ||
153 | class wxInternetFSHandler : public wxFileSystemHandler { | |
154 | public: | |
155 | wxInternetFSHandler(); | |
156 | bool CanOpen(const wxString& location); | |
157 | wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location); | |
158 | }; | |
159 | ||
160 | ||
161 | //--------------------------------------------------------------------------- | |
162 | class wxZipFSHandler : public wxFileSystemHandler { | |
163 | public: | |
164 | wxZipFSHandler(); | |
165 | ||
166 | bool CanOpen(const wxString& location); | |
167 | wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location); | |
168 | wxString FindFirst(const wxString& spec, int flags = 0); | |
169 | wxString FindNext(); | |
170 | }; | |
171 | ||
172 | //--------------------------------------------------------------------------- | |
173 | ||
174 | class wxMemoryFSHandler : public wxFileSystemHandler { | |
175 | public: | |
176 | wxMemoryFSHandler(); | |
177 | ||
178 | // Remove file from memory FS and free occupied memory | |
179 | static void RemoveFile(const wxString& filename); | |
180 | ||
181 | bool CanOpen(const wxString& location); | |
182 | wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location); | |
183 | wxString FindFirst(const wxString& spec, int flags = 0); | |
184 | virtual wxString FindNext(); | |
185 | }; | |
186 | ||
187 | ||
188 | // getting the overloaded static AddFile method right | |
189 | %inline %{ | |
190 | void __wxMemoryFSHandler_AddFile_wxImage(const wxString& filename, | |
191 | wxImage& image, | |
192 | long type) { | |
193 | wxMemoryFSHandler::AddFile(filename, image, type); | |
194 | } | |
195 | ||
196 | void __wxMemoryFSHandler_AddFile_wxBitmap(const wxString& filename, | |
197 | const wxBitmap& bitmap, | |
198 | long type) { | |
199 | wxMemoryFSHandler::AddFile(filename, bitmap, type); | |
200 | } | |
201 | ||
202 | void __wxMemoryFSHandler_AddFile_Data(const wxString& filename, | |
203 | PyObject* data) { | |
204 | ||
205 | wxMemoryFSHandler::AddFile(filename, | |
206 | // TODO: Verify data type | |
207 | (void*)PyString_AsString(data), | |
208 | (size_t)PyString_Size(data)); | |
209 | } | |
210 | %} | |
211 | ||
212 | ||
213 | // case switch for overloading | |
214 | %pragma(python) code = " | |
215 | import types | |
216 | def wxMemoryFSHandler_AddFile(filename, a, b=''): | |
217 | if wx.wxPy_isinstance(a, (wxImage, wxImagePtr)): | |
218 | __wxMemoryFSHandler_AddFile_wxImage(filename, a, b) | |
219 | elif wx.wxPy_isinstance(a, (wxBitmap, wxBitmapPtr)): | |
220 | __wxMemoryFSHandler_AddFile_wxBitmap(filename, a, b) | |
221 | elif type(a) == types.StringType: | |
222 | #__wxMemoryFSHandler_AddFile_wxString(filename, a) | |
223 | __wxMemoryFSHandler_AddFile_Data(filename, a) | |
224 | else: raise TypeError, 'wxImage, wxBitmap or string expected' | |
225 | " | |
226 | ||
227 | ||
228 | //--------------------------------------------------------------------------- | |
229 | ||
230 | %init %{ | |
231 | wxPyPtrTypeMap_Add("wxFileSystemHandler", "wxPyFileSystemHandler"); | |
232 | %} | |
233 | ||
234 | //--------------------------------------------------------------------------- |