]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/_filesys.i
Version
[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:
b87bfdb7
RD
29 %pythonAppend wxFSFile
30 "self.thisown = 0 # It will normally be deleted by the user of the wxFileSystem";
31
c368d904
RD
32 wxFSFile(wxInputStream *stream, const wxString& loc,
33 const wxString& mimetype, const wxString& anchor,
34 wxDateTime modif);
b87bfdb7
RD
35
36 ~wxFSFile();
c368d904
RD
37
38 wxInputStream *GetStream();
39 const wxString& GetMimeType();
40 const wxString& GetLocation();
41 const wxString& GetAnchor();
42 wxDateTime GetModificationTime();
43};
44
45
c368d904
RD
46//---------------------------------------------------------------------------
47
48%{
d14a1e28
RD
49class wxPyFileSystemHandler : public wxFileSystemHandler
50{
c368d904
RD
51public:
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
e9159fe8 75 wxString GetMimeTypeFromExt(const wxString& location) {
c368d904
RD
76 return wxFileSystemHandler::GetMimeTypeFromExt(location);
77 }
78
79 PYPRIVATE;
80};
81
82
83IMP_PYCALLBACK_BOOL_STRING_pure(wxPyFileSystemHandler, wxFileSystemHandler, CanOpen);
84IMP_PYCALLBACK_FSF_FSSTRING_pure(wxPyFileSystemHandler, wxFileSystemHandler, OpenFile);
85IMP_PYCALLBACK_STRING_STRINGINT_pure(wxPyFileSystemHandler, wxFileSystemHandler, FindFirst);
86IMP_PYCALLBACK_STRING__pure(wxPyFileSystemHandler, wxFileSystemHandler, FindNext);
87%}
88
89
c368d904 90
1b8c7ba6
RD
91%rename(CPPFileSystemHandler) wxFileSystemHandler;
92class wxFileSystemHandler //: public wxObject
d14a1e28
RD
93{
94public:
95 //wxFileSystemHandler();
96};
97
98
99
1b8c7ba6
RD
100%rename(FileSystemHandler) wxPyFileSystemHandler;
101class wxPyFileSystemHandler : public wxFileSystemHandler
d14a1e28 102{
c368d904 103public:
2b9048c5 104 %pythonAppend wxPyFileSystemHandler "self._setCallbackInfo(self, FileSystemHandler)";
d14a1e28 105
c368d904
RD
106 wxPyFileSystemHandler();
107
0122b7e3 108 void _setCallbackInfo(PyObject* self, PyObject* _class);
c368d904
RD
109
110 bool CanOpen(const wxString& location);
b87bfdb7 111 %newobject OpenFile;
c368d904
RD
112 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
113 wxString FindFirst(const wxString& spec, int flags = 0);
114 wxString FindNext();
115
116 wxString GetProtocol(const wxString& location);
117 wxString GetLeftLocation(const wxString& location);
118 wxString GetAnchor(const wxString& location);
d14a1e28 119 wxString GetRightLocation(const wxString& location);
c368d904
RD
120 wxString GetMimeTypeFromExt(const wxString& location);
121};
122
d14a1e28
RD
123
124// //---------------------------------------------------------------------------
125
c368d904 126
9416aa89 127class wxFileSystem : public wxObject {
c368d904
RD
128public:
129 wxFileSystem();
d14a1e28 130 ~wxFileSystem();
c368d904 131
a72f4631 132 void ChangePathTo(const wxString& location, bool is_dir = false);
c368d904
RD
133 wxString GetPath();
134
b87bfdb7 135 %newobject OpenFile;
c368d904
RD
136 wxFSFile* OpenFile(const wxString& location);
137
138 wxString FindFirst(const wxString& spec, int flags = 0);
139 wxString FindNext();
140
141 static void AddHandler(wxFileSystemHandler *handler);
142 static void CleanUpHandlers();
1e4a197e 143
dd116e73
RD
144 // Returns the file URL for a native path
145 static wxString FileNameToURL(const wxString& filename);
1e4a197e 146
dd116e73 147 // Returns the native path for a file URL
7e6581d4
RD
148 //static wxFileName URLToFileName(const wxString& url);
149 %extend {
150 static wxString URLToFileName(const wxString& url) {
151 wxFileName fname = wxFileSystem::URLToFileName(url);
152 return fname.GetFullPath();
153 }
154 }
c368d904
RD
155};
156
dd116e73 157
d14a1e28 158
c368d904
RD
159//---------------------------------------------------------------------------
160
161class wxInternetFSHandler : public wxFileSystemHandler {
162public:
163 wxInternetFSHandler();
164 bool CanOpen(const wxString& location);
b87bfdb7 165 %newobject OpenFile;
c368d904
RD
166 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
167};
168
169
170//---------------------------------------------------------------------------
d14a1e28 171
c368d904
RD
172class wxZipFSHandler : public wxFileSystemHandler {
173public:
174 wxZipFSHandler();
175
176 bool CanOpen(const wxString& location);
b87bfdb7 177 %newobject OpenFile;
c368d904
RD
178 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
179 wxString FindFirst(const wxString& spec, int flags = 0);
180 wxString FindNext();
181};
182
183//---------------------------------------------------------------------------
184
d14a1e28 185// TODO: Use SWIG's overloading feature to fix this mess?
c368d904
RD
186
187// getting the overloaded static AddFile method right
188%inline %{
d14a1e28
RD
189 void __wxMemoryFSHandler_AddFile_wxImage(const wxString& filename,
190 wxImage& image,
191 long type) {
192 wxMemoryFSHandler::AddFile(filename, image, type);
193 }
c368d904 194
d14a1e28
RD
195 void __wxMemoryFSHandler_AddFile_wxBitmap(const wxString& filename,
196 const wxBitmap& bitmap,
197 long type) {
198 wxMemoryFSHandler::AddFile(filename, bitmap, type);
199 }
c368d904 200
d14a1e28
RD
201 void __wxMemoryFSHandler_AddFile_Data(const wxString& filename,
202 PyObject* data) {
7e6581d4
RD
203 if (! PyString_Check(data)) {
204 wxPyBLOCK_THREADS(PyErr_SetString(PyExc_TypeError,
205 "Expected string object"));
206 return;
207 }
208
209 bool blocked = wxPyBeginBlockThreads();
210 void* ptr = (void*)PyString_AsString(data);
211 size_t size = PyString_Size(data);
212 wxPyEndBlockThreads(blocked);
213
214 wxMemoryFSHandler::AddFile(filename, ptr, size);
d14a1e28 215 }
c368d904
RD
216%}
217
218
219// case switch for overloading
d14a1e28 220%pythoncode {
7e6581d4
RD
221def MemoryFSHandler_AddFile(filename, dataItem, imgType=-1):
222 """
223 Add 'file' to the memory filesystem. The dataItem parameter can
224 either be a `wx.Bitmap`, `wx.Image` or a string that can contain
225 arbitrary data. If a bitmap or image is used then the imgType
226 parameter should specify what kind of image file it should be
227 written as, wx.BITMAP_TYPE_PNG, etc.
228 """
229 if isinstance(dataItem, wx.Image):
230 __wxMemoryFSHandler_AddFile_wxImage(filename, dataItem, imgType)
231 elif isinstance(dataItem, wx.Bitmap):
232 __wxMemoryFSHandler_AddFile_wxBitmap(filename, dataItem, imgType)
233 elif type(dataItem) == str:
234 __wxMemoryFSHandler_AddFile_Data(filename, dataItem)
235 else:
236 raise TypeError, 'wx.Image, wx.Bitmap or string expected'
d14a1e28 237}
c368d904
RD
238
239
d14a1e28
RD
240class wxMemoryFSHandler : public wxFileSystemHandler {
241public:
242 wxMemoryFSHandler();
243
244 // Remove file from memory FS and free occupied memory
245 static void RemoveFile(const wxString& filename);
246
247 // Add a file to the memory FS
248 %pythoncode { AddFile = staticmethod(MemoryFSHandler_AddFile) }
249
250 bool CanOpen(const wxString& location);
b87bfdb7 251 %newobject OpenFile;
d14a1e28
RD
252 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
253 wxString FindFirst(const wxString& spec, int flags = 0);
254 virtual wxString FindNext();
255};
9416aa89 256
d14a1e28
RD
257
258//---------------------------------------------------------------------------
9416aa89
RD
259%init %{
260 wxPyPtrTypeMap_Add("wxFileSystemHandler", "wxPyFileSystemHandler");
261%}
c368d904 262//---------------------------------------------------------------------------