9 "output_dir" : ("output", "Directory to output bindings to"),
10 "sip" : (True, "Produce SIP bindings"),
11 "swig" : (True, "Produce SWIG bindings."),
15 # format: class : {method : (prototype1, prototype2)}
16 # using a "*" means all prototypes
18 "wxIcon": {'wxIcon': (['const char', 'int', 'int'], )}
,
22 # these classes are either replaced by different data types in bindings, or have equivalent / better
23 # functionality provided by the target language.
25 "wxArchiveClassFactory",
27 "wxArchiveInputStream",
30 "wxArchiveOutputStream",
34 "wxBufferedInputStream",
35 "wxBufferedOutputStream",
44 "wxCountingOutputStream",
46 "wxCriticalSectionLocker",
55 "wxFFileOutputStream",
61 "wxFilterClassFactory",
62 "wxFilterInputStream",
63 "wxFilterOutputStream",
86 "wxMemoryInputStream",
87 "wxMemoryOutputStream",
88 "wxMessageQueue< T >",
93 "wxObjectDataPtr< T >",
101 "wxRecursionGuardFlag",
104 "wxScopedCharTypeBuffer",
113 "wxSocketInputStream",
114 "wxSocketOutputStream",
115 "wxSortedArrayString",
119 "wxStreamToTextRedirector",
122 "wxStringBufferLength",
123 "wxStringClientData",
124 "wxStringInputStream",
125 "wxStringOutputStream",
134 "wxTempFileOutputStream",
136 "wxTextOutputStream",
149 "wxVector< T >::reverse_iterator",
152 "wxWeakRefDynamic< T >",
156 "wxZlibOutputStream",
160 parser
= optparse
.OptionParser(usage
="usage: %prog <doxyml files to parse>\n" , version
="%prog 1.0")
162 for opt
in option_dict
:
163 default
= option_dict
[opt
][0]
166 if type(default
) == types
.BooleanType
:
167 action
= "store_true"
168 parser
.add_option("--" + opt
, default
=default
, action
=action
, dest
=opt
, help=option_dict
[opt
][1])
170 options
, arguments
= parser
.parse_args()
172 def get_first_value(alist
):
178 def make_enums(aclass
):
180 for enum
in aclass
.enums
:
181 retval
+= "enum %s {\n" % enum
182 num_values
= len(aclass
.enums
[enum
])
183 for value
in aclass
.enums
[enum
]:
184 retval
+= " %s" % value
185 if not value
== aclass
.enums
[enum
][-1]:
193 def __init__(self
, doxyparse
, outputdir
):
194 self
.doxyparser
= doxyparse
195 self
.output_dir
= outputdir
197 def make_bindings(self
):
198 output_dir
= os
.path
.abspath(os
.path
.join(self
.output_dir
, "sip"))
199 if not os
.path
.exists(output_dir
):
200 os
.makedirs(output_dir
)
202 for aclass
in self
.doxyparser
.classes
:
203 if aclass
.name
in excluded_classes
:
204 print "Skipping %s" % aclass
.name
207 header_name
= aclass
.name
[2:].lower()
208 filename
= os
.path
.join(output_dir
, header_name
+ ".sip")
209 enums_text
= make_enums(aclass
)
210 method_text
= self
.make_sip_methods(aclass
)
211 base_class
= get_first_value(aclass
.bases
)
213 base_class
= ": %s" % base_class
226 """ % (enums_text
, aclass
.name
, base_class
, get_first_value(aclass
.includes
), method_text
)
228 afile
= open(filename
, "wb")
233 def make_sip_methods(self
, aclass
):
236 for amethod
in aclass
.constructors
+ aclass
.methods
:
239 # we need to come up with a way of filtering the methods out by various criteria
240 # including parameters and method name, and how to deal with overloads
241 if aclass
.name
in ignored_methods
:
242 should_ignore
= False
243 for method
in ignored_methods
[aclass
.name
]:
244 print "method = %s" % method
245 if method
== amethod
.name
:
246 params
= ignored_methods
[aclass
.name
][method
]
248 for i
in xrange(len(params
)):
249 if i
>= len(amethod
.params
):
250 should_ignore
= False
252 elif amethod
.params
[i
]["type"] != params
[i
]:
253 print "param type = %s, amethod.param type = %s" % (params
[i
], amethod
.params
[i
]["type"])
254 should_ignore
= False
258 print "Ignoring method %s..." % amethod
.name
261 if amethod
in aclass
.constructors
and self
.doxyparser
.is_derived_from_base(aclass
, "wxWindow"):
262 transfer
= "/Transfer/"
264 if amethod
.name
.startswith("operator"):
267 retval
+= " %s %s%s%s;\n\n" % (amethod
.return_type
.replace("virtual ", ""), amethod
.name
, amethod
.argsstring
, transfer
)
274 def __init__(self
, doxyparse
, outputdir
):
275 self
.doxyparser
= doxyparse
276 self
.output_dir
= outputdir
278 def make_bindings(self
):
279 output_dir
= os
.path
.abspath(os
.path
.join(self
.output_dir
, "swig"))
280 if not os
.path
.exists(output_dir
):
281 os
.makedirs(output_dir
)
283 for aclass
in self
.doxyparser
.classes
:
284 header_name
= aclass
.name
[2:].lower()
285 if aclass
.name
in excluded_classes
:
286 #print "Skipping %s" % aclass.name
289 filename
= os
.path
.join(output_dir
, header_name
+ ".i")
290 enums_text
= make_enums(aclass
)
291 method_text
= self
.make_swig_methods(aclass
)
302 """ % (enums_text
, aclass
.name
, get_first_value(aclass
.bases
), method_text
)
304 afile
= open(filename
, "wb")
309 def make_swig_methods(self
, aclass
):
313 %%pythonAppend %s "self._setOORInfo(self)"
314 %%pythonAppend %s() ""
315 %%typemap(out) %s*; // turn off this typemap
316 """ % (aclass
.name
, aclass
.name
, aclass
.name
)
318 for amethod
in aclass
.constructors
:
319 retval
+= " %s%s;\n\n" % (amethod
.name
, amethod
.argsstring
)
322 // Turn it back on again
323 %%typemap(out) %s* { $result = wxPyMake_wxObject($1, $owner); }
326 for amethod
in aclass
.methods
:
327 retval
+= " %s %s%s;\n\n" % (amethod
.return_type
, amethod
.name
, amethod
.argsstring
)
332 if __name__
== "__main__":
333 if len(arguments
) < 1:
337 doxyparse
= doxymlparser
.DoxyMLParser()
338 for arg
in arguments
:
342 builder
= SIPBuilder(doxyparse
, options
.output_dir
)
343 builder
.make_bindings()
346 builder
= SWIGBuilder(doxyparse
, options
.output_dir
)
347 builder
.make_bindings()