forked from wxWidgets/Phoenix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilesys.py
133 lines (107 loc) · 4.84 KB
/
filesys.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#---------------------------------------------------------------------------
# Name: etg/filesys.py
# Author: Robin Dunn
#
# Created: 25-Feb-2012
# Copyright: (c) 2012-2017 by Total Control Software
# License: wxWindows License
#---------------------------------------------------------------------------
import etgtools
import etgtools.tweaker_tools as tools
PACKAGE = "wx"
MODULE = "_core"
NAME = "filesys" # Base name of the file to generate to for this script
DOCSTRING = ""
# The classes and/or the basename of the Doxygen XML files to be processed by
# this script.
ITEMS = [ "wxFileSystem",
"wxFSFile",
"wxFileSystemHandler",
"wxMemoryFSHandler",
"wxArchiveFSHandler",
"wxFilterFSHandler",
"wxInternetFSHandler",
]
#---------------------------------------------------------------------------
def run():
# Parse the XML file(s) building a collection of Extractor objects
module = etgtools.ModuleDef(PACKAGE, MODULE, NAME, DOCSTRING)
etgtools.parseDoxyXML(module, ITEMS)
#-----------------------------------------------------------------
# Tweak the parsed meta objects in the module object as needed for
# customizing the generated code and docstrings.
c = module.find('wxFileSystem')
assert isinstance(c, etgtools.ClassDef)
c.addPrivateCopyCtor()
c.find('AddHandler.handler').transfer = True
c.find('RemoveHandler').transferBack = True
c = module.find('wxFileSystemHandler')
c.find('GetAnchor').ignore(False)
c.find('GetLeftLocation').ignore(False)
c.find('GetProtocol').ignore(False)
c.find('GetRightLocation').ignore(False)
c.find('OpenFile').factory = True
def _fixHandlerClass(klass):
klass.addItem(etgtools.WigCode("""\
virtual bool CanOpen(const wxString& location);
virtual wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location) /Factory/;
virtual wxString FindFirst(const wxString& spec, int flags = 0);
virtual wxString FindNext();
"""))
c = module.find('wxArchiveFSHandler')
_fixHandlerClass(c)
c.addPrivateCopyCtor()
module.addPyCode('ZipFSHandler = wx.deprecated(ArchiveFSHandler, "Use ArchiveFSHandler instead.")')
c = module.find('wxFSFile')
c.addPrivateCopyCtor()
c.find('wxFSFile.stream').transfer = True
c.find('DetachStream').transferBack = True
c = module.find('wxFilterFSHandler')
_fixHandlerClass(c)
c.addPrivateCopyCtor()
c = module.find('wxInternetFSHandler')
_fixHandlerClass(c)
c.addPrivateCopyCtor()
c = module.find('wxMemoryFSHandler')
_fixHandlerClass(c)
c.addPrivateCopyCtor()
# Make some more python-friendly versions of the AddFile methods accepting text or raw data
c.find('AddFile').findOverload('textdata').ignore()
c.addCppMethod('void', 'AddFile', '(const wxString& filename, const wxString& textdata)',
isStatic=True,
doc="Add a file from text data, which will first be converted to utf-8 encoded bytes.",
body="""\
wxScopedCharBuffer buf = textdata->utf8_str();
wxMemoryFSHandler::AddFile(*filename, (const char*)buf, strlen(buf));
""")
c.find('AddFile').findOverload('binarydata').ignore()
c.addCppMethod('void', 'AddFile', '(const wxString& filename, wxPyBuffer* binarydata)',
isStatic=True,
doc="Add a file from raw data in a python buffer compatible object.",
body="""\
wxMemoryFSHandler::AddFile(*filename, binarydata->m_ptr, binarydata->m_len);
""")
c.find('AddFileWithMimeType').findOverload('textdata').ignore()
c.addCppMethod('void', 'AddFileWithMimeType',
'(const wxString& filename, const wxString& textdata, const wxString& mimetype)',
isStatic=True,
doc="Add a file from text data, which will first be converted to utf-8 encoded bytes.",
body="""\
wxScopedCharBuffer buf = textdata->utf8_str();
wxMemoryFSHandler::AddFileWithMimeType(*filename, (const char*)buf, strlen(buf), *mimetype);
""")
c.find('AddFileWithMimeType').findOverload('binarydata').ignore()
c.addCppMethod('void', 'AddFileWithMimeType',
'(const wxString& filename, wxPyBuffer* binarydata, const wxString& mimetype)',
isStatic=True,
doc="Add a file from raw data in a python buffer compatible object.",
body="""\
wxMemoryFSHandler::AddFileWithMimeType(
*filename, binarydata->m_ptr, binarydata->m_len, *mimetype);
""")
#-----------------------------------------------------------------
tools.doCommonTweaks(module)
tools.runGenerators(module)
#---------------------------------------------------------------------------
if __name__ == '__main__':
run()