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();
46 %property(Anchor, GetAnchor, doc="See `GetAnchor`");
47 %property(Location, GetLocation, doc="See `GetLocation`");
48 %property(MimeType, GetMimeType, doc="See `GetMimeType`");
49 %property(ModificationTime, GetModificationTime, doc="See `GetModificationTime`");
50 %property(Stream, GetStream, doc="See `GetStream`");
55 //---------------------------------------------------------------------------
58 class wxPyFileSystemHandler : public wxFileSystemHandler
61 wxPyFileSystemHandler() : wxFileSystemHandler() {}
63 DEC_PYCALLBACK_BOOL_STRING_pure(CanOpen);
64 DEC_PYCALLBACK_FSF_FSSTRING_pure(OpenFile);
65 DEC_PYCALLBACK_STRING_STRINGINT_pure(FindFirst);
66 DEC_PYCALLBACK_STRING__pure(FindNext);
68 wxString GetProtocol(const wxString& location) {
69 return wxFileSystemHandler::GetProtocol(location);
72 wxString GetLeftLocation(const wxString& location) {
73 return wxFileSystemHandler::GetLeftLocation(location);
76 wxString GetAnchor(const wxString& location) {
77 return wxFileSystemHandler::GetAnchor(location);
80 wxString GetRightLocation(const wxString& location) {
81 return wxFileSystemHandler::GetRightLocation(location);
84 wxString GetMimeTypeFromExt(const wxString& location) {
85 return wxFileSystemHandler::GetMimeTypeFromExt(location);
92 IMP_PYCALLBACK_BOOL_STRING_pure(wxPyFileSystemHandler, wxFileSystemHandler, CanOpen);
93 IMP_PYCALLBACK_FSF_FSSTRING_pure(wxPyFileSystemHandler, wxFileSystemHandler, OpenFile);
94 IMP_PYCALLBACK_STRING_STRINGINT_pure(wxPyFileSystemHandler, wxFileSystemHandler, FindFirst);
95 IMP_PYCALLBACK_STRING__pure(wxPyFileSystemHandler, wxFileSystemHandler, FindNext);
100 %rename(CPPFileSystemHandler) wxFileSystemHandler;
101 class wxFileSystemHandler //: public wxObject
104 //wxFileSystemHandler();
105 ~wxFileSystemHandler();
110 %rename(FileSystemHandler) wxPyFileSystemHandler;
111 class wxPyFileSystemHandler : public wxFileSystemHandler
114 %pythonAppend wxPyFileSystemHandler "self._setCallbackInfo(self, FileSystemHandler)";
116 wxPyFileSystemHandler();
118 void _setCallbackInfo(PyObject* self, PyObject* _class);
120 bool CanOpen(const wxString& location);
122 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
123 wxString FindFirst(const wxString& spec, int flags = 0);
126 wxString GetProtocol(const wxString& location);
127 wxString GetLeftLocation(const wxString& location);
128 wxString GetAnchor(const wxString& location);
129 wxString GetRightLocation(const wxString& location);
130 wxString GetMimeTypeFromExt(const wxString& location);
132 %property(Anchor, GetAnchor, doc="See `GetAnchor`");
133 %property(LeftLocation, GetLeftLocation, doc="See `GetLeftLocation`");
134 %property(MimeTypeFromExt, GetMimeTypeFromExt, doc="See `GetMimeTypeFromExt`");
135 %property(Protocol, GetProtocol, doc="See `GetProtocol`");
136 %property(RightLocation, GetRightLocation, doc="See `GetRightLocation`");
140 // //---------------------------------------------------------------------------
143 class wxFileSystem : public wxObject {
148 void ChangePathTo(const wxString& location, bool is_dir = false);
152 wxFSFile* OpenFile(const wxString& location);
154 wxString FindFirst(const wxString& spec, int flags = 0);
157 %disownarg(wxFileSystemHandler *handler);
158 static void AddHandler(wxFileSystemHandler *handler);
159 %cleardisown(wxFileSystemHandler *handler);
161 static void CleanUpHandlers();
163 // Returns the file URL for a native path
164 static wxString FileNameToURL(const wxString& filename);
166 // Returns the native path for a file URL
167 //static wxFileName URLToFileName(const wxString& url);
169 static wxString URLToFileName(const wxString& url) {
170 wxFileName fname = wxFileSystem::URLToFileName(url);
171 return fname.GetFullPath();
175 %property(Path, GetPath, doc="See `GetPath`");
180 //---------------------------------------------------------------------------
182 class wxInternetFSHandler : public wxFileSystemHandler {
184 wxInternetFSHandler();
185 bool CanOpen(const wxString& location);
187 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
191 //---------------------------------------------------------------------------
193 class wxZipFSHandler : public wxFileSystemHandler {
197 bool CanOpen(const wxString& location);
199 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
200 wxString FindFirst(const wxString& spec, int flags = 0);
204 //---------------------------------------------------------------------------
206 // TODO: Use SWIG's overloading feature to fix this mess?
208 // getting the overloaded static AddFile method right
210 void __wxMemoryFSHandler_AddFile_wxImage(const wxString& filename,
213 wxMemoryFSHandler::AddFile(filename, image, type);
216 void __wxMemoryFSHandler_AddFile_wxBitmap(const wxString& filename,
217 const wxBitmap& bitmap,
219 wxMemoryFSHandler::AddFile(filename, bitmap, type);
222 void __wxMemoryFSHandler_AddFile_Data(const wxString& filename,
224 if (! PyString_Check(data)) {
225 wxPyBLOCK_THREADS(PyErr_SetString(PyExc_TypeError,
226 "Expected string object"));
230 wxPyBlock_t blocked = wxPyBeginBlockThreads();
231 void* ptr = (void*)PyString_AsString(data);
232 size_t size = PyString_Size(data);
233 wxPyEndBlockThreads(blocked);
235 wxMemoryFSHandler::AddFile(filename, ptr, size);
240 // case switch for overloading
242 def MemoryFSHandler_AddFile(filename, dataItem, imgType=-1):
244 Add 'file' to the memory filesystem. The dataItem parameter can
245 either be a `wx.Bitmap`, `wx.Image` or a string that can contain
246 arbitrary data. If a bitmap or image is used then the imgType
247 parameter should specify what kind of image file it should be
248 written as, wx.BITMAP_TYPE_PNG, etc.
250 if isinstance(dataItem, wx.Image):
251 __wxMemoryFSHandler_AddFile_wxImage(filename, dataItem, imgType)
252 elif isinstance(dataItem, wx.Bitmap):
253 __wxMemoryFSHandler_AddFile_wxBitmap(filename, dataItem, imgType)
254 elif type(dataItem) == str:
255 __wxMemoryFSHandler_AddFile_Data(filename, dataItem)
257 raise TypeError, 'wx.Image, wx.Bitmap or string expected'
261 class wxMemoryFSHandler : public wxFileSystemHandler {
265 // Remove file from memory FS and free occupied memory
266 static void RemoveFile(const wxString& filename);
268 // Add a file to the memory FS
269 %pythoncode { AddFile = staticmethod(MemoryFSHandler_AddFile) }
271 bool CanOpen(const wxString& location);
273 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
274 wxString FindFirst(const wxString& spec, int flags = 0);
275 virtual wxString FindNext();
279 //---------------------------------------------------------------------------
281 wxPyPtrTypeMap_Add("wxFileSystemHandler", "wxPyFileSystemHandler");
283 //---------------------------------------------------------------------------