+ topnode = libxml2.parseFile(xmlfile).children
+
+ # remove any import nodes as we don't need to do renamers for symbols found therein
+ imports = topnode.xpathEval2("*/import")
+ for n in imports:
+ n.unlinkNode()
+ n.freeNode()
+
+ # do a depth first iteration over what's left
+ for node in topnode:
+ doRename = False
+ doPtr = False
+ addWX = False
+ revOnly = False
+
+
+ if node.name == "class":
+ lastClassName = name = GetAttr(node, "name")
+ lastClassSymName = sym_name = GetAttr(node, "sym_name")
+ doRename = True
+ doPtr = True
+ if sym_name != name:
+ name = sym_name
+ addWX = True
+
+ # renamed constructors
+ elif node.name == "constructor":
+ name = GetAttr(node, "name")
+ sym_name = GetAttr(node, "sym_name")
+ if sym_name != name:
+ name = sym_name
+ addWX = True
+ doRename = True
+
+ # only enumitems at the top level
+ elif node.name == "enumitem" and node.parent.parent.name == "include":
+ name = GetAttr(node, "name")
+ sym_name = GetAttr(node, "sym_name")
+ doRename = True
+
+
+ elif node.name in ["cdecl", "constant"]:
+ name = GetAttr(node, "name")
+ sym_name = GetAttr(node, "sym_name")
+ toplevel = node.parent.name == "include"
+
+ # top-level functions
+ if toplevel and GetAttr(node, "view") == "globalfunctionHandler":
+ doRename = True
+
+ # top-level global vars
+ elif toplevel and GetAttr(node, "feature_immutable") == "1":
+ doRename = True
+
+ # static methods
+ elif GetAttr(node, "view") == "staticmemberfunctionHandler":
+ name = lastClassName + '_' + name
+ sym_name = lastClassSymName + '_' + sym_name
+ # only output the reverse renamer in this case
+ doRename = revOnly = True
+
+ if doRename and name != sym_name:
+ name = sym_name
+ addWX = True
+
+
+ if doRename and name:
+ old = new = name
+ if old.startswith('wx') and not old.startswith('wxEVT_'):
+ # remove all wx prefixes except wxEVT_ and write a %rename directive for it
+ new = old[2:]
+ if not revOnly:
+ swigFile.write("%%rename(%s) %35s;\n" % (new, old))
+
+ # Write assignments to import into the old wxPython namespace
+ if addWX and not old.startswith('wx'):
+ old = 'wx'+old
+ pyFile.write("%s = wx.%s.%s\n" % (old, modname, new))
+ if doPtr:
+ pyFile.write("%sPtr = wx.%s.%sPtr\n" % (old, modname, new))
+