-
-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathmulti_range_bar.py
More file actions
49 lines (40 loc) · 1.44 KB
/
Copy pathmulti_range_bar.py
File metadata and controls
49 lines (40 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""``MultiRangeBar`` shows several named ranges as segments of one bar.
Reach for it to visualize a whole made of distinct categories -- done,
processing, scheduled, not started -- as proportional segments of a
single bar, rather than a single fill fraction. Compare
``MultiProgressBar``, which shows independent per-job progress instead
of categories of one whole. Its loop runs until every unit reaches the
"done" range rather than a fixed ``STEPS`` count, since that is what the
widget is for.
"""
import random
import time
import progressbar
random.seed(0)
UNITS = 25
def main() -> None:
markers = [
'\x1b[38;5;2m█\x1b[39m', # Done (green)
'\x1b[38;5;3m#\x1b[39m', # Processing (yellow)
'\x1b[38;5;1m.\x1b[39m', # Scheduled (red)
' ', # Not started
]
widgets = [progressbar.MultiRangeBar('amounts', markers=markers)]
amounts = [0] * (len(markers) - 1) + [UNITS]
with progressbar.ProgressBar(widgets=widgets) as bar:
while True:
incomplete = [
idx
for idx, amount in enumerate(amounts)
for _ in range(amount)
if idx != 0
]
if not incomplete:
break
which = random.choice(incomplete)
amounts[which] -= 1
amounts[which - 1] += 1
bar.update(amounts=amounts, force=True)
time.sleep(0.005)
if __name__ == '__main__':
main()