BouncingBar¶
BouncingBar slides a marker back and forth instead of filling.
Reach for it for indeterminate work: with no total to measure progress
against, it shows a marker bouncing across the full width to signal
that the process is still running. The marker moves on a wall-clock
timer, not per update() call, and the characters come from the same
marker/left/right/fill arguments as Bar.
- class progressbar.widgets.BouncingBar(marker='#', left='|', right='|', fill=' ', fill_left=True, marker_wrap=None, **kwargs)[source]
Bases:
Bar,TimeSensitiveWidgetBaseA bar which has a marker which bounces from side to side.
Create the bar with its marker and border characters.
- Parameters:
marker – Character, or (progress, data, width) -> str callable, used for the filled portion.
left – Character, or callable, used as the left border.
right – Character, or callable, used as the right border.
fill – Character used for the empty part of the bar.
fill_left – Fill/grow from the left. If False, from the right.
marker_wrap – Begin/end strings or template wrapped around a string marker (see create_wrapper). Ignored for a callable marker.
**kwargs – Forwarded to the next class in the cooperative __init__ chain.
Example¶
"""``BouncingBar`` slides a marker back and forth instead of filling.
Reach for it for indeterminate work -- there is no total to measure
progress against, so instead of a percentage it shows a bouncing marker
to signal that the process is still running, similar in spirit to
``AnimatedMarker`` but shaped like a full-width bar. The marker moves on
a wall-clock timer, not per ``update()`` call, so this example runs
longer than most in this set -- otherwise it barely twitches before the
run ends.
"""
import time
import progressbar
STEPS = 40
def main() -> None:
widgets = ['Working: ', progressbar.BouncingBar()]
with progressbar.ProgressBar(
max_value=progressbar.UnknownLength,
widgets=widgets,
) as bar:
for step in range(STEPS):
bar.update(step)
time.sleep(0.05)
if __name__ == '__main__':
main()
See also¶
AnimatedMarker: a single-character spinner, also indeterminate.
Bar: the determinate fill bar this stands in for.