ProgressBarController

class termtools.terminal.ProgressBarController(barNames=None, barLength=50, align_bars=True)[source]

Bases: object

A set of progress bars.

A set of progress bars with custom pre and post text. It is mostly useful when you have several running threads or suprocesses and each needs its own bar. It allows prefixes and postfixes that can be changed using the following tags: <name> bar name <remaining> remaining time to completion estimate <activity> An indicator that the process represented by the bar is active

Attributes Summary

activityChars
barNames
begTime
completed_background
completed_color
current
last_i
last_n
last_name_updated
over_complete_background
over_complete_color
running_background
running_color
under_complete_background
under_complete_color

Methods Summary

activate([name]) Indicate that the given bar is active.
add_bar(name, *[, i, n, start_timing]) Adds a bar
get_remaining_time(name) Gets the time remaining till the end of execution (only an estimate)
remove_bar(name) Removes a bar given its name
set_progress(name, i[, n]) Sets progress for a specific bar, optionally setting its limit as well
show([name, prefix, suffix, bar_length, …]) Shows a specific bar just in the current place on the screen.
show_all([barname, i, n, clean_screen, …]) Shows a specific bar or all bars, possibly cleaning the screen
show_in_position([name, prefix, suffix, …]) Shows the named bar in its appropriate position without touching anything else in the screen
start_timing([forNames]) Starts timing for ETA calculation for the given bar names
terminal() Gets the built-in TerminalController object
update([name, i, n, prefix, suffix, bar_length]) Updates the progress value of a given bar and shows all the bars in their relative positions

Attributes Documentation

activityChars = ['. ', ' . ', ' . ', ' .', ' . ', ' . ', '. ']
barNames = None
begTime = None
completed_background = 'black'
completed_color = 'green'
current = None
last_i = None
last_n = None
last_name_updated = None
over_complete_background = 'black'
over_complete_color = 'red'
running_background = 'black'
running_color = 'yellow'
under_complete_background = 'black'
under_complete_color = 'red'

Methods Documentation

activate(name=None)[source]

Indicate that the given bar is active. If name is None, all bars are indicated to be active by progressing

Parameters:name (str) – bar name. If None is given then all bars are set to be active
Returns:self
add_bar(name, *, i=0, n=0, start_timing=True)[source]

Adds a bar

Can control the name, starting progress (i) and total progress

Parameters:name (str) – name of bar
Kwargs:

i (int): current progress n (int): total progress start_timing (bool or None): Starts a timer for this bar, otherwise it uses the begTime member which

is common to all bars
Returns:self

Remarks:

get_remaining_time(name)[source]

Gets the time remaining till the end of execution (only an estimate)

Parameters:name – bar name
Returns:remaining time (ETA)
Return type:int
remove_bar(name)[source]

Removes a bar given its name

Parameters:name (str) – bar name
Returns:self
set_progress(name, i, n=None)[source]

Sets progress for a specific bar, optionally setting its limit as well

Parameters:
  • name (str) – bar name
  • i (int) – current progress
  • n (int or None) – Limit (optional)
Returns:

self

show(name=None, prefix='<name>', suffix='<remaining>', bar_length=-1, from_line_beginning=True)[source]

Shows a specific bar just in the current place on the screen. We should have a new line before it

Args:

name (str or None): name of the bar prefix (str): prefix to write before the bar (see the class doc string for possible tag values) suffix (str): postfix (see prefix) bar_length (int): Bar length, if less than zero then the current length set during creation of the bar or

latest setting of its progess will be used.

from_line_beginning (bool): If true, a ‘

‘ and flushing will be outputed to set the bar to the beginning
of the line
Returns:
self
show_all(barname=None, i=None, n=None, clean_screen=True, prefix='<name><activity>', suffix='<remaining>', bar_length=-1, skip_rows=0)[source]

Shows a specific bar or all bars, possibly cleaning the screen

Parameters:
  • barname (str or None) – name of the bar
  • i (int or None) – optional progress value
  • n (int or None) – optional maximum value for the bar
  • clean_screen (bool) – Whether or not to clean the screen before drawing. Default is true
  • prefix (str) – prefix to write before the bar (see the class doc string for possible tag values)
  • suffix (str) – postfix (see prefix)
  • bar_length (int) – Bar length, if less than zero then the current length set during creation of the bar or latest setting of its progess will be used.
  • skip_rows (int) – the number of lines to skip between bars
  • from_line_beginning (bool) – If true, a r and flushing will be outputed to set the bar to the beginning of the line
Returns:

self

Remarks:

show_in_position(name=None, prefix='<name><activity>', suffix='<remaining>', bar_length=-1)[source]

Shows the named bar in its appropriate position without touching anything else in the screen

Parameters:
  • name (str) – bar name
  • clean_screen (bool) – Whether or not to clean the screen before drawing. Default is true
  • prefix (str) – prefix to write before the bar (see the class doc string for possible tag values)
  • suffix (str) – postfix (see prefix)
  • bar_length (int) – Bar length, if less than zero then the current length set during creation of the bar or latest setting of its progress will be used.
Returns:

self

start_timing(forNames=None)[source]

Starts timing for ETA calculation for the given bar names

Parameters:forNames (str or None) – The list of bar names. If None (Default), the beginning time of all bars is set to now
Returns:self
terminal()[source]

Gets the built-in TerminalController object

Return type:TerminalController
Returns:TerminalController
update(name=None, i=None, n=None, prefix='<name><activity>', suffix='<remaining>', bar_length=-1)[source]

Updates the progress value of a given bar and shows all the bars in their relative positions

Parameters:
  • name (str) – bar name
  • i (int or None) – optional progress value
  • n (int or None) – optional maximum value for the bar
  • clean_screen (bool) – Whether or not to clean the screen before drawing. Default is true
  • prefix (str) – prefix to write before the bar (see the class doc string for possible tag values)
  • suffix (str) – postfix (see prefix)
  • bar_length (int) – Bar length, if less than zero then the current length set during creation of the bar or latest setting of its progess will be used.
Returns:

self