]>
Commit | Line | Data |
---|---|---|
1 | import wx | |
2 | import restconvert | |
3 | html_heading = "<H3><font color=\"red\">%s</font></H3>" | |
4 | ||
5 | def stylesAsHtml(styles, extraStyles=False): | |
6 | heading = "Window styles" | |
7 | if extraStyles: | |
8 | heading = "Extra window styles" | |
9 | ||
10 | html = html_heading % heading | |
11 | html += """<table width="95%">""" | |
12 | for style in styles: | |
13 | html += "<tr><td>%s</td><td>%s</td>" % (style[0], style[1]) | |
14 | ||
15 | html += "</table>" | |
16 | ||
17 | return html | |
18 | ||
19 | class wxClass: | |
20 | def __init__(self, name, description="", derivedFrom=[], styles=[], extrastyles=[]): | |
21 | self.name = name | |
22 | self.description = description | |
23 | self.derivedFrom = derivedFrom | |
24 | self.styles = styles | |
25 | self.extrastyles = extrastyles | |
26 | self.methods = {} | |
27 | self.propConflicts = [] | |
28 | self.props = [] | |
29 | ||
30 | def asHtml(self): | |
31 | html = "<H1>%s</H1>" % self.name | |
32 | html += self.description | |
33 | if len(self.derivedFrom) > 0: | |
34 | html += html_heading % "Derived from" | |
35 | for der in self.derivedFrom: | |
36 | derurl = der.replace("wx.", "wx").lower() | |
37 | html += "<a href=\"wx_%s.html\">%s</a></br>" % (derurl, der) | |
38 | ||
39 | if len(self.styles) > 0: | |
40 | html += stylesAsHtml(self.styles) | |
41 | ||
42 | if len(self.extrastyles) > 0: | |
43 | html += stylesAsHtml(self.extrastyles, extraStyles=True) | |
44 | ||
45 | return html | |
46 | ||
47 | def asReST(self): | |
48 | restText = "DocStr(%s,\n" % (self.name) | |
49 | ||
50 | restText += ");" | |
51 | return restText | |
52 | ||
53 | def createProps(self): | |
54 | propsText = "" | |
55 | propList = self.props | |
56 | for conflict in self.propConflicts: | |
57 | if conflict in propList: | |
58 | propList.remove(conflict) | |
59 | ||
60 | basename = self.name.replace("wx", "") | |
61 | for prop in propList: | |
62 | if prop != "": | |
63 | propname = prop | |
64 | if propname[0] == "3": | |
65 | propname = "Three" + propname[1:] | |
66 | ||
67 | getter = "wx.%s.Get%s" % (basename, prop) | |
68 | setter = "wx.%s.Set%s" % (basename, prop) | |
69 | propsText += "wx.%s.%s = property(%s" % (basename, propname, getter) | |
70 | hasSetter = eval("(\"%s\" in dir(wx.%s))" % ("Set" + prop, basename)) | |
71 | if hasSetter: | |
72 | propsText += ", %s" % setter | |
73 | propsText += ")\n" | |
74 | ||
75 | if propsText != "": | |
76 | propsText += "\n\n" | |
77 | ||
78 | return propsText | |
79 | ||
80 | class wxMethod: | |
81 | def __init__(self, name, parent, prototypes=[], params={}, description="", remarks=""): | |
82 | self.name = name | |
83 | self.parent = parent | |
84 | self.prototypes = prototypes | |
85 | self.params = params | |
86 | self.description = description | |
87 | self.remarks = remarks | |
88 | self.pythonNote = "" | |
89 | self.pythonOverrides = [] | |
90 | ||
91 | def asReST(self): | |
92 | restText = "" | |
93 | ||
94 | # The below code converts prototypes into ReST, but currently isn't | |
95 | # needed. Left here in case we change approach later. | |
96 | ||
97 | #for proto in self.prototypes: | |
98 | # restText += proto[1] + "(" | |
99 | # counter = 1 | |
100 | # for arg in proto[2]: | |
101 | # restText += "%s %s" % (arg[0].replace("wx.", ""), arg[1]) | |
102 | # if counter < len(proto[2]): | |
103 | # restText += ", " | |
104 | # counter += 1 | |
105 | # if proto[0] != "": | |
106 | # restText += "-> " + proto[0] | |
107 | # restText += "\n" | |
108 | #restText += "\n" | |
109 | ||
110 | if len(self.params) > 0: | |
111 | ||
112 | for param in self.params: | |
113 | restText += "\n:param %s: %s" % (param[0], restconvert.htmlToReST(param[1])) | |
114 | restText += "\n\n" | |
115 | ||
116 | restText += restconvert.htmlToReST(self.description.strip()) | |
117 | return restText | |
118 | ||
119 | def asHtml(self): | |
120 | anchorname = self.getAnchorName() | |
121 | retval = "<A name=\"%s\"></A>" % (anchorname) | |
122 | retval += "<H3>%s</H3>" % self.name | |
123 | if len(self.pythonOverrides) > 0: | |
124 | for myfunc in self.pythonOverrides: | |
125 | retval += "<p><b>%s</b></br>%s</p>" % (myfunc[0], myfunc[1]) | |
126 | else: | |
127 | for proto in self.prototypes: | |
128 | retval += "<P><B>" | |
129 | if proto[0] != "": | |
130 | retval += proto[0] + " " | |
131 | retval += proto[1] + "(" | |
132 | counter = 1 | |
133 | for arg in proto[2]: | |
134 | retval += "%s <i>%s</i>" % (arg[0], arg[1]) | |
135 | if counter < len(proto[2]): | |
136 | retval += ", " | |
137 | counter += 1 | |
138 | retval += ")</B></P>" | |
139 | ||
140 | if len(self.params) > 0: | |
141 | retval += "<table width=\"90%%\" cellspacing=\"10\">" | |
142 | for param in self.params: | |
143 | retval += "<tr><td align=\"right\"><i>%s</i></td><td bgcolor=\"#E3E3E3\">%s</td></tr>" % (param[0], param[1]) | |
144 | retval += "</table>" | |
145 | ||
146 | retval += "<p>%s</p>" % self.description | |
147 | ||
148 | if self.remarks != "": | |
149 | retval += "<font color=\"red\">Remarks</font><h4>%s</h4></font>" % self.remarks | |
150 | ||
151 | return retval | |
152 | ||
153 | def getAnchorName(self): | |
154 | anchorname = self.parent.name.lower() + self.name.lower() | |
155 | if self.parent.name == self.name: | |
156 | anchorname = self.name.lower() | |
157 | ||
158 | return anchorname | |
159 | ||
160 | def asString(self): | |
161 | retval = "method: " + self.name | |
162 | retval += "\n\nprototypes: " | |
163 | for proto in self.prototypes: | |
164 | retval += "\t%s" % `proto` | |
165 | retval += "\n\nparams: " | |
166 | for param in self.params: | |
167 | retval += "%s: %s" % (param, self.params[param]) | |
168 | ||
169 | retval += "\n\ndescription: \n" + self.description | |
170 | ||
171 | retval += "remarks: \n" + self.remarks | |
172 | ||
173 | return retval |