Package doconce :: Module DocWriter
[hide private]
[frames] | no frames]

Module DocWriter

source code

DocWriter is a tool for writing documents in ASCII, HTML, LaTeX, Doconce, and other formats based on input from Python datastructures.

The base class _BaseWriter defines common functions and data structures, while subclasses HTML, Doconce, etc. implement (i.e., write to) various formats.

This module works, but is unifinished and needs documentation!

Classes [hide private]
  _BaseWriter
Base class for document writing classes.
  Doconce
  HTML
  LaTeX
  DocWriter
DocWriter can write documents in several formats at once.
Functions [hide private]
 
makedocstr(parent_class, subclass_method)
Compose a string (to be used as doc string) from a method's doc string in a parent class and an additional doc string in a subclass version of the method.
source code
 
func_to_method(func, class_, method_name=None) source code
 
html_movie(plotfiles, interval_ms=300, width=800, height=600, casename='movie')
Takes a list plotfiles which should be for example of the form:
source code
 
html_movie_embed(moviefile, width=400, height=400)
Return HTML for embedding a moviefile using the default handling of such files.
source code
 
html_movie_embed_wmp(moviefile, width=400, height=400)
Return HTML text for embedding a movie file (Windows Media Player code).
source code
 
html_movie_embed_qt(moviefile, width=400, height=400)
Return HTML for embedding a moviefile (QuickTime code).
source code
 
_test(d) source code
 
_figure(self, filename, caption, width=None, height=None, label=None)
Insert a figure into the document.
source code
 
_link(self, link_text, link_target)
Typeset a hyperlink.
source code
 
_list(self, items, listtype='itemize')
Write list or nested lists.
source code
 
_math(self, text)
Write block of mathematical text (equations).
source code
 
_paragraph(self, title, ending='.', label=None)
Write a paragraph heading with the given title and an ending (period, question mark, colon) and an optional label (for navigation).
source code
 
_paragraph_separator(self)
Add a (space) separator between running paragraphs.
source code
 
_raw(self, text)
Write text directly 'as is' to output.
source code
 
_section(self, title, label=None)
Write a section heading with the given title and an optional label (for navigation).
source code
 
_subsection(self, title, label=None)
Write a subsection heading with the given title and an optional label (for navigation).
source code
 
_subsubsection(self, title, label=None)
Write a subsubsection heading with the given title and an optional label (for navigation).
source code
 
_table(self, table, column_headline_pos='c', column_pos='c')
Translates a two-dimensional list of data, containing strings or numbers, to a suitable "tabular" environment in the output.
source code
 
_text(self, text, indent=0)
Write plain text.
source code
 
_title(self, title, authors_and_institutions=[], date='today')
Provide title and authors.
source code
 
_url(self, url_address, link_text=None)
Typeset an URL (with an optional link).
source code
 
_verbatim(self, code)
Write verbatim text in fixed-width form (typically for computer code).
source code
 
_write_to_file(self, filename)
Write formatted document to a file.
source code
Variables [hide private]
  inline_tag_begin = '(?P<begin>(^|[(\\s]))'
  inline_tag_end = '(?P<end>($|[.,?!;:)\\s]))'
  INLINE_TAGS = {'bold': '(?P<begin>(^|[(\\s]))_(?P<subst>[^ `][...
  __package__ = 'doconce'
  a = ArgSpec(args=['self', 'table', 'column_headline_pos', 'col...
  allargs = ['self', 'table', 'column_headline_pos=\'c\'', 'colu...
  arg = 'column_pos'
  args = ['self', 'table']
  code = 'def _table(self, table, column_headline_pos=\'c\', col...
  docstring = '\n Translates a two-dimensional list of da...
  kwargs = ['column_headline_pos=\'c\'', 'column_pos=\'c\'']
  method = 'table'
  signature_call = 'table(table, column_headline_pos, column_pos)'
  signature_def = 'table(self, table, column_headline_pos=\'c\',...
  value = 'c'
Function Details [hide private]

makedocstr(parent_class, subclass_method)

source code 

Compose a string (to be used as doc string) from a method's doc string in a parent class and an additional doc string in a subclass version of the method.

Parameters:
  • parent_class - class object for parent class.
  • subclass_method - method object for subclass.
Returns:
parent_class.method.__doc__ + subclass_method.__doc__

html_movie(plotfiles, interval_ms=300, width=800, height=600, casename='movie')

source code 

Takes a list plotfiles which should be for example of the form:

   ['frame00.png', 'frame01.png', ... ]

where each string should be the name of an image file and they should be in the proper order for viewing as an animation.

The result is html text strings that incorporate javascript to loop through the plots one after another. The html text also features buttons for controlling the movie. The parameter iterval_ms is the time interval between loading successive images and is in milliseconds.

The width and height parameters do not seem to have any effect for reasons not understood.

The following strings are returned: header, javascript code, form with movie and buttons, and footer. Concatenating these strings and dumping to an html file yields a kind of movie file to be viewed in a browser. The images variable in the javascript code is unique for each movie, because it is annotated by the casename string, so several such javascript sections can be used in the same html file.

This function is based on code written by R.J. LeVeque, based on a template from Alan McIntyre.

_figure(self, filename, caption, width=None, height=None, label=None)

source code 

Insert a figure into the document. filename should be without extension; a proper extension is added, and if the figure is not available in that image format, the convert utility from ImageMagick is called to convert the format.

_list(self, items, listtype='itemize')

source code 

Write list or nested lists.

Parameters:
  • items - list of items.
  • listtype - 'itemize', 'enumerate', or 'description'.

_table(self, table, column_headline_pos='c', column_pos='c')

source code 

Translates a two-dimensional list of data, containing strings or numbers, to a suitable "tabular" environment in the output.

Parameters:
  • table - list of list with rows/columns in table, including (optional) column-headline 1st row and row-headline 1st column.
  • column_pos - specify the l/c/r position of data entries in columns, give either (e.g.) 'llrrc' or one char (if all are equal).
  • column_headline_pos - position l/c/r for the headline row

_text(self, text, indent=0)

source code 

Write plain text. Each line can be idented by a given number of spaces.

_title(self, title, authors_and_institutions=[], date='today')

source code 

Provide title and authors.

Parameters:
  • title - document title (string).
  • authors_and_institutions - list of authors and their associated institutions, where each list item is a tuple/list with author as first element followed by the name of all institutions this author is associated with.
  • date - None implies no date, while 'today' generates the current date, otherwise a string is supplied.

_write_to_file(self, filename)

source code 

Write formatted document to a file. Just give the stem of the file name; the extension will be automatically added (depending on the document format).


Variables Details [hide private]

INLINE_TAGS

Value:
{'bold': '(?P<begin>(^|[(\\s]))_(?P<subst>[^ `][^_`]*)_(?P<end>($|[.,?\
!;:)\\s]))',
 'emphasize': '(?P<begin>(^|[(\\s]))\\*(?P<subst>[^ `][^*`]*)\\*(?P<en\
d>($|[.,?!;:)\\s]))',
 'math': '(?P<begin>(^|[(\\s]))\\$(?P<subst>[^ `][^$`]*)\\$(?P<end>($|\
[.,?!;:)\\s]))',
 'math2': '(?P<begin>(^|[(\\s]))\\$(?P<latexmath>[^ `][^$`]*)\\$\\|\\$\
(?P<puretext>[^ `][^$`]*)\\$(?P<end>($|[.,?!;:)\\s]))',
...

a

Value:
ArgSpec(args=['self', 'table', 'column_headline_pos', 'column_pos'], v\
arargs=None, keywords=None, defaults=('c', 'c'))

allargs

Value:
['self', 'table', 'column_headline_pos=\'c\'', 'column_pos=\'c\'']

code

Value:
'''def _table(self, table, column_headline_pos=\'c\', column_pos=\'c\'\
):
    \'\'\'
        Translates a two-dimensional list of data, containing strings \
or
        numbers, to a suitable "tabular" environment in the output.

        @param table: list of list with rows/columns in table, includi\
...

docstring

Value:
'''
        Translates a two-dimensional list of data, containing strings \
or
        numbers, to a suitable "tabular" environment in the output.

        @param table: list of list with rows/columns in table, includi\
ng
        (optional) column-headline 1st row and row-headline 1st column\
...

signature_def

Value:
'table(self, table, column_headline_pos=\'c\', column_pos=\'c\')'