1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG definitions of the wxFileSystem family of classes
7 // Created: 25-Sept-2000
9 // Copyright: (c) 2003 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
16 //---------------------------------------------------------------------------
19 #include "wx/wxPython/pyistream.h"
22 //---------------------------------------------------------------------------
26 class wxFSFile : public wxObject
29 %typemap(out) wxFSFile*; // turn off this typemap
31 wxFSFile(wxInputStream *stream, const wxString& loc,
32 const wxString& mimetype, const wxString& anchor,
36 %typemap(out) wxFSFile* { $result = wxPyMake_wxObject($1, $owner); }
40 wxInputStream *GetStream();
43 const wxString& GetMimeType();
44 const wxString& GetLocation();
45 const wxString& GetAnchor();
46 wxDateTime GetModificationTime();
48 %property(Anchor, GetAnchor, doc="See `GetAnchor`");
49 %property(Location, GetLocation, doc="See `GetLocation`");
50 %property(MimeType, GetMimeType, doc="See `GetMimeType`");
51 %property(ModificationTime, GetModificationTime, doc="See `GetModificationTime`");
52 %property(Stream, GetStream, doc="See `GetStream`");
57 //---------------------------------------------------------------------------
60 class wxPyFileSystemHandler : public wxFileSystemHandler
63 wxPyFileSystemHandler() : wxFileSystemHandler() {}
65 DEC_PYCALLBACK_BOOL_STRING_pure(CanOpen);
66 DEC_PYCALLBACK_FSF_FSSTRING_pure(OpenFile);
67 DEC_PYCALLBACK_STRING_STRINGINT_pure(FindFirst);
68 DEC_PYCALLBACK_STRING__pure(FindNext);
70 wxString GetProtocol(const wxString& location) {
71 return wxFileSystemHandler::GetProtocol(location);
74 wxString GetLeftLocation(const wxString& location) {
75 return wxFileSystemHandler::GetLeftLocation(location);
78 wxString GetAnchor(const wxString& location) {
79 return wxFileSystemHandler::GetAnchor(location);
82 wxString GetRightLocation(const wxString& location) {
83 return wxFileSystemHandler::GetRightLocation(location);
86 wxString GetMimeTypeFromExt(const wxString& location) {
87 return wxFileSystemHandler::GetMimeTypeFromExt(location);
94 IMP_PYCALLBACK_BOOL_STRING_pure(wxPyFileSystemHandler, wxFileSystemHandler, CanOpen);
95 IMP_PYCALLBACK_FSF_FSSTRING_pure(wxPyFileSystemHandler, wxFileSystemHandler, OpenFile);
96 IMP_PYCALLBACK_STRING_STRINGINT_pure(wxPyFileSystemHandler, wxFileSystemHandler, FindFirst);
97 IMP_PYCALLBACK_STRING__pure(wxPyFileSystemHandler, wxFileSystemHandler, FindNext);
102 %rename(CPPFileSystemHandler) wxFileSystemHandler;
103 class wxFileSystemHandler //: public wxObject
106 //wxFileSystemHandler();
107 ~wxFileSystemHandler();
112 %rename(FileSystemHandler) wxPyFileSystemHandler;
113 class wxPyFileSystemHandler : public wxFileSystemHandler
116 %pythonAppend wxPyFileSystemHandler "self._setCallbackInfo(self, FileSystemHandler)";
118 wxPyFileSystemHandler();
120 void _setCallbackInfo(PyObject* self, PyObject* _class);
122 bool CanOpen(const wxString& location);
124 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
125 wxString FindFirst(const wxString& spec, int flags = 0);
128 wxString GetProtocol(const wxString& location);
129 wxString GetLeftLocation(const wxString& location);
130 wxString GetAnchor(const wxString& location);
131 wxString GetRightLocation(const wxString& location);
132 wxString GetMimeTypeFromExt(const wxString& location);
134 %property(Anchor, GetAnchor, doc="See `GetAnchor`");
135 %property(LeftLocation, GetLeftLocation, doc="See `GetLeftLocation`");
136 %property(MimeTypeFromExt, GetMimeTypeFromExt, doc="See `GetMimeTypeFromExt`");
137 %property(Protocol, GetProtocol, doc="See `GetProtocol`");
138 %property(RightLocation, GetRightLocation, doc="See `GetRightLocation`");
142 // //---------------------------------------------------------------------------
145 class wxFileSystem : public wxObject {
150 void ChangePathTo(const wxString& location, bool is_dir = false);
154 wxFSFile* OpenFile(const wxString& location);
156 wxString FindFirst(const wxString& spec, int flags = 0);
159 %disownarg(wxFileSystemHandler *handler);
160 static void AddHandler(wxFileSystemHandler *handler);
161 %cleardisown(wxFileSystemHandler *handler);
163 // Removes FS handler
164 %newobject RemoveHandler;
165 static wxFileSystemHandler* RemoveHandler(wxFileSystemHandler *handler);
167 static void CleanUpHandlers();
169 // Returns the file URL for a native path
170 static wxString FileNameToURL(const wxString& filename);
172 // Returns the native path for a file URL
173 //static wxFileName URLToFileName(const wxString& url);
175 static wxString URLToFileName(const wxString& url) {
176 wxFileName fname = wxFileSystem::URLToFileName(url);
177 return fname.GetFullPath();
181 %property(Path, GetPath, doc="See `GetPath`");
186 //---------------------------------------------------------------------------
188 class wxInternetFSHandler : public wxFileSystemHandler {
190 wxInternetFSHandler();
191 bool CanOpen(const wxString& location);
193 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
197 //---------------------------------------------------------------------------
199 class wxZipFSHandler : public wxFileSystemHandler {
203 bool CanOpen(const wxString& location);
205 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
206 wxString FindFirst(const wxString& spec, int flags = 0);
210 //---------------------------------------------------------------------------
212 // TODO: Use SWIG's overloading feature to fix this mess?
214 // getting the overloaded static AddFile method right
216 void __wxMemoryFSHandler_AddFile_wxImage(const wxString& filename,
219 wxMemoryFSHandler::AddFile(filename, image, type);
222 void __wxMemoryFSHandler_AddFile_wxBitmap(const wxString& filename,
223 const wxBitmap& bitmap,
225 wxMemoryFSHandler::AddFile(filename, bitmap, type);
228 void __wxMemoryFSHandler_AddFile_Data(const wxString& filename,
230 if (! PyString_Check(data)) {
231 wxPyBLOCK_THREADS(PyErr_SetString(PyExc_TypeError,
232 "Expected string object"));
236 wxPyBlock_t blocked = wxPyBeginBlockThreads();
237 void* ptr = (void*)PyString_AsString(data);
238 size_t size = PyString_Size(data);
239 wxPyEndBlockThreads(blocked);
241 wxMemoryFSHandler::AddFile(filename, ptr, size);
246 // case switch for overloading
248 def MemoryFSHandler_AddFile(filename, dataItem, imgType=-1):
250 Add 'file' to the memory filesystem. The dataItem parameter can
251 either be a `wx.Bitmap`, `wx.Image` or a string that can contain
252 arbitrary data. If a bitmap or image is used then the imgType
253 parameter should specify what kind of image file it should be
254 written as, wx.BITMAP_TYPE_PNG, etc.
256 if isinstance(dataItem, wx.Image):
257 __wxMemoryFSHandler_AddFile_wxImage(filename, dataItem, imgType)
258 elif isinstance(dataItem, wx.Bitmap):
259 __wxMemoryFSHandler_AddFile_wxBitmap(filename, dataItem, imgType)
260 elif type(dataItem) == str:
261 __wxMemoryFSHandler_AddFile_Data(filename, dataItem)
263 raise TypeError, 'wx.Image, wx.Bitmap or string expected'
267 class wxMemoryFSHandler : public wxFileSystemHandler {
271 // Remove file from memory FS and free occupied memory
272 static void RemoveFile(const wxString& filename);
274 // Add a file to the memory FS
275 %pythoncode { AddFile = staticmethod(MemoryFSHandler_AddFile) }
277 bool CanOpen(const wxString& location);
279 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
280 wxString FindFirst(const wxString& spec, int flags = 0);
281 virtual wxString FindNext();
285 //---------------------------------------------------------------------------
287 wxPyPtrTypeMap_Add("wxFileSystemHandler", "wxPyFileSystemHandler");
289 //---------------------------------------------------------------------------