]> git.lyx.org Git - lyx.git/blob - src/frontends/gnome/accessors.py
Minipage is no more (long live the box inset)
[lyx.git] / src / frontends / gnome / accessors.py
1 from xml.sax import *
2
3 import re, sys
4
5 ###
6 # Real name.  This RE distinguishes 'filler' widgets from the
7 # widgets we actually care about.
8 ###
9
10 rn = re.compile(r"^r_")
11
12
13 def cppClass(gladeClass):
14     gtk = re.compile(r"^Gtk")
15     gnome = re.compile(r"^Gnome")
16
17     if gtk.search(gladeClass):
18         return "Gtk::" + gladeClass[3:]
19     elif gnome.search(gladeClass):
20         return "Gnome::" + gladeClass[5:]
21
22 class widget:
23     def __init__(self, clss, name):
24         self.clss = cppClass(clss)
25         self.name = name
26
27     def getAccessor(self):
28         function = ""
29         function += self.clss + " * " + dialog +"::" + self.name
30         function += "() const \n{\n        return getWidget<" + self.clss
31         function +=  ">(\"" + "r_" + self.name + "\");\n}\n"
32
33         return function
34
35     def getDeclaration(self):
36         function = "/// generated by accessors.py\n"
37         function += self.clss + " * " + self.name
38         function += "() const;\n";
39
40         return function
41
42
43 class GnomeFrontendHandler(ContentHandler):
44
45     def __init__(self):
46
47         self.elemstack = []
48         self.widget = 0
49         self.TODO = []
50
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"])))
56
57     def endElement(self, name):
58         self.elemstack.pop()
59
60
61     def characters(self, data):
62
63         elem = self.elemstack[-1]
64
65     def widgets(self):
66         return self.TODO
67
68
69
70 dialog = sys.argv[2]
71 glade = open(sys.argv[1])
72
73
74 ## parse the document
75
76 prs = make_parser()
77 hndlr = GnomeFrontendHandler()
78 prs.setContentHandler(hndlr)
79 prs.parse(glade)
80
81 ## write the definitions to .C_gen
82
83 dotC = open(dialog + ".C_gen", "w+")
84
85 for i in hndlr.widgets():
86     dotC.write( i.getAccessor())
87
88 dotC.close()
89
90 ## write the declarations to .h_gen
91
92 dotH = open(dialog + ".h_gen", "w+")
93
94 for i in hndlr.widgets():
95     dotH.write( i.getDeclaration())
96
97 dotH.close()
98
99
100
101
102
103