diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-14 20:18:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-14 20:18:28 +0000 |
commit | f8363b456f1ab31ee56abad579b215af195093d5 (patch) | |
tree | b1500c675c2e0a55fb75721a854e1510acf7c862 /examples/live_progress.py | |
parent | Initial commit. (diff) | |
download | rich-f8363b456f1ab31ee56abad579b215af195093d5.tar.xz rich-f8363b456f1ab31ee56abad579b215af195093d5.zip |
Adding upstream version 9.11.0.upstream/9.11.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'examples/live_progress.py')
-rw-r--r-- | examples/live_progress.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/examples/live_progress.py b/examples/live_progress.py new file mode 100644 index 0000000..7ae1056 --- /dev/null +++ b/examples/live_progress.py @@ -0,0 +1,45 @@ +""" + +Demonstrates the use of multiple Progress instances in a single Live display. + +""" + +from time import sleep + +from rich.live import Live +from rich.panel import Panel +from rich.progress import Progress, SpinnerColumn, BarColumn, TextColumn +from rich.table import Table + + +job_progress = Progress( + "{task.description}", + SpinnerColumn(), + BarColumn(), + TextColumn("[progress.percentage]{task.percentage:>3.0f}%"), +) +job1 = job_progress.add_task("[green]Cooking") +job2 = job_progress.add_task("[magenta]Baking", total=200) +job3 = job_progress.add_task("[cyan]Mixing", total=400) + +total = sum(task.total for task in job_progress.tasks) +overall_progress = Progress() +overall_task = overall_progress.add_task("All Jobs", total=int(total)) + +progress_table = Table.grid() +progress_table.add_row( + Panel.fit( + overall_progress, title="Overall Progress", border_style="green", padding=(2, 2) + ), + Panel.fit(job_progress, title="[b]Jobs", border_style="red", padding=(1, 2)), +) + +with Live(progress_table, refresh_per_second=10): + while not overall_progress.finished: + sleep(0.1) + for job in job_progress.tasks: + if not job.finished: + job_progress.advance(job.id) + + completed = sum(task.completed for task in job_progress.tasks) + overall_progress.update(overall_task, completed=completed) |