]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_filesys.i
more todos so I don't forget
[wxWidgets.git] / wxPython / src / _filesys.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: _filesys.i
3 // Purpose: SWIG definitions of the wxFileSystem family of classes
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 25-Sept-2000
8 // RCS-ID: $Id$
9 // Copyright: (c) 2003 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 // Not a %module
14
15
16 //---------------------------------------------------------------------------
17
18 %{
19 #include "wx/wxPython/pyistream.h"
20 %}
21
22 //---------------------------------------------------------------------------
23 %newgroup
24
25
26 class wxFSFile : public wxObject
27 {
28 public:
29 %pythonAppend wxFSFile
30 "self.thisown = 0 # It will normally be deleted by the user of the wxFileSystem";
31
32 wxFSFile(wxInputStream *stream, const wxString& loc,
33 const wxString& mimetype, const wxString& anchor,
34 wxDateTime modif);
35
36 ~wxFSFile();
37
38 wxInputStream *GetStream();
39 const wxString& GetMimeType();
40 const wxString& GetLocation();
41 const wxString& GetAnchor();
42 wxDateTime GetModificationTime();
43 };
44
45
46 //---------------------------------------------------------------------------
47
48 %{
49 class wxPyFileSystemHandler : public wxFileSystemHandler
50 {
51 public:
52 wxPyFileSystemHandler() : wxFileSystemHandler() {}
53
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);
58
59 wxString GetProtocol(const wxString& location) {
60 return wxFileSystemHandler::GetProtocol(location);
61 }
62
63 wxString GetLeftLocation(const wxString& location) {
64 return wxFileSystemHandler::GetLeftLocation(location);
65 }
66
67 wxString GetAnchor(const wxString& location) {
68 return wxFileSystemHandler::GetAnchor(location);
69 }
70
71 wxString GetRightLocation(const wxString& location) {
72 return wxFileSystemHandler::GetRightLocation(location);
73 }
74
75 wxString GetMimeTypeFromExt(const wxString& location) {
76 return wxFileSystemHandler::GetMimeTypeFromExt(location);
77 }
78
79 PYPRIVATE;
80 };
81
82
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);
87 %}
88
89
90
91 %name(CPPFileSystemHandler) class wxFileSystemHandler //: public wxObject
92 {
93 public:
94 //wxFileSystemHandler();
95 };
96
97
98
99 %name(FileSystemHandler) class wxPyFileSystemHandler : public wxFileSystemHandler
100 {
101 public:
102 %pythonAppend wxPyFileSystemHandler "self._setCallbackInfo(self, FileSystemHandler)";
103
104 wxPyFileSystemHandler();
105
106 void _setCallbackInfo(PyObject* self, PyObject* _class);
107
108 bool CanOpen(const wxString& location);
109 %newobject OpenFile;
110 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
111 wxString FindFirst(const wxString& spec, int flags = 0);
112 wxString FindNext();
113
114 wxString GetProtocol(const wxString& location);
115 wxString GetLeftLocation(const wxString& location);
116 wxString GetAnchor(const wxString& location);
117 wxString GetRightLocation(const wxString& location);
118 wxString GetMimeTypeFromExt(const wxString& location);
119 };
120
121
122 // //---------------------------------------------------------------------------
123
124
125 class wxFileSystem : public wxObject {
126 public:
127 wxFileSystem();
128 ~wxFileSystem();
129
130 void ChangePathTo(const wxString& location, bool is_dir = false);
131 wxString GetPath();
132
133 %newobject OpenFile;
134 wxFSFile* OpenFile(const wxString& location);
135
136 wxString FindFirst(const wxString& spec, int flags = 0);
137 wxString FindNext();
138
139 static void AddHandler(wxFileSystemHandler *handler);
140 static void CleanUpHandlers();
141
142 // Returns the file URL for a native path
143 static wxString FileNameToURL(const wxString& filename);
144
145 // Returns the native path for a file URL
146 //static wxFileName URLToFileName(const wxString& url);
147 %extend {
148 static wxString URLToFileName(const wxString& url) {
149 wxFileName fname = wxFileSystem::URLToFileName(url);
150 return fname.GetFullPath();
151 }
152 }
153 };
154
155
156
157 //---------------------------------------------------------------------------
158
159 class wxInternetFSHandler : public wxFileSystemHandler {
160 public:
161 wxInternetFSHandler();
162 bool CanOpen(const wxString& location);
163 %newobject OpenFile;
164 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
165 };
166
167
168 //---------------------------------------------------------------------------
169
170 class wxZipFSHandler : public wxFileSystemHandler {
171 public:
172 wxZipFSHandler();
173
174 bool CanOpen(const wxString& location);
175 %newobject OpenFile;
176 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
177 wxString FindFirst(const wxString& spec, int flags = 0);
178 wxString FindNext();
179 };
180
181 //---------------------------------------------------------------------------
182
183 // TODO: Use SWIG's overloading feature to fix this mess?
184
185 // getting the overloaded static AddFile method right
186 %inline %{
187 void __wxMemoryFSHandler_AddFile_wxImage(const wxString& filename,
188 wxImage& image,
189 long type) {
190 wxMemoryFSHandler::AddFile(filename, image, type);
191 }
192
193 void __wxMemoryFSHandler_AddFile_wxBitmap(const wxString& filename,
194 const wxBitmap& bitmap,
195 long type) {
196 wxMemoryFSHandler::AddFile(filename, bitmap, type);
197 }
198
199 void __wxMemoryFSHandler_AddFile_Data(const wxString& filename,
200 PyObject* data) {
201 if (! PyString_Check(data)) {
202 wxPyBLOCK_THREADS(PyErr_SetString(PyExc_TypeError,
203 "Expected string object"));
204 return;
205 }
206
207 bool blocked = wxPyBeginBlockThreads();
208 void* ptr = (void*)PyString_AsString(data);
209 size_t size = PyString_Size(data);
210 wxPyEndBlockThreads(blocked);
211
212 wxMemoryFSHandler::AddFile(filename, ptr, size);
213 }
214 %}
215
216
217 // case switch for overloading
218 %pythoncode {
219 def MemoryFSHandler_AddFile(filename, dataItem, imgType=-1):
220 """
221 Add 'file' to the memory filesystem. The dataItem parameter can
222 either be a `wx.Bitmap`, `wx.Image` or a string that can contain
223 arbitrary data. If a bitmap or image is used then the imgType
224 parameter should specify what kind of image file it should be
225 written as, wx.BITMAP_TYPE_PNG, etc.
226 """
227 if isinstance(dataItem, wx.Image):
228 __wxMemoryFSHandler_AddFile_wxImage(filename, dataItem, imgType)
229 elif isinstance(dataItem, wx.Bitmap):
230 __wxMemoryFSHandler_AddFile_wxBitmap(filename, dataItem, imgType)
231 elif type(dataItem) == str:
232 __wxMemoryFSHandler_AddFile_Data(filename, dataItem)
233 else:
234 raise TypeError, 'wx.Image, wx.Bitmap or string expected'
235 }
236
237
238 class wxMemoryFSHandler : public wxFileSystemHandler {
239 public:
240 wxMemoryFSHandler();
241
242 // Remove file from memory FS and free occupied memory
243 static void RemoveFile(const wxString& filename);
244
245 // Add a file to the memory FS
246 %pythoncode { AddFile = staticmethod(MemoryFSHandler_AddFile) }
247
248 bool CanOpen(const wxString& location);
249 %newobject OpenFile;
250 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
251 wxString FindFirst(const wxString& spec, int flags = 0);
252 virtual wxString FindNext();
253 };
254
255
256 //---------------------------------------------------------------------------
257 %init %{
258 wxPyPtrTypeMap_Add("wxFileSystemHandler", "wxPyFileSystemHandler");
259 %}
260 //---------------------------------------------------------------------------