JobStatusBar¶
JobStatusBar marks each job as succeeded or failed on the bar.
Reach for it when a bar tracks discrete jobs rather than continuous
progress: each update() records one job’s outcome as a colored
marker, and jobs not yet reported stay blank rather than showing a
fill. success_marker/failure_marker and their *_fg_color
counterparts control the rendering per outcome.
- class progressbar.widgets.JobStatusBar(name: str, left='|', right='|', fill=' ', fill_left=True, success_fg_color=((0, 128, 0), (120, 100, 25), 'Green', 2), success_bg_color=None, success_marker='█', failure_fg_color=((255, 0, 0), (0, 100, 50), 'Red', 9), failure_bg_color=None, failure_marker='X', **kwargs)[source]
Bases:
Bar,VariableMixinWidget which displays the job status as markers on the bar.
The status updates can be given either as a boolean or as a string. If it’s a string, it will be displayed as-is. If it’s a boolean, it will be displayed as a marker (default: ‘█’ for success, ‘X’ for failure) configurable through the success_marker and failure_marker parameters. See __init__ for the full parameter list.
Create a JobStatusBar.
- Parameters:
name – data[‘variables’] key holding each status update.
left – The left border of the bar.
right – The right border of the bar.
fill – The fill character of the bar.
fill_left – Whether to fill the bar from the left or the right.
success_fg_color – Foreground color for successful jobs.
success_bg_color – Background color for successful jobs.
success_marker – Marker character for successful jobs.
failure_fg_color – Foreground color for failed jobs.
failure_bg_color – Background color for failed jobs.
failure_marker – Marker character for failed jobs.
**kwargs – Forwarded to Bar.__init__.
- get_job_markers(progress: ProgressBarMixinBase) list[str][source]
Return this bar’s colored marker history, creating it if needed.
Per-bar marker history, following SamplesMixin’s progress.extra pattern so the widget itself stays stateless; see SamplesMixin.get_sample_times for why that matters.
- job_markers: list[str]
Unused, retained for backwards compatibility only.
Per-run marker state lives in
progress.extrainstead (seeget_job_markers()).
Example¶
"""``JobStatusBar`` marks each job as succeeded or failed on the bar.
Reach for it when a bar tracks discrete jobs rather than continuous
progress -- each ``update()`` records one job's outcome as a colored
marker; jobs not yet reported stay blank rather than showing a fill.
"""
import random
import time
import progressbar
random.seed(0)
STEPS = 24
def main() -> None:
widgets = [progressbar.JobStatusBar('status')]
with progressbar.ProgressBar(max_value=STEPS, widgets=widgets) as bar:
for step in range(STEPS):
roll = random.random()
if roll > 0.66:
status = True
elif roll > 0.33:
status = False
else:
status = None
bar.update(step + 1, status=status)
time.sleep(0.005)
if __name__ == '__main__':
main()
See also¶
Bar: the plain fill bar this repurposes for discrete outcomes.
MultiRangeBar: proportional category segments instead of per-job markers.