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 %pythonAppend wxFSFile
30 "self.thisown = 0 # It will normally be deleted by the user of the wxFileSystem";
32 wxFSFile(wxInputStream *stream, const wxString& loc,
33 const wxString& mimetype, const wxString& anchor,
38 wxInputStream *GetStream();
39 const wxString& GetMimeType();
40 const wxString& GetLocation();
41 const wxString& GetAnchor();
42 wxDateTime GetModificationTime();
46 //---------------------------------------------------------------------------
49 class wxPyFileSystemHandler : public wxFileSystemHandler
52 wxPyFileSystemHandler() : wxFileSystemHandler() {}
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);
59 wxString GetProtocol(const wxString& location) {
60 return wxFileSystemHandler::GetProtocol(location);
63 wxString GetLeftLocation(const wxString& location) {
64 return wxFileSystemHandler::GetLeftLocation(location);
67 wxString GetAnchor(const wxString& location) {
68 return wxFileSystemHandler::GetAnchor(location);
71 wxString GetRightLocation(const wxString& location) {
72 return wxFileSystemHandler::GetRightLocation(location);
75 wxString GetMimeTypeFromExt(const wxString& location) {
76 return wxFileSystemHandler::GetMimeTypeFromExt(location);
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);
91 %name(CPPFileSystemHandler) class wxFileSystemHandler //: public wxObject
94 //wxFileSystemHandler();
99 %name(FileSystemHandler) class wxPyFileSystemHandler : public wxFileSystemHandler
102 %pythonAppend wxPyFileSystemHandler "self._setCallbackInfo(self, FileSystemHandler)";
104 wxPyFileSystemHandler();
106 void _setCallbackInfo(PyObject* self, PyObject* _class);
108 bool CanOpen(const wxString& location);
110 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
111 wxString FindFirst(const wxString& spec, int flags = 0);
114 wxString GetProtocol(const wxString& location);
115 wxString GetLeftLocation(const wxString& location);
116 wxString GetAnchor(const wxString& location);
117 wxString GetRightLocation(const wxString& location);
118 wxString GetMimeTypeFromExt(const wxString& location);
122 // //---------------------------------------------------------------------------
125 class wxFileSystem : public wxObject {
130 void ChangePathTo(const wxString& location, bool is_dir = False);
134 wxFSFile* OpenFile(const wxString& location);
136 wxString FindFirst(const wxString& spec, int flags = 0);
139 static void AddHandler(wxFileSystemHandler *handler);
140 static void CleanUpHandlers();
142 // Returns the file URL for a native path
143 static wxString FileNameToURL(const wxString& filename);
145 // Returns the native path for a file URL
146 //static wxFileName URLToFileName(const wxString& url); *** See below
150 // Returns the native path for a file URL
151 wxString wxFileSystem_URLToFileName(const wxString& url);
153 wxString wxFileSystem_URLToFileName(const wxString& url) {
154 wxFileName fname = wxFileSystem::URLToFileName(url);
155 return fname.GetFullPath();
160 //---------------------------------------------------------------------------
162 class wxInternetFSHandler : public wxFileSystemHandler {
164 wxInternetFSHandler();
165 bool CanOpen(const wxString& location);
167 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
171 //---------------------------------------------------------------------------
173 class wxZipFSHandler : public wxFileSystemHandler {
177 bool CanOpen(const wxString& location);
179 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
180 wxString FindFirst(const wxString& spec, int flags = 0);
184 //---------------------------------------------------------------------------
186 // TODO: Use SWIG's overloading feature to fix this mess?
188 // getting the overloaded static AddFile method right
190 void __wxMemoryFSHandler_AddFile_wxImage(const wxString& filename,
193 wxMemoryFSHandler::AddFile(filename, image, type);
196 void __wxMemoryFSHandler_AddFile_wxBitmap(const wxString& filename,
197 const wxBitmap& bitmap,
199 wxMemoryFSHandler::AddFile(filename, bitmap, type);
202 void __wxMemoryFSHandler_AddFile_Data(const wxString& filename,
204 wxMemoryFSHandler::AddFile(filename,
205 // TODO: Verify data type
206 (void*)PyString_AsString(data),
207 (size_t)PyString_Size(data));
212 // case switch for overloading
214 def MemoryFSHandler_AddFile(filename, a, b=''):
215 if isinstance(a, wx.Image):
216 __wxMemoryFSHandler_AddFile_wxImage(filename, a, b)
217 elif isinstance(a, wx.Bitmap):
218 __wxMemoryFSHandler_AddFile_wxBitmap(filename, a, b)
220 __wxMemoryFSHandler_AddFile_Data(filename, a)
221 else: raise TypeError, 'wx.Image, wx.Bitmap or string expected'
225 class wxMemoryFSHandler : public wxFileSystemHandler {
229 // Remove file from memory FS and free occupied memory
230 static void RemoveFile(const wxString& filename);
232 // Add a file to the memory FS
233 %pythoncode { AddFile = staticmethod(MemoryFSHandler_AddFile) }
235 bool CanOpen(const wxString& location);
237 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
238 wxString FindFirst(const wxString& spec, int flags = 0);
239 virtual wxString FindNext();
243 //---------------------------------------------------------------------------
245 wxPyPtrTypeMap_Add("wxFileSystemHandler", "wxPyFileSystemHandler");
247 //---------------------------------------------------------------------------