Source code for Muscat.Helpers.ProgressBar

# -*- coding: utf-8 -*-
#
# This file is subject to the terms and conditions defined in
# file 'LICENSE.txt', which is part of this source code package.
#

from typing import Union
from Muscat.Types import MuscatIndex


[docs] def PrintProgressBar(iteration: Union[int, MuscatIndex], total: Union[int, MuscatIndex], prefix: str = '', suffix: str = '', decimals: int = 1, length: int = 100, fill: str = '|') -> None: """ Call in a loop to create terminal progress bar .. code-block:: python PrintProgressBar(0, l, prefix = 'Progress:', suffix = 'Complete', length = 50) for i, item in enumerate(items): # Do stuff... # Update Progress Bar PrintProgressBar(i + 1, l, prefix = 'Progress:', suffix = 'Complete', length = 50) Parameters ---------- iteration : int Current iteration total : int Total iterations prefix : str, optional Prefix string suffix : str, optional Suffix string decimals : int, optional Positive number of decimals in percent complete length : str, optional Character length of bar fill : str, optional Bar fill character """ filledLength = int(length * iteration // total) # Print New Line on Complete end = '\n' if iteration == total else '\r' print(f"\r{prefix} |{fill * filledLength}{'-' * (length - filledLength)}| {100 * iteration / total:.{decimals}f}% {suffix}", end=end, flush=True)
[docs] def CheckIntegrity(GUI: bool = False) -> str: from time import sleep # A List of Items items = list(range(0, 57)) l = len(items) # Initial call to print 0% progress PrintProgressBar(0, l, prefix='Progress:', suffix='Complete', length=50) for i, item in enumerate(items): # Do stuff... sleep(0.001) # Update Progress Bar PrintProgressBar(i + 1, l, prefix='Progress:', suffix='Complete', length=50) return 'ok'
if __name__ == '__main__': CheckIntegrity(True) # pragma: no cover