]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/_filesys.i
fixed selection when using keyboard after JS' change broke it
[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();
76b8fa1d
RD
41 void DetachStream();
42
c368d904
RD
43 const wxString& GetMimeType();
44 const wxString& GetLocation();
45 const wxString& GetAnchor();
46 wxDateTime GetModificationTime();
42e2bbb9
RD
47
48 %property(Anchor, GetAnchor, doc="See `GetAnchor`");
49 %property(Location, GetLocation, doc="See `GetLocation`");
50 %property(MimeType, GetMimeType, doc="See `GetMimeType`");
51 %property(ModificationTime, GetModificationTime, doc="See `GetModificationTime`");
52 %property(Stream, GetStream, doc="See `GetStream`");
53
c368d904
RD
54};
55
56
c368d904
RD
57//---------------------------------------------------------------------------
58
59%{
d14a1e28
RD
60class wxPyFileSystemHandler : public wxFileSystemHandler
61{
c368d904
RD
62public:
63 wxPyFileSystemHandler() : wxFileSystemHandler() {}
64
65 DEC_PYCALLBACK_BOOL_STRING_pure(CanOpen);
66 DEC_PYCALLBACK_FSF_FSSTRING_pure(OpenFile);
67 DEC_PYCALLBACK_STRING_STRINGINT_pure(FindFirst);
68 DEC_PYCALLBACK_STRING__pure(FindNext);
69
70 wxString GetProtocol(const wxString& location) {
71 return wxFileSystemHandler::GetProtocol(location);
72 }
73
74 wxString GetLeftLocation(const wxString& location) {
75 return wxFileSystemHandler::GetLeftLocation(location);
76 }
77
78 wxString GetAnchor(const wxString& location) {
79 return wxFileSystemHandler::GetAnchor(location);
80 }
81
82 wxString GetRightLocation(const wxString& location) {
83 return wxFileSystemHandler::GetRightLocation(location);
84 }
85
e9159fe8 86 wxString GetMimeTypeFromExt(const wxString& location) {
c368d904
RD
87 return wxFileSystemHandler::GetMimeTypeFromExt(location);
88 }
89
90 PYPRIVATE;
91};
92
93
94IMP_PYCALLBACK_BOOL_STRING_pure(wxPyFileSystemHandler, wxFileSystemHandler, CanOpen);
95IMP_PYCALLBACK_FSF_FSSTRING_pure(wxPyFileSystemHandler, wxFileSystemHandler, OpenFile);
96IMP_PYCALLBACK_STRING_STRINGINT_pure(wxPyFileSystemHandler, wxFileSystemHandler, FindFirst);
97IMP_PYCALLBACK_STRING__pure(wxPyFileSystemHandler, wxFileSystemHandler, FindNext);
98%}
99
100
c368d904 101
1b8c7ba6
RD
102%rename(CPPFileSystemHandler) wxFileSystemHandler;
103class wxFileSystemHandler //: public wxObject
d14a1e28
RD
104{
105public:
106 //wxFileSystemHandler();
cdd7b180 107 ~wxFileSystemHandler();
d14a1e28
RD
108};
109
110
111
1b8c7ba6
RD
112%rename(FileSystemHandler) wxPyFileSystemHandler;
113class wxPyFileSystemHandler : public wxFileSystemHandler
d14a1e28 114{
c368d904 115public:
2b9048c5 116 %pythonAppend wxPyFileSystemHandler "self._setCallbackInfo(self, FileSystemHandler)";
e2e2649f 117
c368d904
RD
118 wxPyFileSystemHandler();
119
0122b7e3 120 void _setCallbackInfo(PyObject* self, PyObject* _class);
c368d904
RD
121
122 bool CanOpen(const wxString& location);
b87bfdb7 123 %newobject OpenFile;
c368d904
RD
124 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
125 wxString FindFirst(const wxString& spec, int flags = 0);
126 wxString FindNext();
127
128 wxString GetProtocol(const wxString& location);
129 wxString GetLeftLocation(const wxString& location);
130 wxString GetAnchor(const wxString& location);
d14a1e28 131 wxString GetRightLocation(const wxString& location);
c368d904 132 wxString GetMimeTypeFromExt(const wxString& location);
42e2bbb9
RD
133
134 %property(Anchor, GetAnchor, doc="See `GetAnchor`");
135 %property(LeftLocation, GetLeftLocation, doc="See `GetLeftLocation`");
136 %property(MimeTypeFromExt, GetMimeTypeFromExt, doc="See `GetMimeTypeFromExt`");
137 %property(Protocol, GetProtocol, doc="See `GetProtocol`");
138 %property(RightLocation, GetRightLocation, doc="See `GetRightLocation`");
c368d904
RD
139};
140
d14a1e28
RD
141
142// //---------------------------------------------------------------------------
143
c368d904 144
9416aa89 145class wxFileSystem : public wxObject {
c368d904
RD
146public:
147 wxFileSystem();
d14a1e28 148 ~wxFileSystem();
c368d904 149
a72f4631 150 void ChangePathTo(const wxString& location, bool is_dir = false);
c368d904
RD
151 wxString GetPath();
152
b87bfdb7 153 %newobject OpenFile;
c368d904
RD
154 wxFSFile* OpenFile(const wxString& location);
155
156 wxString FindFirst(const wxString& spec, int flags = 0);
157 wxString FindNext();
158
cdd7b180 159 %disownarg(wxFileSystemHandler *handler);
c368d904 160 static void AddHandler(wxFileSystemHandler *handler);
cdd7b180 161 %cleardisown(wxFileSystemHandler *handler);
e2e2649f 162
76b8fa1d
RD
163 // Removes FS handler
164 %newobject RemoveHandler;
165 static wxFileSystemHandler* RemoveHandler(wxFileSystemHandler *handler);
166
c368d904 167 static void CleanUpHandlers();
1e4a197e 168
dd116e73
RD
169 // Returns the file URL for a native path
170 static wxString FileNameToURL(const wxString& filename);
1e4a197e 171
dd116e73 172 // Returns the native path for a file URL
7e6581d4
RD
173 //static wxFileName URLToFileName(const wxString& url);
174 %extend {
175 static wxString URLToFileName(const wxString& url) {
176 wxFileName fname = wxFileSystem::URLToFileName(url);
177 return fname.GetFullPath();
178 }
e2e2649f 179 }
42e2bbb9
RD
180
181 %property(Path, GetPath, doc="See `GetPath`");
c368d904
RD
182};
183
dd116e73 184
d14a1e28 185
c368d904
RD
186//---------------------------------------------------------------------------
187
188class wxInternetFSHandler : public wxFileSystemHandler {
189public:
190 wxInternetFSHandler();
191 bool CanOpen(const wxString& location);
b87bfdb7 192 %newobject OpenFile;
c368d904
RD
193 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
194};
195
196
197//---------------------------------------------------------------------------
d14a1e28 198
c368d904
RD
199class wxZipFSHandler : public wxFileSystemHandler {
200public:
201 wxZipFSHandler();
202
203 bool CanOpen(const wxString& location);
b87bfdb7 204 %newobject OpenFile;
c368d904
RD
205 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
206 wxString FindFirst(const wxString& spec, int flags = 0);
207 wxString FindNext();
208};
209
210//---------------------------------------------------------------------------
211
d14a1e28 212// TODO: Use SWIG's overloading feature to fix this mess?
c368d904
RD
213
214// getting the overloaded static AddFile method right
215%inline %{
d14a1e28
RD
216 void __wxMemoryFSHandler_AddFile_wxImage(const wxString& filename,
217 wxImage& image,
218 long type) {
219 wxMemoryFSHandler::AddFile(filename, image, type);
220 }
c368d904 221
d14a1e28
RD
222 void __wxMemoryFSHandler_AddFile_wxBitmap(const wxString& filename,
223 const wxBitmap& bitmap,
224 long type) {
225 wxMemoryFSHandler::AddFile(filename, bitmap, type);
226 }
c368d904 227
d14a1e28
RD
228 void __wxMemoryFSHandler_AddFile_Data(const wxString& filename,
229 PyObject* data) {
7e6581d4
RD
230 if (! PyString_Check(data)) {
231 wxPyBLOCK_THREADS(PyErr_SetString(PyExc_TypeError,
232 "Expected string object"));
233 return;
234 }
235
6e6b3557 236 wxPyBlock_t blocked = wxPyBeginBlockThreads();
7e6581d4
RD
237 void* ptr = (void*)PyString_AsString(data);
238 size_t size = PyString_Size(data);
239 wxPyEndBlockThreads(blocked);
240
241 wxMemoryFSHandler::AddFile(filename, ptr, size);
d14a1e28 242 }
c368d904
RD
243%}
244
245
246// case switch for overloading
d14a1e28 247%pythoncode {
7e6581d4
RD
248def MemoryFSHandler_AddFile(filename, dataItem, imgType=-1):
249 """
250 Add 'file' to the memory filesystem. The dataItem parameter can
251 either be a `wx.Bitmap`, `wx.Image` or a string that can contain
252 arbitrary data. If a bitmap or image is used then the imgType
253 parameter should specify what kind of image file it should be
254 written as, wx.BITMAP_TYPE_PNG, etc.
255 """
256 if isinstance(dataItem, wx.Image):
257 __wxMemoryFSHandler_AddFile_wxImage(filename, dataItem, imgType)
258 elif isinstance(dataItem, wx.Bitmap):
259 __wxMemoryFSHandler_AddFile_wxBitmap(filename, dataItem, imgType)
260 elif type(dataItem) == str:
261 __wxMemoryFSHandler_AddFile_Data(filename, dataItem)
262 else:
263 raise TypeError, 'wx.Image, wx.Bitmap or string expected'
d14a1e28 264}
c368d904
RD
265
266
d14a1e28
RD
267class wxMemoryFSHandler : public wxFileSystemHandler {
268public:
269 wxMemoryFSHandler();
270
271 // Remove file from memory FS and free occupied memory
272 static void RemoveFile(const wxString& filename);
273
274 // Add a file to the memory FS
275 %pythoncode { AddFile = staticmethod(MemoryFSHandler_AddFile) }
e2e2649f 276
d14a1e28 277 bool CanOpen(const wxString& location);
b87bfdb7 278 %newobject OpenFile;
d14a1e28
RD
279 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
280 wxString FindFirst(const wxString& spec, int flags = 0);
281 virtual wxString FindNext();
282};
9416aa89 283
d14a1e28
RD
284
285//---------------------------------------------------------------------------
9416aa89
RD
286%init %{
287 wxPyPtrTypeMap_Add("wxFileSystemHandler", "wxPyFileSystemHandler");
288%}
c368d904 289//---------------------------------------------------------------------------