ProgressBar#

class alfred3.element.display.ProgressBar(progress: Union[str, float, int] = 'auto', bar_height: str = '6px', show_text: bool = False, striped: bool = True, style: str = 'primary', animated: bool = False, round_corners: bool = False, progress_base: str = 'pages_elements', n_elements: Optional[int] = None, n_pages: Optional[int] = None, increments_of_five: bool = True, **kwargs)[source]#

Bases: alfred3.element.core.LabelledElement

Displays a progress bar.

Parameters
  • progress (str, float, int) –

    Can be either “auto”, or a number between 0 and 100. If “auto”, the progress is calculated from the current progress of the experiment. The exact calculation can be further refined with the arguments ‘progress_base’, ‘n_elements’, and ‘n_pages’.

    If a number is supplied, that number will be used as the progress to be displayed.

    Defaults to ‘auto’.

  • bar_height (str) – Height of the progress bar. Supply a string with unit, e.g. “6px”.

  • show_text (bool) – Indicates, whether the progress bar should include text with the current progress.

  • striped (bool) – Indicates, whether the progress bar shoulb be striped.

  • style (str) – Determines the color of the progress bar. Possible values are “primary”, “secondary”, “info”, “success”, “warning”, “danger”, “light”, “dark”.

  • animated (bool) – Determines, whether a striped progress bar should be equipped with an animation.

  • round (bool) – Determines, whether the corners of the progress bar should be round.

  • progress_base (str) – A string, specifying the unit to use as the basis upon which progress should be calculated. Can be either ‘pages_elements’, ‘pages’, or ‘elements’. Defaults to ‘pages_elements’, in which case the number of pages and the number of input elements are added together to form the denominator in the fraction for calculating progress.

  • n_elements (int) – Manual specification of the number of input elements in the experiment. If ‘None’, the experiment will try to infer the number of elements automatically, which may not always find the correct result. Defaults to None.

  • n_pages (int) – Manual specification of the number of page in the experiment. If ‘None’, the experiment will try to infer the number of pages automatically, which may not always find the correct result. Defaults to None.

  • increments_of_five (bool) – If True (default), the progress text activated by setting show_text=True will be displayed in increments of five. This can lead to a more consistent user experience, because the visual display updates in increments of five as well.

  • **kwargs

    Inherited keyword arguments

    align

    Horizontal alignment of text in the element. Does not usually apply to labels. Think of it as an alignment that applies to the innermost layer of an element (while labels are generally located at outer layers). See LabelledElement for more on labelled elements. Can be left (default), center, right, or justify.

    font_size

    Font size for text in the element. You can use a keyword or an exact specification. The available keywords are tiny, small, normal, big, and huge. The exact specification shoul ideally include a unit, such as 1rem, or 12pt. If you supply an integer without a unit, a unit of pt will be assumed. Defaults to normal.

    height

    Vertical height of the elements display area. Supply a string with a unit, e.g. 80px. Usually, the default is fine. For adding vertical space to a page, you should prefer the VerticalSpace element, as it is sematically more clear.

    instance_log

    If True, the element will use an instance-specific logger, thereby allowing detailed fine- tuning of its logging behavior.

    layout

    Can be one of the following: 1) An instance of RowLayout, or 2) a tuple of integers, specifying the allocation of horizontal space between leftlab, main element widget and rightlab on small screens upwards. Option 1) offers fine-tuned flexibility, 2) uses a default RowLayout and changes the RowLayout.width_sm attribute. By default, the layout is set automatically depending on the specification of the left and right labels.

    name

    Name of the element. This should be a unique identifier. It will be used to identify the corresponding data in the final data set.

    position

    Horizontal position of the full element on the page. Values can be left, center (default), end, or any valid value for the justify-content flexbox utility. Takes effect only, when the element is not full-width.

    showif

    A dictionary, defining conditions that must be met for the element to be shown. The conditions take the form of key-value pairs, where each key is an element name and the value is the required input. See showif for details.

    toplab, bottomlab, leftlab, rightlab

    Labels above, below, left and right of the element.

    width

    Defines the horizontal width of the element from small screens upwards. It is always full-width on extra small screens. Possible values are narrow, medium, wide, and full. For more detailed control, you can define the element_width attribute.

See also

See ExperimentSession.progress_bar for more information on the experiment-wide progress bar.

Notes

If the argument show_text is True, the text’s appearance can be altered via CSS. It receives a class of “css_class_element-text” and an id of “Element.name-text”. You can use the method add_css() to append fitting CSS to the bar (see examples).

Examples

Overriding the default experiment-wide progress bar:

import alfred3 as al
exp = al.Experiment()

@exp.setup
def setup(exp_session):
    exp_session.progress_bar = al.ProgressBar(show_text=True, bar_height="15px")

exp += al.Page(name="example_page")

Adding a progress bar as an element to a page:

import alfred3 as al
exp = al.Experiment()

@exp.member
class Example(al.Page):
    name = "example_page"

    def on_exp_access(self):
        self += al.ProgressBar()

Altering the progress bar text’s apperance, applied to the experiment-wide progress bar. Note that the experiment-wide progress bar always receives the name “progress_bar_”:

import alfred3 as al
exp = al.Experiment()

@exp.setup
def setup(exp):
    exp.progress_bar = al.ProgressBar(show_text=True, bar_height="15px")
    exp.progress_bar.add_css("#progress_bar_ {font-size: 12pt;}")

exp += al.Page(name="example_page")

Methods

add_css

Adds CSS to the element.

add_js

Adds Javascript to the element.

added_to_experiment

Tells the element that it was added to an experiment.

added_to_page

Tells the element that it was added to a page.

prepare_web_widget

Hook for computations for preparing an element's web widget.

render_inner_html

Renders the element template element_template.

Attributes

base_template

Base template for the element, which will be used to hold the rendered element template.

bottomlab

Label below of the main element widget.

converted_width

List of bootstrap column widths at different screen sizes.

css_class_container

Returns the name the element container's CSS class.

css_class_element

Returns the name of the element's CSS class.

css_code

A list of tuples, which contain a priority and CSS code.

css_urls

A list of tuples, which contain a priority and an url pointing to CSS code.

denominator

Denominator for the fraction in calculating the progress.

display_standalone

If True (default), the element will be displayed as usual on its own.

element_template

The element's specific, inner template.

element_width

Returns a string of column width definitions.

exp

The experiment session to which this element belongs.

experiment

Alias for exp

font_size

Font size

js_code

A list of tuples, which contain a priority and Javascript.

js_urls

A list of tuples, which contain a priority and an url pointing to JavaScript.

labels

Returns the labels in a single, nicely formatted string.

layout

Controls the allocation of horizontal space between the left and right label, as well as the main element.

leftlab

Label to the left of the main element widget.

n_elements

Number of elements.

n_pages

Number of pages.

name

Unique identifier for the element.

numerator

Numerator for the fraction in calculating the progress.

page

The page to which this element belongs.

position

Position of the whole element on the page.

progress

rightlab

Label to the right of the main element widget.

section

The direct parent section of this element's page.

short_tree

String, giving the exact position in the experiment.

should_be_shown

Boolean, indicating whether the element is meant to be shown.

showif

Conditions that have to be met for the element to be shown.

template_data

Dictionary of data to be passed on to jinja templates.

toplab

Label above of the main element widget.

tree

String, giving the exact position in the experiment.

web_widget

The element's rendered html code for display on a page.

width

Element width