]> git.saurik.com Git - wxWidgets.git/blame_incremental - wxPython/src/filesys.i
More unicode related cleanup and fixes for wxPython
[wxWidgets.git] / wxPython / src / filesys.i
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: filesys.i
3// Purpose: SWIG definitions of the wxFileSystem family of classes
4//
5// Author: Joerg Baumann and Robin Dunn
6//
7// Created: 25-Sept-2000
8// RCS-ID: $Id$
9// Copyright: (c) 2000 by Joerg Baumann
10// Licence: wxWindows license
11/////////////////////////////////////////////////////////////////////////////
12
13%module filesys
14
15%{
16#include "helpers.h"
17#include "pyistream.h"
18#include <wx/filesys.h>
19#include <wx/fs_inet.h>
20#include <wx/fs_mem.h>
21#include <wx/fs_zip.h>
22%}
23
24//----------------------------------------------------------------------
25
26%include typemaps.i
27%include my_typemaps.i
28
29// Import some definitions of other classes, etc.
30%import _defs.i
31%import utils.i
32%import image.i
33%import streams.i
34
35%pragma(python) code = "import wx"
36%pragma(python) code = "import string"
37
38//---------------------------------------------------------------------------
39
40
41class wxFSFile : public wxObject {
42public:
43 wxFSFile(wxInputStream *stream, const wxString& loc,
44 const wxString& mimetype, const wxString& anchor,
45 wxDateTime modif);
46
47 wxInputStream *GetStream();
48 const wxString& GetMimeType();
49 const wxString& GetLocation();
50 const wxString& GetAnchor();
51 wxDateTime GetModificationTime();
52};
53
54
55// clear typemaps
56%typemap(python,in) wxInputStream *stream;
57%typemap(python,out) wxInputStream *;
58
59
60//---------------------------------------------------------------------------
61
62%{
63// wxPyFileSystemHandler will be the Python class wxFileSystemHandler and handling
64// the callback functions
65class wxPyFileSystemHandler : public wxFileSystemHandler {
66public:
67 wxPyFileSystemHandler() : wxFileSystemHandler() {}
68
69 DEC_PYCALLBACK_BOOL_STRING_pure(CanOpen);
70 DEC_PYCALLBACK_FSF_FSSTRING_pure(OpenFile);
71 DEC_PYCALLBACK_STRING_STRINGINT_pure(FindFirst);
72 DEC_PYCALLBACK_STRING__pure(FindNext);
73
74 wxString GetProtocol(const wxString& location) {
75 return wxFileSystemHandler::GetProtocol(location);
76 }
77
78 wxString GetLeftLocation(const wxString& location) {
79 return wxFileSystemHandler::GetLeftLocation(location);
80 }
81
82 wxString GetAnchor(const wxString& location) {
83 return wxFileSystemHandler::GetAnchor(location);
84 }
85
86 wxString GetRightLocation(const wxString& location) {
87 return wxFileSystemHandler::GetRightLocation(location);
88 }
89
90 wxString GetMimeTypeFromExt(const wxString& location) {
91 return wxFileSystemHandler::GetMimeTypeFromExt(location);
92 }
93
94 PYPRIVATE;
95};
96
97
98IMP_PYCALLBACK_BOOL_STRING_pure(wxPyFileSystemHandler, wxFileSystemHandler, CanOpen);
99IMP_PYCALLBACK_FSF_FSSTRING_pure(wxPyFileSystemHandler, wxFileSystemHandler, OpenFile);
100IMP_PYCALLBACK_STRING_STRINGINT_pure(wxPyFileSystemHandler, wxFileSystemHandler, FindFirst);
101IMP_PYCALLBACK_STRING__pure(wxPyFileSystemHandler, wxFileSystemHandler, FindNext);
102%}
103
104
105%name(wxCPPFileSystemHandler)class wxFileSystemHandler : public wxObject {
106 wxFileSystemHandler();
107}
108
109%name(wxFileSystemHandler)class wxPyFileSystemHandler : public wxFileSystemHandler {
110public:
111 wxPyFileSystemHandler();
112
113 void _setCallbackInfo(PyObject* self, PyObject* _class);
114 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxFileSystemHandler)"
115
116 bool CanOpen(const wxString& location);
117 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
118 wxString FindFirst(const wxString& spec, int flags = 0);
119 wxString FindNext();
120
121 wxString GetProtocol(const wxString& location);
122 wxString GetLeftLocation(const wxString& location);
123 wxString GetAnchor(const wxString& location);
124 wxString GetRightLocation(const wxString& location) const;
125 wxString GetMimeTypeFromExt(const wxString& location);
126};
127
128//---------------------------------------------------------------------------
129
130class wxFileSystem : public wxObject {
131public:
132 wxFileSystem();
133
134 void ChangePathTo(const wxString& location, bool is_dir = FALSE);
135 wxString GetPath();
136
137 wxFSFile* OpenFile(const wxString& location);
138
139 wxString FindFirst(const wxString& spec, int flags = 0);
140 wxString FindNext();
141
142 static void AddHandler(wxFileSystemHandler *handler);
143 static void CleanUpHandlers();
144};
145
146//---------------------------------------------------------------------------
147
148class wxInternetFSHandler : public wxFileSystemHandler {
149public:
150 wxInternetFSHandler();
151 bool CanOpen(const wxString& location);
152 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
153};
154
155
156//---------------------------------------------------------------------------
157class wxZipFSHandler : public wxFileSystemHandler {
158public:
159 wxZipFSHandler();
160
161 bool CanOpen(const wxString& location);
162 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
163 wxString FindFirst(const wxString& spec, int flags = 0);
164 wxString FindNext();
165};
166
167//---------------------------------------------------------------------------
168
169class wxMemoryFSHandler : public wxFileSystemHandler {
170public:
171 wxMemoryFSHandler();
172
173 // Remove file from memory FS and free occupied memory
174 static void RemoveFile(const wxString& filename);
175
176 bool CanOpen(const wxString& location);
177 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
178 wxString FindFirst(const wxString& spec, int flags = 0);
179 virtual wxString FindNext();
180};
181
182
183// getting the overloaded static AddFile method right
184%inline %{
185void __wxMemoryFSHandler_AddFile_wxImage(const wxString& filename,
186 wxImage& image,
187 long type) {
188 wxMemoryFSHandler::AddFile(filename, image, type);
189}
190
191void __wxMemoryFSHandler_AddFile_wxBitmap(const wxString& filename,
192 const wxBitmap& bitmap,
193 long type) {
194 wxMemoryFSHandler::AddFile(filename, bitmap, type);
195}
196
197void __wxMemoryFSHandler_AddFile_Data(const wxString& filename,
198 PyObject* data) {
199
200 wxMemoryFSHandler::AddFile(filename,
201 // TODO: Verify data type
202 (void*)PyString_AsString(data),
203 (size_t)PyString_Size(data));
204}
205%}
206
207
208// case switch for overloading
209%pragma(python) code = "
210import types
211def wxMemoryFSHandler_AddFile(filename, a, b=''):
212 if isinstance(a, wxImage):
213 __wxMemoryFSHandler_AddFile_wxImage(filename, a, b)
214 elif isinstance(a, wxBitmap):
215 __wxMemoryFSHandler_AddFile_wxBitmap(filename, a, b)
216 elif type(a) == types.StringType:
217 #__wxMemoryFSHandler_AddFile_wxString(filename, a)
218 __wxMemoryFSHandler_AddFile_Data(filename, a)
219 else: raise TypeError, 'wxImage, wxBitmap or string expected'
220"
221
222
223//---------------------------------------------------------------------------
224
225%init %{
226 wxPyPtrTypeMap_Add("wxFileSystemHandler", "wxPyFileSystemHandler");
227%}
228
229//---------------------------------------------------------------------------