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 wx.FileSystem";
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 %rename(CPPFileSystemHandler) wxFileSystemHandler;
92 class wxFileSystemHandler //: public wxObject
95 //wxFileSystemHandler();
96 ~wxFileSystemHandler();
101 %rename(FileSystemHandler) wxPyFileSystemHandler;
102 class wxPyFileSystemHandler : public wxFileSystemHandler
105 %pythonAppend wxPyFileSystemHandler "self._setCallbackInfo(self, FileSystemHandler)";
107 wxPyFileSystemHandler();
109 void _setCallbackInfo(PyObject* self, PyObject* _class);
111 bool CanOpen(const wxString& location);
113 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
114 wxString FindFirst(const wxString& spec, int flags = 0);
117 wxString GetProtocol(const wxString& location);
118 wxString GetLeftLocation(const wxString& location);
119 wxString GetAnchor(const wxString& location);
120 wxString GetRightLocation(const wxString& location);
121 wxString GetMimeTypeFromExt(const wxString& location);
125 // //---------------------------------------------------------------------------
128 class wxFileSystem : public wxObject {
133 void ChangePathTo(const wxString& location, bool is_dir = false);
137 wxFSFile* OpenFile(const wxString& location);
139 wxString FindFirst(const wxString& spec, int flags = 0);
142 %disownarg(wxFileSystemHandler *handler);
143 static void AddHandler(wxFileSystemHandler *handler);
144 %cleardisown(wxFileSystemHandler *handler);
146 static void CleanUpHandlers();
148 // Returns the file URL for a native path
149 static wxString FileNameToURL(const wxString& filename);
151 // Returns the native path for a file URL
152 //static wxFileName URLToFileName(const wxString& url);
154 static wxString URLToFileName(const wxString& url) {
155 wxFileName fname = wxFileSystem::URLToFileName(url);
156 return fname.GetFullPath();
163 //---------------------------------------------------------------------------
165 class wxInternetFSHandler : public wxFileSystemHandler {
167 wxInternetFSHandler();
168 bool CanOpen(const wxString& location);
170 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
174 //---------------------------------------------------------------------------
176 class wxZipFSHandler : public wxFileSystemHandler {
180 bool CanOpen(const wxString& location);
182 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
183 wxString FindFirst(const wxString& spec, int flags = 0);
187 //---------------------------------------------------------------------------
189 // TODO: Use SWIG's overloading feature to fix this mess?
191 // getting the overloaded static AddFile method right
193 void __wxMemoryFSHandler_AddFile_wxImage(const wxString& filename,
196 wxMemoryFSHandler::AddFile(filename, image, type);
199 void __wxMemoryFSHandler_AddFile_wxBitmap(const wxString& filename,
200 const wxBitmap& bitmap,
202 wxMemoryFSHandler::AddFile(filename, bitmap, type);
205 void __wxMemoryFSHandler_AddFile_Data(const wxString& filename,
207 if (! PyString_Check(data)) {
208 wxPyBLOCK_THREADS(PyErr_SetString(PyExc_TypeError,
209 "Expected string object"));
213 wxPyBlock_t blocked = wxPyBeginBlockThreads();
214 void* ptr = (void*)PyString_AsString(data);
215 size_t size = PyString_Size(data);
216 wxPyEndBlockThreads(blocked);
218 wxMemoryFSHandler::AddFile(filename, ptr, size);
223 // case switch for overloading
225 def MemoryFSHandler_AddFile(filename, dataItem, imgType=-1):
227 Add 'file' to the memory filesystem. The dataItem parameter can
228 either be a `wx.Bitmap`, `wx.Image` or a string that can contain
229 arbitrary data. If a bitmap or image is used then the imgType
230 parameter should specify what kind of image file it should be
231 written as, wx.BITMAP_TYPE_PNG, etc.
233 if isinstance(dataItem, wx.Image):
234 __wxMemoryFSHandler_AddFile_wxImage(filename, dataItem, imgType)
235 elif isinstance(dataItem, wx.Bitmap):
236 __wxMemoryFSHandler_AddFile_wxBitmap(filename, dataItem, imgType)
237 elif type(dataItem) == str:
238 __wxMemoryFSHandler_AddFile_Data(filename, dataItem)
240 raise TypeError, 'wx.Image, wx.Bitmap or string expected'
244 class wxMemoryFSHandler : public wxFileSystemHandler {
248 // Remove file from memory FS and free occupied memory
249 static void RemoveFile(const wxString& filename);
251 // Add a file to the memory FS
252 %pythoncode { AddFile = staticmethod(MemoryFSHandler_AddFile) }
254 bool CanOpen(const wxString& location);
256 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
257 wxString FindFirst(const wxString& spec, int flags = 0);
258 virtual wxString FindNext();
262 //---------------------------------------------------------------------------
264 wxPyPtrTypeMap_Add("wxFileSystemHandler", "wxPyFileSystemHandler");
266 //---------------------------------------------------------------------------