6 # Real name. This RE distinguishes 'filler' widgets from the
7 # widgets we actually care about.
10 rn = re.compile(r"^r_")
13 def cppClass(gladeClass):
14 gtk = re.compile(r"^Gtk")
15 gnome = re.compile(r"^Gnome")
17 if gtk.search(gladeClass):
18 return "Gtk::" + gladeClass[3:]
19 elif gnome.search(gladeClass):
20 return "Gnome::" + gladeClass[5:]
23 def __init__(self, clss, name):
24 self.clss = cppClass(clss)
27 def getAccessor(self):
29 function += self.clss + " * " + dialog +"::" + self.name
30 function += "() const \n{\n return getWidget<" + self.clss
31 function += ">(\"" + "r_" + self.name + "\");\n}\n"
35 def getDeclaration(self):
36 function = "/// generated by accessors.py\n"
37 function += self.clss + " * " + self.name
38 function += "() const;\n";
43 class GnomeFrontendHandler(ContentHandler):
51 def startElement(self, name, attrs):
52 self.elemstack.append(name)
53 if name == "widget" and rn.search(attrs["id"]):
54 self.TODO.append(widget(attrs["class"],
55 re.sub("^r_", "", attrs["id"])))
57 def endElement(self, name):
61 def characters(self, data):
63 elem = self.elemstack[-1]
71 glade = open(sys.argv[1])
77 hndlr = GnomeFrontendHandler()
78 prs.setContentHandler(hndlr)
81 ## write the definitions to .C_gen
83 dotC = open(dialog + ".C_gen", "w+")
85 for i in hndlr.widgets():
86 dotC.write( i.getAccessor())
90 ## write the declarations to .h_gen
92 dotH = open(dialog + ".h_gen", "w+")
94 for i in hndlr.widgets():
95 dotH.write( i.getDeclaration())