]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/_filesys.i
Trim trailing spaces from key names when parsing
[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
RD
28public:
29 wxFSFile(wxInputStream *stream, const wxString& loc,
30 const wxString& mimetype, const wxString& anchor,
31 wxDateTime modif);
d14a1e28 32 ~wxFSFile();
c368d904
RD
33
34 wxInputStream *GetStream();
35 const wxString& GetMimeType();
36 const wxString& GetLocation();
37 const wxString& GetAnchor();
38 wxDateTime GetModificationTime();
39};
40
41
c368d904
RD
42//---------------------------------------------------------------------------
43
44%{
d14a1e28
RD
45class wxPyFileSystemHandler : public wxFileSystemHandler
46{
c368d904
RD
47public:
48 wxPyFileSystemHandler() : wxFileSystemHandler() {}
49
50 DEC_PYCALLBACK_BOOL_STRING_pure(CanOpen);
51 DEC_PYCALLBACK_FSF_FSSTRING_pure(OpenFile);
52 DEC_PYCALLBACK_STRING_STRINGINT_pure(FindFirst);
53 DEC_PYCALLBACK_STRING__pure(FindNext);
54
55 wxString GetProtocol(const wxString& location) {
56 return wxFileSystemHandler::GetProtocol(location);
57 }
58
59 wxString GetLeftLocation(const wxString& location) {
60 return wxFileSystemHandler::GetLeftLocation(location);
61 }
62
63 wxString GetAnchor(const wxString& location) {
64 return wxFileSystemHandler::GetAnchor(location);
65 }
66
67 wxString GetRightLocation(const wxString& location) {
68 return wxFileSystemHandler::GetRightLocation(location);
69 }
70
e9159fe8 71 wxString GetMimeTypeFromExt(const wxString& location) {
c368d904
RD
72 return wxFileSystemHandler::GetMimeTypeFromExt(location);
73 }
74
75 PYPRIVATE;
76};
77
78
79IMP_PYCALLBACK_BOOL_STRING_pure(wxPyFileSystemHandler, wxFileSystemHandler, CanOpen);
80IMP_PYCALLBACK_FSF_FSSTRING_pure(wxPyFileSystemHandler, wxFileSystemHandler, OpenFile);
81IMP_PYCALLBACK_STRING_STRINGINT_pure(wxPyFileSystemHandler, wxFileSystemHandler, FindFirst);
82IMP_PYCALLBACK_STRING__pure(wxPyFileSystemHandler, wxFileSystemHandler, FindNext);
83%}
84
85
c368d904 86
d14a1e28
RD
87%name(CPPFileSystemHandler) class wxFileSystemHandler //: public wxObject
88{
89public:
90 //wxFileSystemHandler();
91};
92
93
94
95%name(FileSystemHandler) class wxPyFileSystemHandler : public wxFileSystemHandler
96{
c368d904 97public:
2b9048c5 98 %pythonAppend wxPyFileSystemHandler "self._setCallbackInfo(self, FileSystemHandler)";
d14a1e28 99
c368d904
RD
100 wxPyFileSystemHandler();
101
0122b7e3 102 void _setCallbackInfo(PyObject* self, PyObject* _class);
c368d904
RD
103
104 bool CanOpen(const wxString& location);
105 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
106 wxString FindFirst(const wxString& spec, int flags = 0);
107 wxString FindNext();
108
109 wxString GetProtocol(const wxString& location);
110 wxString GetLeftLocation(const wxString& location);
111 wxString GetAnchor(const wxString& location);
d14a1e28 112 wxString GetRightLocation(const wxString& location);
c368d904
RD
113 wxString GetMimeTypeFromExt(const wxString& location);
114};
115
d14a1e28
RD
116
117// //---------------------------------------------------------------------------
118
c368d904 119
9416aa89 120class wxFileSystem : public wxObject {
c368d904
RD
121public:
122 wxFileSystem();
d14a1e28 123 ~wxFileSystem();
c368d904 124
dd9f7fea 125 void ChangePathTo(const wxString& location, bool is_dir = False);
c368d904
RD
126 wxString GetPath();
127
128 wxFSFile* OpenFile(const wxString& location);
129
130 wxString FindFirst(const wxString& spec, int flags = 0);
131 wxString FindNext();
132
133 static void AddHandler(wxFileSystemHandler *handler);
134 static void CleanUpHandlers();
1e4a197e 135
dd116e73
RD
136 // Returns the file URL for a native path
137 static wxString FileNameToURL(const wxString& filename);
1e4a197e 138
dd116e73
RD
139 // Returns the native path for a file URL
140 //static wxFileName URLToFileName(const wxString& url); *** See below
c368d904
RD
141};
142
dd116e73
RD
143
144// Returns the native path for a file URL
145wxString wxFileSystem_URLToFileName(const wxString& url);
146%{
147 wxString wxFileSystem_URLToFileName(const wxString& url) {
148 wxFileName fname = wxFileSystem::URLToFileName(url);
149 return fname.GetFullPath();
150 }
151%}
152
d14a1e28 153
c368d904
RD
154//---------------------------------------------------------------------------
155
156class wxInternetFSHandler : public wxFileSystemHandler {
157public:
158 wxInternetFSHandler();
159 bool CanOpen(const wxString& location);
160 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
161};
162
163
164//---------------------------------------------------------------------------
d14a1e28 165
c368d904
RD
166class wxZipFSHandler : public wxFileSystemHandler {
167public:
168 wxZipFSHandler();
169
170 bool CanOpen(const wxString& location);
171 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
172 wxString FindFirst(const wxString& spec, int flags = 0);
173 wxString FindNext();
174};
175
176//---------------------------------------------------------------------------
177
d14a1e28 178// TODO: Use SWIG's overloading feature to fix this mess?
c368d904
RD
179
180// getting the overloaded static AddFile method right
181%inline %{
d14a1e28
RD
182 void __wxMemoryFSHandler_AddFile_wxImage(const wxString& filename,
183 wxImage& image,
184 long type) {
185 wxMemoryFSHandler::AddFile(filename, image, type);
186 }
c368d904 187
d14a1e28
RD
188 void __wxMemoryFSHandler_AddFile_wxBitmap(const wxString& filename,
189 const wxBitmap& bitmap,
190 long type) {
191 wxMemoryFSHandler::AddFile(filename, bitmap, type);
192 }
c368d904 193
d14a1e28
RD
194 void __wxMemoryFSHandler_AddFile_Data(const wxString& filename,
195 PyObject* data) {
196 wxMemoryFSHandler::AddFile(filename,
197 // TODO: Verify data type
198 (void*)PyString_AsString(data),
199 (size_t)PyString_Size(data));
200 }
c368d904
RD
201%}
202
203
204// case switch for overloading
d14a1e28
RD
205%pythoncode {
206def MemoryFSHandler_AddFile(filename, a, b=''):
207 if isinstance(a, wx.Image):
c368d904 208 __wxMemoryFSHandler_AddFile_wxImage(filename, a, b)
d14a1e28 209 elif isinstance(a, wx.Bitmap):
c368d904 210 __wxMemoryFSHandler_AddFile_wxBitmap(filename, a, b)
d14a1e28 211 elif type(a) == str:
c368d904 212 __wxMemoryFSHandler_AddFile_Data(filename, a)
d14a1e28
RD
213 else: raise TypeError, 'wx.Image, wx.Bitmap or string expected'
214}
c368d904
RD
215
216
d14a1e28
RD
217class wxMemoryFSHandler : public wxFileSystemHandler {
218public:
219 wxMemoryFSHandler();
220
221 // Remove file from memory FS and free occupied memory
222 static void RemoveFile(const wxString& filename);
223
224 // Add a file to the memory FS
225 %pythoncode { AddFile = staticmethod(MemoryFSHandler_AddFile) }
226
227 bool CanOpen(const wxString& location);
228 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
229 wxString FindFirst(const wxString& spec, int flags = 0);
230 virtual wxString FindNext();
231};
9416aa89 232
d14a1e28
RD
233
234//---------------------------------------------------------------------------
9416aa89
RD
235%init %{
236 wxPyPtrTypeMap_Add("wxFileSystemHandler", "wxPyFileSystemHandler");
237%}
c368d904 238//---------------------------------------------------------------------------