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
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 theRowLayout.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 methodadd_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
Adds CSS to the element.
Adds Javascript to the element.
Tells the element that it was added to an experiment.
Tells the element that it was added to a page.
Hook for computations for preparing an element's web widget.
Renders the element template
element_template
.Attributes
Base template for the element, which will be used to hold the rendered element template.
Label below of the main element widget.
List of bootstrap column widths at different screen sizes.
Returns the name the element container's CSS class.
Returns the name of the element's CSS class.
A list of tuples, which contain a priority and CSS code.
A list of tuples, which contain a priority and an url pointing to CSS code.
Denominator for the fraction in calculating the progress.
If True (default), the element will be displayed as usual on its own.
The element's specific, inner template.
Returns a string of column width definitions.
The experiment session to which this element belongs.
Alias for
exp
Font size
A list of tuples, which contain a priority and Javascript.
A list of tuples, which contain a priority and an url pointing to JavaScript.
Returns the labels in a single, nicely formatted string.
Controls the allocation of horizontal space between the left and right label, as well as the main element.
Label to the left of the main element widget.
Number of elements.
Number of pages.
Unique identifier for the element.
Numerator for the fraction in calculating the progress.
The page to which this element belongs.
Position of the whole element on the page.
Label to the right of the main element widget.
The direct parent section of this element's page.
String, giving the exact position in the experiment.
Boolean, indicating whether the element is meant to be shown.
Conditions that have to be met for the element to be shown.
Dictionary of data to be passed on to jinja templates.
Label above of the main element widget.
String, giving the exact position in the experiment.
The element's rendered html code for display on a page.
Element width