1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG definitions of the wxFileSystem family of classes
5 // Author: Joerg Baumann
7 // Created: 25-Sept-2000
9 // Copyright: (c) 2000 by Joerg Baumann
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
17 #include <wx/filesys.h>
18 #include <wx/fs_inet.h>
19 #include <wx/fs_mem.h>
20 #include <wx/fs_zip.h>
23 //----------------------------------------------------------------------
26 %include my_typemaps.i
28 // Import some definitions of other classes, etc.
34 %pragma(python) code = "import wx"
35 %pragma(python) code = "import string"
37 //---------------------------------------------------------------------------
39 // // typemaps for wxInputStream: Note wxFSFile object has to do the delete
40 // // of wxInputStream *
41 // %typemap(python,in) wxInputStream *stream {
42 // if (PyInstance_Check($source)) {
43 // wxPyInputStream* ptr;
44 // if (SWIG_GetPtrObj($source, (void **) &ptr,"_wxPyInputStream_p")) {
45 // PyErr_SetString(PyExc_TypeError,"Expected _wxInputStream_p.");
48 // $target = ptr->wxi;
50 // PyErr_SetString(PyExc_TypeError,"Expected _wxInputStream_p.");
56 // // typemaps for wxInputStream: Note wxFSFile object has to do the delete
57 // // of wxInputStream *
58 // %typemap(python,out) wxInputStream* {
59 // wxPyInputStream * _ptr = NULL;
62 // _ptr = new wxPyInputStream($source);
66 // SWIG_MakePtr(swigptr, _ptr, "_wxPyInputStream_p");
68 // PyObject* classobj = PyDict_GetItemString(wxPython_dict, "wxInputStreamPtr");
70 // Py_INCREF(Py_None);
73 // PyObject* arg = Py_BuildValue("(s)", swigptr);
74 // $target = PyInstance_New(classobj, arg, NULL);
78 // PyObject_SetAttrString($target, "thisown", PyInt_FromLong(1));
81 // Py_INCREF(Py_None);
90 wxFSFile(wxInputStream *stream, const wxString& loc,
91 const wxString& mimetype, const wxString& anchor,
94 wxInputStream *GetStream();
95 const wxString& GetMimeType();
96 const wxString& GetLocation();
97 const wxString& GetAnchor();
98 wxDateTime GetModificationTime();
103 %typemap(python,in) wxInputStream *stream;
104 %typemap(python,out) wxInputStream *;
107 //---------------------------------------------------------------------------
110 // wxPyFileSystemHandler will be the Python class wxFileSystemHandler and handling
111 // the callback functions
112 class wxPyFileSystemHandler : public wxFileSystemHandler {
114 wxPyFileSystemHandler() : wxFileSystemHandler() {}
116 DEC_PYCALLBACK_BOOL_STRING_pure(CanOpen);
117 DEC_PYCALLBACK_FSF_FSSTRING_pure(OpenFile);
118 DEC_PYCALLBACK_STRING_STRINGINT_pure(FindFirst);
119 DEC_PYCALLBACK_STRING__pure(FindNext);
121 wxString GetProtocol(const wxString& location) {
122 return wxFileSystemHandler::GetProtocol(location);
125 wxString GetLeftLocation(const wxString& location) {
126 return wxFileSystemHandler::GetLeftLocation(location);
129 wxString GetAnchor(const wxString& location) {
130 return wxFileSystemHandler::GetAnchor(location);
133 wxString GetRightLocation(const wxString& location) {
134 return wxFileSystemHandler::GetRightLocation(location);
137 wxString GetMimeTypeFromExt(const wxString& location){
138 return wxFileSystemHandler::GetMimeTypeFromExt(location);
145 IMP_PYCALLBACK_BOOL_STRING_pure(wxPyFileSystemHandler, wxFileSystemHandler, CanOpen);
146 IMP_PYCALLBACK_FSF_FSSTRING_pure(wxPyFileSystemHandler, wxFileSystemHandler, OpenFile);
147 IMP_PYCALLBACK_STRING_STRINGINT_pure(wxPyFileSystemHandler, wxFileSystemHandler, FindFirst);
148 IMP_PYCALLBACK_STRING__pure(wxPyFileSystemHandler, wxFileSystemHandler, FindNext);
152 %name(wxCPPFileSystemHandler)class wxFileSystemHandler {
153 wxFileSystemHandler();
156 %name(wxFileSystemHandler)class wxPyFileSystemHandler : public wxFileSystemHandler {
158 wxPyFileSystemHandler();
160 void _setSelf(PyObject* self, PyObject* _class);
161 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxFileSystemHandler)"
163 bool CanOpen(const wxString& location);
164 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
165 wxString FindFirst(const wxString& spec, int flags = 0);
168 wxString GetProtocol(const wxString& location);
169 wxString GetLeftLocation(const wxString& location);
170 wxString GetAnchor(const wxString& location);
171 wxString GetRightLocation(const wxString& location) const;
172 wxString GetMimeTypeFromExt(const wxString& location);
175 //---------------------------------------------------------------------------
181 void ChangePathTo(const wxString& location, bool is_dir = FALSE);
184 wxFSFile* OpenFile(const wxString& location);
186 wxString FindFirst(const wxString& spec, int flags = 0);
189 static void AddHandler(wxFileSystemHandler *handler);
190 static void CleanUpHandlers();
193 //---------------------------------------------------------------------------
195 class wxInternetFSHandler : public wxFileSystemHandler {
197 wxInternetFSHandler();
198 bool CanOpen(const wxString& location);
199 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
203 //---------------------------------------------------------------------------
204 class wxZipFSHandler : public wxFileSystemHandler {
208 bool CanOpen(const wxString& location);
209 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
210 wxString FindFirst(const wxString& spec, int flags = 0);
214 //---------------------------------------------------------------------------
216 class wxMemoryFSHandler : public wxFileSystemHandler {
220 // Remove file from memory FS and free occupied memory
221 static void RemoveFile(const wxString& filename);
223 bool CanOpen(const wxString& location);
224 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
225 wxString FindFirst(const wxString& spec, int flags = 0);
226 virtual wxString FindNext();
230 // getting the overloaded static AddFile method right
232 void __wxMemoryFSHandler_AddFile_wxImage(const wxString& filename,
235 wxMemoryFSHandler::AddFile(filename, image, type);
238 void __wxMemoryFSHandler_AddFile_wxBitmap(const wxString& filename,
239 const wxBitmap& bitmap,
241 wxMemoryFSHandler::AddFile(filename, bitmap, type);
244 // void __wxMemoryFSHandler_AddFile_wxString(const wxString& filename,
245 // const wxString& textdata) {
246 // wxMemoryFSHandler::AddFile(filename, textdata);
249 void __wxMemoryFSHandler_AddFile_Data(const wxString& filename,
252 wxMemoryFSHandler::AddFile(filename,
253 (void*)PyString_AsString(data),
254 (size_t)PyString_Size(data));
259 // case switch for overloading
260 %pragma(python) code = "
262 def wxMemoryFSHandler_AddFile(filename, a, b=''):
263 if isinstance(a, wxImage):
264 __wxMemoryFSHandler_AddFile_wxImage(filename, a, b)
265 elif isinstance(a, wxBitmap):
266 __wxMemoryFSHandler_AddFile_wxBitmap(filename, a, b)
267 elif type(a) == types.StringType:
268 #__wxMemoryFSHandler_AddFile_wxString(filename, a)
269 __wxMemoryFSHandler_AddFile_Data(filename, a)
270 else: raise TypeError, 'wxImage, wxBitmap or string expected'
274 //---------------------------------------------------------------------------