]> git.saurik.com Git - wxWidgets.git/blame - wxPython/docs/bin/pythonize_docs.py
No animate contrib anymore
[wxWidgets.git] / wxPython / docs / bin / pythonize_docs.py
CommitLineData
ce1245e1
RD
1import sys, os, string, glob
2import re
3from docparser.wxclasses import *
4from docparser.wxhtmlparse import *
5import wx
6
7# HTML macros
8html_heading = "<H3><font color=\"red\">%s</font></H3>"
9
10def classToHTML(name, thisclass):
11 global outdir, classes
12 page = open(os.path.join(outdir, "wx_" + name.lower() + ".html"), "w")
13 classname = namespacify_wxClasses(name)
14 page.write(thisclass.asHtml())
15 page.write("<HR>" + html_heading % "Methods")
16
17 methods = thisclass.methods
18 if len(thisclass.derivedFrom) > 0:
19 for parentclass in thisclass.derivedFrom:
20 classname = parentclass.replace("wx.", "wx")
21 if classname in classes.keys():
22 derivedmethods = classes[classname].methods
23 if parentclass in derivedmethods:
24 derivedmethods.pop(parentclass)
25 methods.update(derivedmethods)
26
27 methodnames = sortMethods(classname, methods.keys())
28
29 for method in methodnames:
30 page.write("<A href=\"#%s\">%s</A></BR>" % (methods[method].getAnchorName(), method))
31
32 page.write("<HR>")
33
34 for method in methodnames:
35 page.write(methods[method].asHtml())
36 page.write("<HR>")
37 page.close()
38
39def sortMethods(classname, methodnames):
40 names = methodnames
41 names.sort()
42 # bump the constructor to the top of the list.
43 if classname in names:
44 names.remove(classname)
45 names.insert(0, classname)
46
47 return names
48
49def makeDocString(name, docstring, longdocs=""):
50 myname = name.replace("wx.", "wx")
51 return "DocStr(%s, \"%s\", \"%s\");\n\n" % (myname, docstring, longdocs)
52
53def classToReST(name, thisclass):
54 global restdir
55 page = open(os.path.join(restdir, "_" + name + "_docstrings.i"), "w")
56 page.write(makeDocString(thisclass.name, thisclass.description))
57
58 classname = namespacify_wxClasses(name)
59 methodnames = sortMethods(classname, thisclass.methods.keys())
60
61 for method in methodnames:
62 docstr = makeDocString(name + "::" + method.replace("wx.", "wx"), thisclass.methods[method].asReST())
63 page.write(docstr)
64
65 page.close()
66
67
68docspath = sys.argv[1]
69if not os.path.isdir(docspath):
70 # get default directory
71 print "Please specify the directory where docs are located."
72
73outdir = os.path.join(docspath, outputdir)
74if not os.path.exists(outdir):
75 os.makedirs(outdir)
76
77restdir = os.path.join(docspath, "docstrings")
78if not os.path.exists(restdir):
79 os.makedirs(restdir)
80
81classes_page = os.path.join(docspath, "wx_classref.html")
82print "docspath: %s" % (classes_page)
83if os.path.exists(classes_page):
84
85 # first, add namespace conventions to classes page.
86 output = open(os.path.join(outdir, os.path.basename(classes_page)), "w")
87 output.write("<HTML><HEAD></HEAD><BODY>")
88
89 propsfile = open(os.path.join(outdir, "props.py"), "w")
90 propsfile.write("import wx\n\n")
91
92 # now, change the classes.
93 print "parsing wx HTML docs..."
94 classes = getClasses(classes_page)
95 names = classes.keys()
96 names.sort()
97 propConflicts = []
98 for name in names:
99 basename = name.replace("wx", "")
100 urlname = "wx_%s.html" % name.lower()
101 output.write("<b><a href=\"%s\">%s</a></b><br>" % (urlname, basename))
102 print "creating HTML docs for " + name
103 classToHTML(name, classes[name])
104 print "creating rest docs for " + name
105 classToReST(name, classes[name])
106 propsfile.write(classes[name].createProps())
107
108 propsfile.close()
109 output.write("</BODY></HTML>")
110 output.close()
111
112 print "prop conflicts: " + `propConflicts`
113
114#for doc in glob.glob(os.path.join(docspath, "wx_*.html")):
115# print "doc is: %s" % (doc)
116# pythonize_doc(doc)
117
118
119