]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/_filesys.i
Comment why we don't call PyErr_Print after calling OnInit
[wxWidgets.git] / wxPython / src / _filesys.i
CommitLineData
c368d904 1/////////////////////////////////////////////////////////////////////////////
d14a1e28 2// Name: _filesys.i
c368d904
RD
3// Purpose: SWIG definitions of the wxFileSystem family of classes
4//
d14a1e28 5// Author: Robin Dunn
c368d904
RD
6//
7// Created: 25-Sept-2000
8// RCS-ID: $Id$
d14a1e28 9// Copyright: (c) 2003 by Total Control Software
c368d904
RD
10// Licence: wxWindows license
11/////////////////////////////////////////////////////////////////////////////
12
d14a1e28 13// Not a %module
c368d904 14
c368d904 15
d14a1e28 16//---------------------------------------------------------------------------
c368d904 17
d14a1e28
RD
18%{
19#include "wx/wxPython/pyistream.h"
20%}
c368d904
RD
21
22//---------------------------------------------------------------------------
d14a1e28 23%newgroup
c368d904 24
c368d904 25
d14a1e28
RD
26class wxFSFile : public wxObject
27{
c368d904 28public:
e2e2649f 29 %typemap(out) wxFSFile*; // turn off this typemap
d02ea46c 30
c368d904
RD
31 wxFSFile(wxInputStream *stream, const wxString& loc,
32 const wxString& mimetype, const wxString& anchor,
33 wxDateTime modif);
e2e2649f
RD
34
35 // Turn it back on.
36 %typemap(out) wxFSFile* { $result = wxPyMake_wxObject($1, $owner); }
37
38 ~wxFSFile();
c368d904
RD
39
40 wxInputStream *GetStream();
41 const wxString& GetMimeType();
42 const wxString& GetLocation();
43 const wxString& GetAnchor();
44 wxDateTime GetModificationTime();
42e2bbb9
RD
45
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`");
51
c368d904
RD
52};
53
54
c368d904
RD
55//---------------------------------------------------------------------------
56
57%{
d14a1e28
RD
58class wxPyFileSystemHandler : public wxFileSystemHandler
59{
c368d904
RD
60public:
61 wxPyFileSystemHandler() : wxFileSystemHandler() {}
62
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);
67
68 wxString GetProtocol(const wxString& location) {
69 return wxFileSystemHandler::GetProtocol(location);
70 }
71
72 wxString GetLeftLocation(const wxString& location) {
73 return wxFileSystemHandler::GetLeftLocation(location);
74 }
75
76 wxString GetAnchor(const wxString& location) {
77 return wxFileSystemHandler::GetAnchor(location);
78 }
79
80 wxString GetRightLocation(const wxString& location) {
81 return wxFileSystemHandler::GetRightLocation(location);
82 }
83
e9159fe8 84 wxString GetMimeTypeFromExt(const wxString& location) {
c368d904
RD
85 return wxFileSystemHandler::GetMimeTypeFromExt(location);
86 }
87
88 PYPRIVATE;
89};
90
91
92IMP_PYCALLBACK_BOOL_STRING_pure(wxPyFileSystemHandler, wxFileSystemHandler, CanOpen);
93IMP_PYCALLBACK_FSF_FSSTRING_pure(wxPyFileSystemHandler, wxFileSystemHandler, OpenFile);
94IMP_PYCALLBACK_STRING_STRINGINT_pure(wxPyFileSystemHandler, wxFileSystemHandler, FindFirst);
95IMP_PYCALLBACK_STRING__pure(wxPyFileSystemHandler, wxFileSystemHandler, FindNext);
96%}
97
98
c368d904 99
1b8c7ba6
RD
100%rename(CPPFileSystemHandler) wxFileSystemHandler;
101class wxFileSystemHandler //: public wxObject
d14a1e28
RD
102{
103public:
104 //wxFileSystemHandler();
cdd7b180 105 ~wxFileSystemHandler();
d14a1e28
RD
106};
107
108
109
1b8c7ba6
RD
110%rename(FileSystemHandler) wxPyFileSystemHandler;
111class wxPyFileSystemHandler : public wxFileSystemHandler
d14a1e28 112{
c368d904 113public:
2b9048c5 114 %pythonAppend wxPyFileSystemHandler "self._setCallbackInfo(self, FileSystemHandler)";
e2e2649f 115
c368d904
RD
116 wxPyFileSystemHandler();
117
0122b7e3 118 void _setCallbackInfo(PyObject* self, PyObject* _class);
c368d904
RD
119
120 bool CanOpen(const wxString& location);
b87bfdb7 121 %newobject OpenFile;
c368d904
RD
122 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
123 wxString FindFirst(const wxString& spec, int flags = 0);
124 wxString FindNext();
125
126 wxString GetProtocol(const wxString& location);
127 wxString GetLeftLocation(const wxString& location);
128 wxString GetAnchor(const wxString& location);
d14a1e28 129 wxString GetRightLocation(const wxString& location);
c368d904 130 wxString GetMimeTypeFromExt(const wxString& location);
42e2bbb9
RD
131
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`");
c368d904
RD
137};
138
d14a1e28
RD
139
140// //---------------------------------------------------------------------------
141
c368d904 142
9416aa89 143class wxFileSystem : public wxObject {
c368d904
RD
144public:
145 wxFileSystem();
d14a1e28 146 ~wxFileSystem();
c368d904 147
a72f4631 148 void ChangePathTo(const wxString& location, bool is_dir = false);
c368d904
RD
149 wxString GetPath();
150
b87bfdb7 151 %newobject OpenFile;
c368d904
RD
152 wxFSFile* OpenFile(const wxString& location);
153
154 wxString FindFirst(const wxString& spec, int flags = 0);
155 wxString FindNext();
156
cdd7b180 157 %disownarg(wxFileSystemHandler *handler);
c368d904 158 static void AddHandler(wxFileSystemHandler *handler);
cdd7b180 159 %cleardisown(wxFileSystemHandler *handler);
e2e2649f 160
c368d904 161 static void CleanUpHandlers();
1e4a197e 162
dd116e73
RD
163 // Returns the file URL for a native path
164 static wxString FileNameToURL(const wxString& filename);
1e4a197e 165
dd116e73 166 // Returns the native path for a file URL
7e6581d4
RD
167 //static wxFileName URLToFileName(const wxString& url);
168 %extend {
169 static wxString URLToFileName(const wxString& url) {
170 wxFileName fname = wxFileSystem::URLToFileName(url);
171 return fname.GetFullPath();
172 }
e2e2649f 173 }
42e2bbb9
RD
174
175 %property(Path, GetPath, doc="See `GetPath`");
c368d904
RD
176};
177
dd116e73 178
d14a1e28 179
c368d904
RD
180//---------------------------------------------------------------------------
181
182class wxInternetFSHandler : public wxFileSystemHandler {
183public:
184 wxInternetFSHandler();
185 bool CanOpen(const wxString& location);
b87bfdb7 186 %newobject OpenFile;
c368d904
RD
187 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
188};
189
190
191//---------------------------------------------------------------------------
d14a1e28 192
c368d904
RD
193class wxZipFSHandler : public wxFileSystemHandler {
194public:
195 wxZipFSHandler();
196
197 bool CanOpen(const wxString& location);
b87bfdb7 198 %newobject OpenFile;
c368d904
RD
199 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
200 wxString FindFirst(const wxString& spec, int flags = 0);
201 wxString FindNext();
202};
203
204//---------------------------------------------------------------------------
205
d14a1e28 206// TODO: Use SWIG's overloading feature to fix this mess?
c368d904
RD
207
208// getting the overloaded static AddFile method right
209%inline %{
d14a1e28
RD
210 void __wxMemoryFSHandler_AddFile_wxImage(const wxString& filename,
211 wxImage& image,
212 long type) {
213 wxMemoryFSHandler::AddFile(filename, image, type);
214 }
c368d904 215
d14a1e28
RD
216 void __wxMemoryFSHandler_AddFile_wxBitmap(const wxString& filename,
217 const wxBitmap& bitmap,
218 long type) {
219 wxMemoryFSHandler::AddFile(filename, bitmap, type);
220 }
c368d904 221
d14a1e28
RD
222 void __wxMemoryFSHandler_AddFile_Data(const wxString& filename,
223 PyObject* data) {
7e6581d4
RD
224 if (! PyString_Check(data)) {
225 wxPyBLOCK_THREADS(PyErr_SetString(PyExc_TypeError,
226 "Expected string object"));
227 return;
228 }
229
6e6b3557 230 wxPyBlock_t blocked = wxPyBeginBlockThreads();
7e6581d4
RD
231 void* ptr = (void*)PyString_AsString(data);
232 size_t size = PyString_Size(data);
233 wxPyEndBlockThreads(blocked);
234
235 wxMemoryFSHandler::AddFile(filename, ptr, size);
d14a1e28 236 }
c368d904
RD
237%}
238
239
240// case switch for overloading
d14a1e28 241%pythoncode {
7e6581d4
RD
242def MemoryFSHandler_AddFile(filename, dataItem, imgType=-1):
243 """
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.
249 """
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)
256 else:
257 raise TypeError, 'wx.Image, wx.Bitmap or string expected'
d14a1e28 258}
c368d904
RD
259
260
d14a1e28
RD
261class wxMemoryFSHandler : public wxFileSystemHandler {
262public:
263 wxMemoryFSHandler();
264
265 // Remove file from memory FS and free occupied memory
266 static void RemoveFile(const wxString& filename);
267
268 // Add a file to the memory FS
269 %pythoncode { AddFile = staticmethod(MemoryFSHandler_AddFile) }
e2e2649f 270
d14a1e28 271 bool CanOpen(const wxString& location);
b87bfdb7 272 %newobject OpenFile;
d14a1e28
RD
273 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
274 wxString FindFirst(const wxString& spec, int flags = 0);
275 virtual wxString FindNext();
276};
9416aa89 277
d14a1e28
RD
278
279//---------------------------------------------------------------------------
9416aa89
RD
280%init %{
281 wxPyPtrTypeMap_Add("wxFileSystemHandler", "wxPyFileSystemHandler");
282%}
c368d904 283//---------------------------------------------------------------------------