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();
41 const wxString& GetMimeType();
42 const wxString& GetLocation();
43 const wxString& GetAnchor();
44 wxDateTime GetModificationTime();
48 //---------------------------------------------------------------------------
51 class wxPyFileSystemHandler : public wxFileSystemHandler
54 wxPyFileSystemHandler() : wxFileSystemHandler() {}
56 DEC_PYCALLBACK_BOOL_STRING_pure(CanOpen);
57 DEC_PYCALLBACK_FSF_FSSTRING_pure(OpenFile);
58 DEC_PYCALLBACK_STRING_STRINGINT_pure(FindFirst);
59 DEC_PYCALLBACK_STRING__pure(FindNext);
61 wxString GetProtocol(const wxString& location) {
62 return wxFileSystemHandler::GetProtocol(location);
65 wxString GetLeftLocation(const wxString& location) {
66 return wxFileSystemHandler::GetLeftLocation(location);
69 wxString GetAnchor(const wxString& location) {
70 return wxFileSystemHandler::GetAnchor(location);
73 wxString GetRightLocation(const wxString& location) {
74 return wxFileSystemHandler::GetRightLocation(location);
77 wxString GetMimeTypeFromExt(const wxString& location) {
78 return wxFileSystemHandler::GetMimeTypeFromExt(location);
85 IMP_PYCALLBACK_BOOL_STRING_pure(wxPyFileSystemHandler, wxFileSystemHandler, CanOpen);
86 IMP_PYCALLBACK_FSF_FSSTRING_pure(wxPyFileSystemHandler, wxFileSystemHandler, OpenFile);
87 IMP_PYCALLBACK_STRING_STRINGINT_pure(wxPyFileSystemHandler, wxFileSystemHandler, FindFirst);
88 IMP_PYCALLBACK_STRING__pure(wxPyFileSystemHandler, wxFileSystemHandler, FindNext);
93 %rename(CPPFileSystemHandler) wxFileSystemHandler;
94 class wxFileSystemHandler //: public wxObject
97 //wxFileSystemHandler();
98 ~wxFileSystemHandler();
103 %rename(FileSystemHandler) wxPyFileSystemHandler;
104 class wxPyFileSystemHandler : public wxFileSystemHandler
107 %pythonAppend wxPyFileSystemHandler "self._setCallbackInfo(self, FileSystemHandler)";
109 wxPyFileSystemHandler();
111 void _setCallbackInfo(PyObject* self, PyObject* _class);
113 bool CanOpen(const wxString& location);
115 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
116 wxString FindFirst(const wxString& spec, int flags = 0);
119 wxString GetProtocol(const wxString& location);
120 wxString GetLeftLocation(const wxString& location);
121 wxString GetAnchor(const wxString& location);
122 wxString GetRightLocation(const wxString& location);
123 wxString GetMimeTypeFromExt(const wxString& location);
127 // //---------------------------------------------------------------------------
130 class wxFileSystem : public wxObject {
135 void ChangePathTo(const wxString& location, bool is_dir = false);
139 wxFSFile* OpenFile(const wxString& location);
141 wxString FindFirst(const wxString& spec, int flags = 0);
144 %disownarg(wxFileSystemHandler *handler);
145 static void AddHandler(wxFileSystemHandler *handler);
146 %cleardisown(wxFileSystemHandler *handler);
148 static void CleanUpHandlers();
150 // Returns the file URL for a native path
151 static wxString FileNameToURL(const wxString& filename);
153 // Returns the native path for a file URL
154 //static wxFileName URLToFileName(const wxString& url);
156 static wxString URLToFileName(const wxString& url) {
157 wxFileName fname = wxFileSystem::URLToFileName(url);
158 return fname.GetFullPath();
165 //---------------------------------------------------------------------------
167 class wxInternetFSHandler : public wxFileSystemHandler {
169 wxInternetFSHandler();
170 bool CanOpen(const wxString& location);
172 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
176 //---------------------------------------------------------------------------
178 class wxZipFSHandler : public wxFileSystemHandler {
182 bool CanOpen(const wxString& location);
184 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
185 wxString FindFirst(const wxString& spec, int flags = 0);
189 //---------------------------------------------------------------------------
191 // TODO: Use SWIG's overloading feature to fix this mess?
193 // getting the overloaded static AddFile method right
195 void __wxMemoryFSHandler_AddFile_wxImage(const wxString& filename,
198 wxMemoryFSHandler::AddFile(filename, image, type);
201 void __wxMemoryFSHandler_AddFile_wxBitmap(const wxString& filename,
202 const wxBitmap& bitmap,
204 wxMemoryFSHandler::AddFile(filename, bitmap, type);
207 void __wxMemoryFSHandler_AddFile_Data(const wxString& filename,
209 if (! PyString_Check(data)) {
210 wxPyBLOCK_THREADS(PyErr_SetString(PyExc_TypeError,
211 "Expected string object"));
215 wxPyBlock_t blocked = wxPyBeginBlockThreads();
216 void* ptr = (void*)PyString_AsString(data);
217 size_t size = PyString_Size(data);
218 wxPyEndBlockThreads(blocked);
220 wxMemoryFSHandler::AddFile(filename, ptr, size);
225 // case switch for overloading
227 def MemoryFSHandler_AddFile(filename, dataItem, imgType=-1):
229 Add 'file' to the memory filesystem. The dataItem parameter can
230 either be a `wx.Bitmap`, `wx.Image` or a string that can contain
231 arbitrary data. If a bitmap or image is used then the imgType
232 parameter should specify what kind of image file it should be
233 written as, wx.BITMAP_TYPE_PNG, etc.
235 if isinstance(dataItem, wx.Image):
236 __wxMemoryFSHandler_AddFile_wxImage(filename, dataItem, imgType)
237 elif isinstance(dataItem, wx.Bitmap):
238 __wxMemoryFSHandler_AddFile_wxBitmap(filename, dataItem, imgType)
239 elif type(dataItem) == str:
240 __wxMemoryFSHandler_AddFile_Data(filename, dataItem)
242 raise TypeError, 'wx.Image, wx.Bitmap or string expected'
246 class wxMemoryFSHandler : public wxFileSystemHandler {
250 // Remove file from memory FS and free occupied memory
251 static void RemoveFile(const wxString& filename);
253 // Add a file to the memory FS
254 %pythoncode { AddFile = staticmethod(MemoryFSHandler_AddFile) }
256 bool CanOpen(const wxString& location);
258 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
259 wxString FindFirst(const wxString& spec, int flags = 0);
260 virtual wxString FindNext();
264 //---------------------------------------------------------------------------
266 wxPyPtrTypeMap_Add("wxFileSystemHandler", "wxPyFileSystemHandler");
268 //---------------------------------------------------------------------------