html_utils.py

Functions to write HTML elements.

class openmdao.visualization.html_utils.ButtonGroup(indent=0)[source]

Bases: openmdao.visualization.html_utils.UIElement

Button group, which consists of buttons and dropdowns.

Write it to get the HTML for the button group.

__init__(indent=0)

Initialize.

Parameters
indentint

Number of spaces to indent.

add_button(title, content='', uid=None, **kwargs)[source]

Add a button to the button group.

Parameters
titlestr

Name to be shown.

contentstr, optional

The content of the element.

uidstr or None

ID.

**kwargsdict

Attributes passed to the button element.

Returns
str
add_dropdown(title, id_naming=None, options=None, button_content='', header=None, uid=None, option_formatter=None, **kwargs)[source]

Add a dropdown to the button group.

Parameters
titlestr

Name to be shown.

id_namingstr or None, optional

ID of an item will be id_naming + option Defaults to None.

optionslist(str) or None, optional

Items of the dropdown. Can be None, if filled with a script. Defaults to None.

button_contentstr, optional

Content of the button.

headerstr or None, optional

First item in the dropdown. Defaults to the title.

uidstr or None, optional

ID.

option_formatterNone or callable, optional

Text formatter for the dropdown items. Called with one item. Defaults to None.

**kwargsdict

Attributes passed to the dropdown element.

Returns
str

HTML for dropdown.

write()[source]

Output the HTML code.

Returns
str
class openmdao.visualization.html_utils.DiagramWriter(filename, embeddable=False, title=None, styles=None)[source]

Bases: openmdao.visualization.html_utils.TemplateWriter

An HTML diagram writer.

The diagram has a toolbar, which can be edited by adding button groups, dropdowns, buttons, etc. to this class.

Attributes

toolbar

(Toolbar) The toolbar with button groups for this diagram.

help

(Toolbar) String of HTML for the help dialog.

__init__(filename, embeddable=False, title=None, styles=None)[source]

Initialize.

Parameters
filenamestr

Filename to write to.

embeddablebool

If true, create file so that it can be embedded in a webpage.

titlestr

Title of diagram.

stylesdict

Dictionary of CSS styles.

add_help(txt, diagram_filepath, header='Instructions', footer='')[source]

Add a modal with instructions.

Parameters
txtstr

Text.

diagram_filepathstr

File path to the diagram file in SVG format.

headerstr

Title of the modal.

footerstr

Extra info.

Returns
str

String of HTML for the help dialog.

insert(ref, txt)

Insert text.

Parameters
refstr

Reference string in template file.

txtstr

String used to replace text in template file.

write(outfile)[source]

Write an HTML output file.

Parameters
outfilestr

Name of the output file (include extension).

class openmdao.visualization.html_utils.TemplateWriter(filename, embeddable=False, title=None, styles=None)[source]

Bases: object

Writes HTML files using templates.

Opens an HTML template files, text can be inserted into the template, and writes a new HTML file with the replacements.

Attributes

filename

(str) Filename of file to write to.

template

(str) Contents of template file.

__init__(filename, embeddable=False, title=None, styles=None)[source]

Initialize.

Parameters
filenamestr

Filename of file to write to.

embeddablebool

If true, create file so that it can be embedded in a webpage.

titlestr

Title of diagram.

stylesdict

Dictionary of CSS styles.

insert(ref, txt)[source]

Insert text.

Parameters
refstr

Reference string in template file.

txtstr

String used to replace text in template file.

write(outfile)[source]

Write the output file.

Parameters
outfilestr

Path name for file to write to.

class openmdao.visualization.html_utils.Toolbar(indent=0)[source]

Bases: openmdao.visualization.html_utils.UIElement

A toolbar consists of button groups.

Add button groups, and write it to get the HTML for the toolbar.

__init__(indent=0)

Initialize.

Parameters
indentint

Number of spaces to indent.

add_button_group()[source]

Add a group of buttons.

Returns
ButtonGroup
write()[source]

Output the HTML code.

Returns
str

HTML div enclosed in tags.

class openmdao.visualization.html_utils.UIElement(indent=0)[source]

Bases: object

Abstract class for user interface elements.

Attributes

items: list

List of UI elements contained by this element.

indent

(int) Number of spaces for indent.

__init__(indent=0)[source]

Initialize.

Parameters
indentint

Number of spaces to indent.

openmdao.visualization.html_utils.add_button(title, content='', uid=None, indent=0, **kwargs)[source]

Add a button.

Parameters
titlestr

Title of button.

contentstr or list(str)

This goes into the body of the element.

uidstr or None

The “id” attribute of the element.

indentint

Indentation expressed in spaces.

**kwargsdict

Alternative way to add element attributes. Use with attention, can overwrite some in-bult python names as “class” or “id” if misused.

Returns
str

HTML for this button.

openmdao.visualization.html_utils.add_dropdown(title, id_naming=None, options=None, button_content='', header=None, uid=None, indent=0, option_formatter=None, **kwargs)[source]

Add a dropdown menu.

Parameters
titlestr

Title of button.

id_namingstr

Prefix for the id’s for the items in the menu.

optionslist

List of options for the menu.

button_contentstr

Class of icon fonts used for the menu buttons.

headerstr

Top item in the menu. It describes the purpose of the menu.

uidstr or None

The “id” attribute of the element.

indentint

Indentation expressed in spaces.

option_formatterfunc

Function used to format the displayed menu options using the values from options arg.

**kwargsdict

Alternative way to add element attributes. Use with attention, can overwrite some in-bult python names as “class” or “id” if misused.

Returns
str

HTML for this dropdown.

openmdao.visualization.html_utils.add_help(txt, diagram_filepath, header='Instructions', footer='')[source]

Add a popup help.

Parameters
txtstr

Help message/instructions.

diagram_filepathstr

File path to the diagram file in SVG format.

headerstr

Message header.

footerstr

Additional info.

Returns
str
openmdao.visualization.html_utils.add_title(txt, heading='h1', align='center')[source]

Add a title heading.

Parameters
txtstr

Title text.

headingstr

Heading. Options are “h1” to “h6”. Defaults to “h1”

alignstr

Defaults to “center”

Returns
str
openmdao.visualization.html_utils.head_and_body(head, body, attrs=None)[source]

Make an html element from a head and body.

Parameters
headstr

Head of HTML.

bodystr

Body of the HTML

attrsdict or None

Attributes of the html element. Defaults to None.

Returns
str
openmdao.visualization.html_utils.read_files(filenames, directory, extension)[source]

Read files (based on filenames) from a directory with a given extension.

Parameters
filenameslist of str

List of names of files to read.

directorystr

Pathname of directory.

extensionstr

Extension of file names.

Returns
dict

Dict of contents of files read with file names as keys.

openmdao.visualization.html_utils.write_div(content='', attrs=None, cls_attr=None, uid=None, indent=0, **kwargs)[source]

Write an HTML div.

Parameters
contentstr or list(str)

This goes into the body of the element.

attrsdict

Attributes of the element.

cls_attrstr or None

The “class” attribute of the element.

uidstr or None

The “id” attribute of the element.

indentint

Indentation expressed in spaces.

**kwargsdict

Alternative way to add element attributes. Use with attention, can overwrite some in-bult python names as “class” or “id” if misused.

Returns
str
openmdao.visualization.html_utils.write_paragraph(content)[source]

Write a paragraph.

Parameters
contentstr or list(str)

This goes into the body of the element.

Returns
str

HTML for this paragraph.

openmdao.visualization.html_utils.write_script(content='', attrs=None, indent=0, **kwargs)[source]

Write JavaScript.

Parameters
contentstr or list(str)

This goes into the body of the element.

attrsdict or None

Attributes of the element. Defaults to None.

indentint

Indentation expressed in spaces. Defaults to 0.

**kwargsdict

Alternative way to add element attributes. Use with attention, can overwrite some in-built python names as “class” or “id” if misused.

Returns
str

HTML for this JavaScript element.

openmdao.visualization.html_utils.write_style(content='', attrs=None, indent=0, **kwargs)[source]

Write CSS.

Parameters
contentstr or list(str)

This goes into the body of the element.

attrsdict or None

Attributes of the element. Defaults to None.

indentint

Indentation expressed in spaces. Defaults to 0.

**kwargsdict

Alternative way to add element attributes. Use with attention, can overwrite some in-built python names as “class” or “id” if misused.

Returns
str

HTML for this CSS element.

openmdao.visualization.html_utils.write_tags(tag, content='', attrs=None, cls_attr=None, uid=None, new_lines=False, indent=0, **kwargs)[source]

Write an HTML element enclosed in tags.

Parameters
tagstr

Name of the tag.

contentstr or list(str)

This goes into the body of the element.

attrsdict or None

Attributes of the element. Defaults to None.

cls_attrstr or None

The “class” attribute of the element.

uidstr or None

The “id” attribute of the element.

new_linesbool

Make new line after tags.

indentint

Indentation expressed in spaces. Defaults to 0.

**kwargsdict

Alternative way to add element attributes. Use with attention, can overwrite some in-built python names as “class” or “id” if misused.

Returns
str

HTML element enclosed in tags.