Changeset 6592f56 in sasmodels


Ignore:
Timestamp:
Sep 12, 2016 1:37:18 AM (8 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
b217c71
Parents:
7b68dc5
Message:

view plugin model docs from sasview console

Location:
sasmodels
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/generate.py

    r52ec91e r6592f56  
    706706    Iq_units = "The returned value is scaled to units of |cm^-1| |sr^-1|, absolute scale." 
    707707    Sq_units = "The returned value is a dimensionless structure factor, $S(q)$." 
    708     docs = convert_section_titles_to_boldface(model_info.docs) 
     708    docs = model_info.docs if model_info.docs is not None else "" 
     709    docs = convert_section_titles_to_boldface(docs) 
    709710    pars = make_partable(model_info.parameters.COMMON 
    710711                         + model_info.parameters.kernel_parameters) 
     
    718719 
    719720 
     721# TODO: need a single source for rst_prolog; it is also in doc/rst_prolog 
     722RST_PROLOG = """\ 
     723.. |Ang| unicode:: U+212B 
     724.. |Ang^-1| replace:: |Ang|\ :sup:`-1` 
     725.. |Ang^2| replace:: |Ang|\ :sup:`2` 
     726.. |Ang^-2| replace:: |Ang|\ :sup:`-2` 
     727.. |1e-6Ang^-2| replace:: 10\ :sup:`-6`\ |Ang|\ :sup:`-2` 
     728.. |Ang^3| replace:: |Ang|\ :sup:`3` 
     729.. |Ang^-3| replace:: |Ang|\ :sup:`-3` 
     730.. |Ang^-4| replace:: |Ang|\ :sup:`-4` 
     731.. |cm^-1| replace:: cm\ :sup:`-1` 
     732.. |cm^2| replace:: cm\ :sup:`2` 
     733.. |cm^-2| replace:: cm\ :sup:`-2` 
     734.. |cm^3| replace:: cm\ :sup:`3` 
     735.. |1e15cm^3| replace:: 10\ :sup:`15`\ cm\ :sup:`3` 
     736.. |cm^-3| replace:: cm\ :sup:`-3` 
     737.. |sr^-1| replace:: sr\ :sup:`-1` 
     738.. |P0| replace:: P\ :sub:`0`\ 
     739 
     740.. |equiv| unicode:: U+2261 
     741.. |noteql| unicode:: U+2260 
     742.. |TM| unicode:: U+2122 
     743 
     744.. |cdot| unicode:: U+00B7 
     745.. |deg| unicode:: U+00B0 
     746.. |g/cm^3| replace:: g\ |cdot|\ cm\ :sup:`-3` 
     747.. |mg/m^2| replace:: mg\ |cdot|\ m\ :sup:`-2` 
     748.. |fm^2| replace:: fm\ :sup:`2` 
     749.. |Ang*cm^-1| replace:: |Ang|\ |cdot|\ cm\ :sup:`-1` 
     750""" 
     751 
     752# TODO: make a better fake reference role 
     753RST_ROLES = """\ 
     754.. role:: ref 
     755 
     756.. role:: numref 
     757 
     758""" 
     759 
    720760def make_html(model_info): 
    721761    """ 
     
    723763    """ 
    724764    from . import rst2html 
    725     return rst2html.convert(make_doc(model_info)) 
     765 
     766    rst = make_doc(model_info) 
     767    return rst2html.rst2html("".join((RST_ROLES, RST_PROLOG, rst))) 
     768 
     769def view_html(model_name): 
     770    from . import rst2html 
     771    from . import modelinfo 
     772    kernel_module = load_kernel_module(model_name) 
     773    info = modelinfo.make_model_info(kernel_module) 
     774    url = "file://"+dirname(info.filename)+"/" 
     775    rst2html.wxview(make_html(info), url=url) 
    726776 
    727777def demo_time(): 
  • sasmodels/rst2html.py

    r40a87fa r6592f56  
    1010from contextlib import contextmanager 
    1111 
     12# CRUFT: locale.getlocale() fails on some versions of OS X 
     13# See https://bugs.python.org/issue18378 
     14import locale 
     15if hasattr(locale, '_parse_localename'): 
     16    try: 
     17        locale._parse_localename('UTF-8') 
     18    except ValueError: 
     19        _old_parse_localename = locale._parse_localename 
     20        def _parse_localename(localename): 
     21            code = locale.normalize(localename) 
     22            if code == 'UTF-8': 
     23                return None, code 
     24            else: 
     25                return _old_parse_localename(localename) 
     26        locale._parse_localename = _parse_localename 
     27 
    1228from docutils.core import publish_parts 
    1329from docutils.writers.html4css1 import HTMLTranslator 
    1430from docutils.nodes import SkipNode 
    1531 
     32def wxview(html, url="", size=(850, 540)): 
     33    import wx 
     34    from wx.html2 import WebView 
     35    frame = wx.Frame(None, -1, size=size) 
     36    view = WebView.New(frame) 
     37    view.SetPage(html, url) 
     38    frame.Show() 
     39    return frame 
    1640 
    17 def rst2html(rst, part="whole", math_output="html"): 
     41def view_rst(filename): 
     42    from os.path import expanduser 
     43    with open(expanduser(filename)) as fid: 
     44        rst = fid.read() 
     45    html = rst2html(rst) 
     46    wxview(html) 
     47 
     48def rst2html(rst, part="whole", math_output="mathjax"): 
    1849    r""" 
    1950    Convert restructured text into simple html. 
     
    4475    else: 
    4576        settings = {"math-output": math_output} 
     77 
     78    # TODO: support stylesheets 
     79    #html_root = "/full/path/to/_static/" 
     80    #sheets = [html_root+s for s in ["basic.css","classic.css"]] 
     81    #settings["embed_styesheet"] = True 
     82    #settings["stylesheet_path"] = sheets 
    4683 
    4784    # math2html and mathml do not support \frac12 
Note: See TracChangeset for help on using the changeset viewer.