]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/docs/bin/pythonize_docs.py
   1 import sys
, os
, string
, glob
 
   3 from docparser
.wxclasses 
import * 
   4 from docparser
.wxhtmlparse 
import * 
   8 html_heading 
= "<H3><font color=\"red\">%s</font></H3>" 
  10 def 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") 
  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
) 
  27     methodnames 
= sortMethods(classname
, methods
.keys()) 
  29     for method 
in methodnames
: 
  30         page
.write("<A href=\"#%s\">%s</A></BR>" % (methods
[method
].getAnchorName(), method
)) 
  34     for method 
in methodnames
: 
  35         page
.write(methods
[method
].asHtml()) 
  39 def sortMethods(classname
, methodnames
): 
  42     # bump the constructor to the top of the list. 
  43     if classname 
in names
: 
  44         names
.remove(classname
) 
  45         names
.insert(0, classname
) 
  49 def makeDocString(name
, docstring
, longdocs
=""): 
  50     myname 
= name
.replace("wx.", "wx") 
  51     return "DocStr(%s, \"%s\", \"%s\");\n\n" % (myname
, docstring
, longdocs
) 
  53 def classToReST(name
, thisclass
): 
  55     page 
= open(os
.path
.join(restdir
, "_" + name 
+ "_docstrings.i"), "w") 
  56     page
.write(makeDocString(thisclass
.name
, thisclass
.description
)) 
  58     classname 
= namespacify_wxClasses(name
) 
  59     methodnames 
= sortMethods(classname
, thisclass
.methods
.keys()) 
  61     for method 
in methodnames
: 
  62         docstr 
= makeDocString(name 
+ "::" + method
.replace("wx.", "wx"), thisclass
.methods
[method
].asReST()) 
  68 docspath 
= sys
.argv
[1] 
  69 if not os
.path
.isdir(docspath
): 
  70     # get default directory 
  71     print "Please specify the directory where docs are located." 
  73 outdir 
= os
.path
.join(docspath
, outputdir
) 
  74 if not os
.path
.exists(outdir
): 
  77 restdir 
= os
.path
.join(docspath
, "docstrings") 
  78 if not os
.path
.exists(restdir
): 
  81 classes_page 
= os
.path
.join(docspath
, "wx_classref.html") 
  82 print "docspath: %s" % (classes_page
) 
  83 if os
.path
.exists(classes_page
): 
  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>") 
  89     propsfile 
= open(os
.path
.join(outdir
, "props.py"), "w") 
  90     propsfile
.write("import wx\n\n") 
  92     # now, change the classes. 
  93     print "parsing wx HTML docs..." 
  94     classes 
= getClasses(classes_page
) 
  95     names 
= classes
.keys() 
  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()) 
 109     output
.write("</BODY></HTML>") 
 112     print "prop conflicts: " + `propConflicts`
 
 114 #for doc in glob.glob(os.path.join(docspath, "wx_*.html")): 
 115 #    print "doc is: %s" % (doc)