1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG definitions of the wxFileSystem family of classes
5 // Author: Joerg Baumann and Robin Dunn
7 // Created: 25-Sept-2000
9 // Copyright: (c) 2000 by Joerg Baumann
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
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>
24 //----------------------------------------------------------------------
27 %include my_typemaps.i
29 // Import some definitions of other classes, etc.
35 %pragma(python) code = "import wx"
37 //---------------------------------------------------------------------------
40 class wxFSFile : public wxObject {
42 wxFSFile(wxInputStream *stream, const wxString& loc,
43 const wxString& mimetype, const wxString& anchor,
46 wxInputStream *GetStream();
47 const wxString& GetMimeType();
48 const wxString& GetLocation();
49 const wxString& GetAnchor();
50 wxDateTime GetModificationTime();
55 %typemap(python,in) wxInputStream *stream;
56 %typemap(python,out) wxInputStream *;
59 //---------------------------------------------------------------------------
62 // wxPyFileSystemHandler will be the Python class wxFileSystemHandler and handling
63 // the callback functions
64 class wxPyFileSystemHandler : public wxFileSystemHandler {
66 wxPyFileSystemHandler() : wxFileSystemHandler() {}
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);
73 wxString GetProtocol(const wxString& location) {
74 return wxFileSystemHandler::GetProtocol(location);
77 wxString GetLeftLocation(const wxString& location) {
78 return wxFileSystemHandler::GetLeftLocation(location);
81 wxString GetAnchor(const wxString& location) {
82 return wxFileSystemHandler::GetAnchor(location);
85 wxString GetRightLocation(const wxString& location) {
86 return wxFileSystemHandler::GetRightLocation(location);
89 wxString GetMimeTypeFromExt(const wxString& location) {
90 return wxFileSystemHandler::GetMimeTypeFromExt(location);
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);
104 %name(wxCPPFileSystemHandler)class wxFileSystemHandler : public wxObject {
105 wxFileSystemHandler();
108 %name(wxFileSystemHandler)class wxPyFileSystemHandler : public wxFileSystemHandler {
110 wxPyFileSystemHandler();
112 void _setCallbackInfo(PyObject* self, PyObject* _class);
113 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxFileSystemHandler)"
115 bool CanOpen(const wxString& location);
116 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
117 wxString FindFirst(const wxString& spec, int flags = 0);
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);
127 //---------------------------------------------------------------------------
129 class wxFileSystem : public wxObject {
133 void ChangePathTo(const wxString& location, bool is_dir = FALSE);
136 wxFSFile* OpenFile(const wxString& location);
138 wxString FindFirst(const wxString& spec, int flags = 0);
141 static void AddHandler(wxFileSystemHandler *handler);
142 static void CleanUpHandlers();
144 // Returns the file URL for a native path
145 static wxString FileNameToURL(const wxString& filename);
147 // Returns the native path for a file URL
148 //static wxFileName URLToFileName(const wxString& url); *** See below
152 // Returns the native path for a file URL
153 wxString wxFileSystem_URLToFileName(const wxString& url);
155 wxString wxFileSystem_URLToFileName(const wxString& url) {
156 wxFileName fname = wxFileSystem::URLToFileName(url);
157 return fname.GetFullPath();
161 //---------------------------------------------------------------------------
163 class wxInternetFSHandler : public wxFileSystemHandler {
165 wxInternetFSHandler();
166 bool CanOpen(const wxString& location);
167 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
171 //---------------------------------------------------------------------------
172 class wxZipFSHandler : public wxFileSystemHandler {
176 bool CanOpen(const wxString& location);
177 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
178 wxString FindFirst(const wxString& spec, int flags = 0);
182 //---------------------------------------------------------------------------
184 class wxMemoryFSHandler : public wxFileSystemHandler {
188 // Remove file from memory FS and free occupied memory
189 static void RemoveFile(const wxString& filename);
191 bool CanOpen(const wxString& location);
192 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
193 wxString FindFirst(const wxString& spec, int flags = 0);
194 virtual wxString FindNext();
198 // getting the overloaded static AddFile method right
200 void __wxMemoryFSHandler_AddFile_wxImage(const wxString& filename,
203 wxMemoryFSHandler::AddFile(filename, image, type);
206 void __wxMemoryFSHandler_AddFile_wxBitmap(const wxString& filename,
207 const wxBitmap& bitmap,
209 wxMemoryFSHandler::AddFile(filename, bitmap, type);
212 void __wxMemoryFSHandler_AddFile_Data(const wxString& filename,
215 wxMemoryFSHandler::AddFile(filename,
216 // TODO: Verify data type
217 (void*)PyString_AsString(data),
218 (size_t)PyString_Size(data));
223 // case switch for overloading
224 %pragma(python) code = "
226 def wxMemoryFSHandler_AddFile(filename, a, b=''):
227 if wx.wxPy_isinstance(a, (wxImage, wxImagePtr)):
228 __wxMemoryFSHandler_AddFile_wxImage(filename, a, b)
229 elif wx.wxPy_isinstance(a, (wxBitmap, wxBitmapPtr)):
230 __wxMemoryFSHandler_AddFile_wxBitmap(filename, a, b)
231 elif type(a) == types.StringType:
232 #__wxMemoryFSHandler_AddFile_wxString(filename, a)
233 __wxMemoryFSHandler_AddFile_Data(filename, a)
234 else: raise TypeError, 'wxImage, wxBitmap or string expected'
238 //---------------------------------------------------------------------------
241 wxPyPtrTypeMap_Add("wxFileSystemHandler", "wxPyFileSystemHandler");
244 //---------------------------------------------------------------------------