swig_tools.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import os
  2. from common import *
  3. class SWIGBuilder:
  4. def __init__(self, doxyparse, outputdir):
  5. self.doxyparser = doxyparse
  6. self.output_dir = outputdir
  7. def make_bindings(self):
  8. output_dir = os.path.abspath(os.path.join(self.output_dir, "swig"))
  9. if not os.path.exists(output_dir):
  10. os.makedirs(output_dir)
  11. for aclass in self.doxyparser.classes:
  12. header_name = aclass.name[2:].lower()
  13. if aclass.name in excluded_classes:
  14. #print "Skipping %s" % aclass.name
  15. continue
  16. filename = os.path.join(output_dir, "_" + header_name + ".i")
  17. enums_text = make_enums(aclass)
  18. method_text = self.make_swig_methods(aclass)
  19. text = """
  20. %%newgroup
  21. %s
  22. class %s : publib %s
  23. {
  24. public:
  25. %s
  26. };
  27. """ % (enums_text, aclass.name, get_first_value(aclass.bases), method_text)
  28. afile = open(filename, "wb")
  29. afile.write(text)
  30. afile.close()
  31. def make_swig_methods(self, aclass):
  32. retval = ""
  33. retval += """
  34. %%pythonAppend %s "self._setOORInfo(self)"
  35. %%pythonAppend %s() ""
  36. %%typemap(out) %s*; // turn off this typemap
  37. """ % (aclass.name, aclass.name, aclass.name)
  38. for amethod in aclass.constructors:
  39. retval += " %s%s;\n\n" % (amethod.name, amethod.argsstring)
  40. retval += """
  41. // Turn it back on again
  42. %%typemap(out) %s* { $result = wxPyMake_wxObject($1, $owner); }
  43. """ % aclass.name
  44. for amethod in aclass.methods:
  45. retval += " %s %s%s;\n\n" % (amethod.return_type, amethod.name, amethod.argsstring)
  46. return retval