Ejemplo n.º 1
0
def multi_range_bar_example():
    markers = [
        '\x1b[32m█\x1b[39m',  # Done
        '\x1b[33m#\x1b[39m',  # Processing
        '\x1b[31m.\x1b[39m',  # Scheduling
        ' '                   # Not started
    ]
    widgets = [progressbar.MultiRangeBar("amounts", markers=markers)]
    amounts = [0] * (len(markers) - 1) + [25]

    with progressbar.ProgressBar(widgets=widgets, max_value=10).start() as bar:
        while True:
            incomplete_items = [
                idx
                for idx, amount in enumerate(amounts)
                for i in range(amount)
                if idx != 0
            ]
            if not incomplete_items:
                break
            which = random.choice(incomplete_items)
            amounts[which] -= 1
            amounts[which - 1] += 1

            bar.update(amounts=amounts, force=True)
            time.sleep(0.02)
Ejemplo n.º 2
0
 def __init__(self, directory, writeLog, logFileName) -> None:
     self.fileList: list = []
     self.reportName = ""
     self.fileType = ""
     self.rootDirectory = Path(directory)
     self.sucessfulInstances: dict = {}
     self.failedInstances: dict = {}
     self.reportOperationErrors: list = []
     self.lineNumber = 0
     self.cellNumber = 0
     self.tempFileName = 'deleteme'
     self.writeLog = writeLog
     self.logFileName = logFileName
     self.processCount: list = [0, 0, 0]
     self.markers: list = [
         '\x1b[32m█\x1b[39m',  # Done
         '\x1b[33m#\x1b[39m',  # Processing
         '\x1b[31m.\x1b[39m',  # ToDo
     ]
     self.widgets: list = [
         f'\x1b[33mStarting...\x1b[39m',
         progressbar.MultiRangeBar(name='processCount',
                                   markers=self.markers)
     ]
     self.processBar: progressbar.ProgressBar = progressbar.ProgressBar(
         widgets=self.widgets,
         max_value=len(self.fileList),
         redirect_stdout=True).start()
Ejemplo n.º 3
0
def probar(expected, done, total):
    """Print a progress bar denoting work done, expected, and total hours."""
    expected = int(expected)
    done = int(done)
    total = int(total)
    markers = [
        '\x1b[30m\x1b[107m\x1b[1m#\x1b[0m',  # On Track
        '\x1b[32m\x1b[107m \x1b[0m',  # Ahead
        '#\x1b[0m',  # Behind
        ' '  # Left
    ]
    widgets = [progressbar.MultiRangeBar("amounts", markers=markers)]

    # Calculate amounts
    diff = abs(done - expected)
    if expected <= done:
        amounts = [expected, diff, 0, (total - done)]
    else:  # expected > done
        amounts = [done, 0, diff, (total - expected)]

    suffix = f'{done/4:5} hours'
    # Set bar_width
    if total < UNITS_PER_DAY:
        bar_width = UNITS_PER_DAY + ENCLOSING_BAR_CHARS + len(suffix)
    else:
        bar_width = total + ENCLOSING_BAR_CHARS + len(suffix)

    # Cap the width at the terminal size
    if bar_width > os.get_terminal_size()[0]:
        bar_width = os.get_terminal_size()[0]

    p_bar = progressbar.ProgressBar(widgets=widgets,
                                    max_value=10,
                                    term_width=bar_width,
                                    suffix=suffix).start()
    p_bar.update(amounts=amounts, force=True)
Ejemplo n.º 4
0
 def updateWidgets(self, file: Path) -> None:
     self.widgets: list = [
         f'\x1b[33mProcessing ({self.processCount[0]}/{self.processCount[2]} files): {file.name}\x1b[39m',
         progressbar.MultiRangeBar(name='processCount',
                                   markers=self.markers)
     ]