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 wxFSFile(wxInputStream *stream, const wxString& loc,
30 const wxString& mimetype, const wxString& anchor,
34 wxInputStream *GetStream();
35 const wxString& GetMimeType();
36 const wxString& GetLocation();
37 const wxString& GetAnchor();
38 wxDateTime GetModificationTime();
42 //---------------------------------------------------------------------------
45 class wxPyFileSystemHandler : public wxFileSystemHandler
48 wxPyFileSystemHandler() : wxFileSystemHandler() {}
50 DEC_PYCALLBACK_BOOL_STRING_pure(CanOpen);
51 DEC_PYCALLBACK_FSF_FSSTRING_pure(OpenFile);
52 DEC_PYCALLBACK_STRING_STRINGINT_pure(FindFirst);
53 DEC_PYCALLBACK_STRING__pure(FindNext);
55 wxString GetProtocol(const wxString& location) {
56 return wxFileSystemHandler::GetProtocol(location);
59 wxString GetLeftLocation(const wxString& location) {
60 return wxFileSystemHandler::GetLeftLocation(location);
63 wxString GetAnchor(const wxString& location) {
64 return wxFileSystemHandler::GetAnchor(location);
67 wxString GetRightLocation(const wxString& location) {
68 return wxFileSystemHandler::GetRightLocation(location);
71 wxString GetMimeTypeFromExt(const wxString& location) {
72 return wxFileSystemHandler::GetMimeTypeFromExt(location);
79 IMP_PYCALLBACK_BOOL_STRING_pure(wxPyFileSystemHandler, wxFileSystemHandler, CanOpen);
80 IMP_PYCALLBACK_FSF_FSSTRING_pure(wxPyFileSystemHandler, wxFileSystemHandler, OpenFile);
81 IMP_PYCALLBACK_STRING_STRINGINT_pure(wxPyFileSystemHandler, wxFileSystemHandler, FindFirst);
82 IMP_PYCALLBACK_STRING__pure(wxPyFileSystemHandler, wxFileSystemHandler, FindNext);
87 %name(CPPFileSystemHandler) class wxFileSystemHandler //: public wxObject
90 //wxFileSystemHandler();
95 %name(FileSystemHandler) class wxPyFileSystemHandler : public wxFileSystemHandler
98 %pythonAppend wxPyFileSystemHandler "self._setCallbackInfo(self, FileSystemHandler)";
100 wxPyFileSystemHandler();
102 void _setCallbackInfo(PyObject* self, PyObject* _class);
104 bool CanOpen(const wxString& location);
105 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
106 wxString FindFirst(const wxString& spec, int flags = 0);
109 wxString GetProtocol(const wxString& location);
110 wxString GetLeftLocation(const wxString& location);
111 wxString GetAnchor(const wxString& location);
112 wxString GetRightLocation(const wxString& location);
113 wxString GetMimeTypeFromExt(const wxString& location);
117 // //---------------------------------------------------------------------------
120 class wxFileSystem : public wxObject {
125 void ChangePathTo(const wxString& location, bool is_dir = False);
128 wxFSFile* OpenFile(const wxString& location);
130 wxString FindFirst(const wxString& spec, int flags = 0);
133 static void AddHandler(wxFileSystemHandler *handler);
134 static void CleanUpHandlers();
136 // Returns the file URL for a native path
137 static wxString FileNameToURL(const wxString& filename);
139 // Returns the native path for a file URL
140 //static wxFileName URLToFileName(const wxString& url); *** See below
144 // Returns the native path for a file URL
145 wxString wxFileSystem_URLToFileName(const wxString& url);
147 wxString wxFileSystem_URLToFileName(const wxString& url) {
148 wxFileName fname = wxFileSystem::URLToFileName(url);
149 return fname.GetFullPath();
154 //---------------------------------------------------------------------------
156 class wxInternetFSHandler : public wxFileSystemHandler {
158 wxInternetFSHandler();
159 bool CanOpen(const wxString& location);
160 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
164 //---------------------------------------------------------------------------
166 class wxZipFSHandler : public wxFileSystemHandler {
170 bool CanOpen(const wxString& location);
171 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
172 wxString FindFirst(const wxString& spec, int flags = 0);
176 //---------------------------------------------------------------------------
178 // TODO: Use SWIG's overloading feature to fix this mess?
180 // getting the overloaded static AddFile method right
182 void __wxMemoryFSHandler_AddFile_wxImage(const wxString& filename,
185 wxMemoryFSHandler::AddFile(filename, image, type);
188 void __wxMemoryFSHandler_AddFile_wxBitmap(const wxString& filename,
189 const wxBitmap& bitmap,
191 wxMemoryFSHandler::AddFile(filename, bitmap, type);
194 void __wxMemoryFSHandler_AddFile_Data(const wxString& filename,
196 wxMemoryFSHandler::AddFile(filename,
197 // TODO: Verify data type
198 (void*)PyString_AsString(data),
199 (size_t)PyString_Size(data));
204 // case switch for overloading
206 def MemoryFSHandler_AddFile(filename, a, b=''):
207 if isinstance(a, wx.Image):
208 __wxMemoryFSHandler_AddFile_wxImage(filename, a, b)
209 elif isinstance(a, wx.Bitmap):
210 __wxMemoryFSHandler_AddFile_wxBitmap(filename, a, b)
212 __wxMemoryFSHandler_AddFile_Data(filename, a)
213 else: raise TypeError, 'wx.Image, wx.Bitmap or string expected'
217 class wxMemoryFSHandler : public wxFileSystemHandler {
221 // Remove file from memory FS and free occupied memory
222 static void RemoveFile(const wxString& filename);
224 // Add a file to the memory FS
225 %pythoncode { AddFile = staticmethod(MemoryFSHandler_AddFile) }
227 bool CanOpen(const wxString& location);
228 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
229 wxString FindFirst(const wxString& spec, int flags = 0);
230 virtual wxString FindNext();
234 //---------------------------------------------------------------------------
236 wxPyPtrTypeMap_Add("wxFileSystemHandler", "wxPyFileSystemHandler");
238 //---------------------------------------------------------------------------