Module reahl.web.bootstrap.ui

Added in version 3.2.

This module houses stylised versions of very basic user interface elements – user interface elements that have a one-to-one correspondence to HTML elements (or are of similar simplicity).

Widgets for constructing a page

Slot

class reahl.web.bootstrap.ui.Slot(view, name)

Bases: Widget

A Slot is a placeholder area on a page into which different Views can plug different Widgets on the fly.

Using Slots, one can create a single HTML5page which can be re-used by different Views instead of having to create similar-looking HTML5Pages for each View in an application.

A Slot is added to an HTML5Page to represent an area that will be populated later by a View. When a View is served up the framework can then populate this empty area with Widgets specific to the current View.

Parameters:
  • view – (See reahl.web.fw.Widget)

  • name – A name for this Slot (must be unique on the page)

RunningOnBadge

class reahl.web.bootstrap.ui.RunningOnBadge(view)

Bases: A

A visual badge proclaiming that a website is “Running on Reahl”. Using it on your site is a bit of advertising for Reahl!

Styling

Renders as an HTML <a class=”runningon”> containing an <img>

Parameters:

view – (See reahl.web.fw.Widget)

Very low-level Widgets that correspond to HTML

TextNode

class reahl.web.bootstrap.ui.TextNode(view, value_or_getter, html_escape=True)

Bases: Widget

An HTML TextNode. You can, for example, use a TextNode to add a snippet of text as a child of a P inbetween its other children (which will all be HTMLElements, like Span).

Parameters:
  • view – (See reahl.web.fw.Widget)

  • value_or_getter – A string which will be used as the text of the TextNode. Pass a no-arg callable instead to delay the computation of what the text of the TextNode should be to the time of rendering the TextNode. The callable will be called right before the TextNode is rendered, and should return the text that should be used in the TextNode.

  • html_escape – If True (default), the given value will first be HTML-escaped before rendered to the browser.

render()

Returns an HTML representation of this Widget. (Not for general use, may be useful for testing.)

Title

class reahl.web.bootstrap.ui.Title(view, text, css_id=None)

Bases: HTMLElement

The title of an HTML page (the title of a reahl.web.fw.View is usually shown via a Title).

Styling

Rendered as a <title> element.

Parameters:
  • view – (See reahl.web.fw.Widget)

  • text – A string for use in a PEP-292 template. The final value after substituting this string Template will be used as the value of this Title. The template string may use one placeholder: $current_title which contains the title of the current View.

  • css_id – (See reahl.web.ui.HTMLElement)

Body

class reahl.web.bootstrap.ui.Body(view, css_id=None)

Bases: HTMLElement

The content of an HTML document.

Styling

Renders as an HTML <body> element.

Parameters:
add_child(child)

Adds another Widget (child) as a child Widget of this one.

Returns:

the added child for convenience.

Span

class reahl.web.bootstrap.ui.Span(view, text=None, html_escape=True, css_id=None)

Bases: HTMLElement

A logical grouping of other HTMLElements which fits in with text flow.

Styling

Renders as an HTML <span> element.

Parameters:

LiteralHTML

class reahl.web.bootstrap.ui.LiteralHTML(view, contents, transform=<function LiteralHTML.<lambda>>)

Bases: Widget

The LiteralHTML Widget renders a chunk of HTML as given in contents. If a single-argument callable is given as transform, contents will first be passed to that callable to possibly change the HTML on-the-fly before rendering (the callable should return the changed HTML to be rendered).

Parameters:
  • view – (See reahl.web.fw.Widget)

  • contents – Some literal HTML.

  • transform – If given, it is called passing contents to possibly transform contents before rendering. The callable should return the final HTML to be rendered.

render()

Returns an HTML representation of this Widget. (Not for general use, may be useful for testing.)

More commonly used Widgets that correspond to HTML

A

class reahl.web.bootstrap.ui.A(view, href, description=None, ajax=False, read_check=None, write_check=None, css_id=None)

Bases: HTMLElement

A hyper link.

Styling

Renders as an HTML <a> element.

Parameters:
classmethod from_bookmark(view, bookmark)

Creates an A for the given bookmark on view.

classmethod factory_from_bookmark(bookmark)

Creates a reahl.web.fw.WidgetFactory for creating an A for the given bookmark.

property attributes

Override this method if you want to change the attributes of this HTMLElement on the fly, based on the state of the HTMLElement at the point in time when it is rendered.

get_js(context=None)

Override this method if your Widget needs JavaScript to be activated on the browser side.

set_active(active)

Explicitly sets whether this hyperlink is “active” or not. An active hyperlink cannot be clicked on, because conceptually, the user is already at its target.

Parameters:

active – A boolean – send True if active, else False.

H

class reahl.web.bootstrap.ui.H(view, priority, text=None, css_id=None)

Bases: HTMLElement

The heading for a section.

Styling

Renders as an HTML <h1>, <h2> … , <h6> element, depending on priority.

Parameters:

P

class reahl.web.bootstrap.ui.P(view, text=None, css_id=None, html_escape=True)

Bases: HTMLElement

A paragraph of text.

Styling

Renders as an HTML <p> element.

Parameters:
  • view – (See reahl.web.fw.Widget)

  • text – The text value displayed in the paragraph (if given)

  • css_id – (See reahl.web.ui.HTMLElement)

  • html_escape – If text is given, by default such text is HTML-escaped. Pass False in here to prevent this from happening.

format(*args, **kwargs)

A complicated paragraph may consist of many TextNodes interspersed with other Widgets. Creating such a paragraph programmatically is cumbersome. Instead, the text of a P can be a template resembling a PEP-292 template. This format method works analogously to string.format(), except that Widgets can be passed in to be substituted into the original P.

Parameters:
  • args – Positional arguments for substituting into the “template P”

  • kwargs – Named arguments for substituting into the “template P”

Div

class reahl.web.bootstrap.ui.Div(view, css_id=None)

Bases: HTMLElement

A logical grouping of other HTMLElements.

Styling

Renders as an HTML <div> element

Parameters:

Article

class reahl.web.bootstrap.ui.Article(view, css_id=None)

Bases: HTMLElement

An independent section of informational content.

Styling

Renders as an HTML <article> element.

Parameters:

Li

class reahl.web.bootstrap.ui.Li(view, css_id=None)

Bases: HTMLElement

A list item.

Styling

Renders as an HTML <li> element.

Parameters:

Ul

class reahl.web.bootstrap.ui.Ul(view, css_id=None)

Bases: HTMLElement

An unordered list.

Styling

Renders as an HTML <ul> element.

Parameters:

Ol

class reahl.web.bootstrap.ui.Ol(view, css_id=None)

Bases: HTMLElement

An ordered list.

Styling

Renders as an HTML <ol> element.

Parameters:

Img

class reahl.web.bootstrap.ui.Img(view, src=None, alt=None, css_id=None)

Bases: HTMLElement

An embedded image.

Styling

Renders as an HTML <img> element.

Parameters:

Legend

class reahl.web.bootstrap.ui.Legend(view, text=None, css_id=None)

Bases: HTMLElement

A caption for an reahl.web.ui.HTMLElement.

Added in version 3.2.

Styling

Rendered as an HTML <legend> element.

Parameters:

Alert

class reahl.web.bootstrap.ui.Alert(view, message_or_widget, severity)

Bases: Div

A message box meant to alert the user of some message.

See also: Badge.

Parameters:
  • view – (See reahl.web.fw.Widget)

  • message_or_widget – Message text or a Widget to display inside the Alert.

  • severity – One of ‘primary’, ‘secondary’, ‘success’, ‘info’, ‘warning’, ‘danger’, ‘light’, ‘dark’ to indicate the color scheme for the Alert.