Skip to content

Commit

Permalink
Re #6101. Added stub version of the fit function pages.
Browse files Browse the repository at this point in the history
  • Loading branch information
peterfpeterson committed Feb 27, 2013
1 parent 0df79b5 commit d6cd649
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 4 deletions.
50 changes: 50 additions & 0 deletions Code/Mantid/docs/qtassistant/fitfunctions_help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from lxml import etree as le # python-lxml on rpm based systems
import lxml.html
from lxml.html import builder as lhbuilder
import os

WEB_BASE = "http://www.mantidproject.org/"

def process_function(name, qhp, outputdir, **kwargs): # was (args, algo):
import mantid.api
func = mantid.api.FunctionFactory.createFunction(name)
#print "***", func, dir(func)

root = le.Element("html")
head = le.SubElement(root, "head")
head.append(lhbuilder.META(lhbuilder.TITLE(name + " Fit Function")))
body = le.SubElement(root, "body")
body.append(lhbuilder.CENTER(lhbuilder.H1(name + " Fit Function")))
text = '<a href="%s">wiki help</a>' % (WEB_BASE+name)
body.append(lxml.html.fragment_fromstring(text))
body.append(lhbuilder.HR())

body.append(lhbuilder.H3("Summary"))

body.append(lhbuilder.H3("Properties"))
table = le.SubElement(body, "table",
**{"border":"1", "cellpadding":"5", "cellspacing":"0"})
header_row = le.SubElement(table, "tr")
header_row.append(lhbuilder.TH("Order"))
header_row.append(lhbuilder.TH("Name"))
header_row.append(lhbuilder.TH("Default"))
header_row.append(lhbuilder.TH("Description"))
# TODO expose getting function properties to python so the table can be generated
#properties = func.getProperties()
#for (i, property) in zip(range(len(properties)), properties):
# propToHtml(table, property, i)

cats = []
for category in func.categories():
cats.append('<a href="fitfunctions_index.html#%s">%s</a>' % (category, category))
if len(cats) > 0:
text = '<p><b>Categories:</b> ' + " ".join(cats) + '</p>'
body.append(lxml.html.fragment_fromstring(text))

# write out the file
outfile = "FitFunc_%s.html" % name
qhp.addFile(outfile, name)
outfile = os.path.join(outputdir, outfile)
handle = open(outfile, 'w')
handle.write(le.tostring(root, pretty_print=True,
xml_declaration=False))
15 changes: 11 additions & 4 deletions Code/Mantid/docs/qtassistant/make_fitfunctions_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def addWikiDir(helpsrcdir):
sys.path.append(wikitoolsloc)

def genFuncElement(name):
text = '<a href="%s">%s</a>' % (WEB_BASE+name, name)
text = '<a href="FitFunc_%s.html">%s</a>' % (name, name)
return lxml.html.fragment_fromstring(text)

def processCategories(categories, qhp, outputdir):
Expand Down Expand Up @@ -62,10 +62,10 @@ def processCategories(categories, qhp, outputdir):
handle = open(filename, 'w')
handle.write(le.tostring(root, pretty_print=True, xml_declaration=False))

def process(functionsalgos, qhp, outputdir):
def process(functions, qhp, outputdir):
import mantid.api

# sort algorithms into categories
# sort fit functions into categories
categories = {}
for name in functions:
func = mantid.api.FunctionFactory.createFunction(name)
Expand All @@ -87,7 +87,9 @@ def process(functionsalgos, qhp, outputdir):
##### section for categories
div_cat = le.SubElement(body, "div", **{"id":"function_cats"})
for category in categories_list:
div_cat.append(lh.H2(category + " Category"))
temp = le.SubElement(div_cat, "h2")
le.SubElement(temp, 'a', **{"name":category})
temp.text = category + " Category"
ul = le.SubElement(div_cat, "ul")
funcs = categories[category]
for func in funcs:
Expand All @@ -101,6 +103,11 @@ def process(functionsalgos, qhp, outputdir):
shortname = os.path.split(filename)[1]
qhp.addFile(shortname, "Fit Functions Index")

# create individual html pages
from fitfunctions_help import process_function
for func in functions:
process_function(func, qhp, helpoutdir)

if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Generate qtassistant docs " \
+ "for the fit functions")
Expand Down

0 comments on commit d6cd649

Please sign in to comment.