Htpbs
Htpbs is a Python library that creates horizontal progress bars to keep
track of the progress of threaded jobs. Bars in htpbs are completely customizable.
Installation
Use the package manager pip to install htpbs.
pip install htpbs
Usage
The following are examples about how to use this library for threaded and non threaded bars
Threaded horizontal bars
from htpbs import ProgressBars, Work
import time
def work(progressbars, bar_index, work_value, work_name):
"""
:param progressbars: the progressbar obkect
:param bar_index: a integer representing the index of the bae
:param work_value: a value for time.sleep() to simulate different progress bars rates
:param work_name: the name of the work
:return: VOID
"""
progressbars.set_bar_prefix(bar_index=bar_index, prefix=work_name)
for i in range(101):
time.sleep(work_value)
progressbars.update(bar_index=bar_index, value=i)
progressbars.finish()
progressbars = ProgressBars(num_bars=3)
progressbars.set_last_bar_as_total_progress(prefix="Total: ")
Work.start(work, (progressbars, 0, 0.1, "w1: "))
Work.start(work, (progressbars, 1, 0.01, "w2: "))
Using the same thread
from htpbs import ProgressBars
import time
progressbars = ProgressBars(num_bars=5)
progressbars.set_last_bar_as_total_progress(prefix="Total Progress: ")
for i in range(101):
time.sleep(0.1)
values = [i, i+5, i+10, i+15, 0]
progressbars.update_all(values)
progressbars.finish_all()
Remove bars when job is done and init the next bar
from htpbs import ProgressBars
import time
progressbars = ProgressBars(num_bars=3)
progressbars.set_last_bar_as_total_progress(prefix="Total Progress: ")
progressbars.set_hidden_bars([1])
for i in range(101):
time.sleep(0.1)
progressbars.update(bar_index=0, value=i)
progressbars.finish()
progressbars.clear_bar(bar_index=0)
progressbars.reset_bar(index=1, prefix="new bar: ")
for i in range(101):
time.sleep(0.1)
progressbars.update(bar_index=1, value=i)
progressbars.finish()
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
License
MIT
htpbs
version: 0.0.4