support.progressindicator – Progress Indicator Widget¶
This module defines functions and classes which implement a flexible progress bar widget.
To date, the module provides only widgets for text user interfaces (i.e. for a terminal).
Public Classes¶
This module is built around two main parts: the first one is the manager; the second one is a collection of widgets which manages the way by which the progression is going to be displayed.
The manager has only on public class.
To date, the module includes a number of widgets listed below in
alphabetical order. A handler is a derived class from the BaseWidget
class.
Public Functions¶
This module has has a number of functions listed below in alphabetical order.
Objects reference¶
This section details the objects defined in this module.
- class support.progressindicator.ProgressIndicatorWidget(width=None)¶
Bases:
objectProgress indicator.
This class is the manager of the
progress indicator. This latter is a element of a textual user interface and it’s made of a set of elementary widget such as aprogress baror atransfer rate indicator(seewidget_classes_availableto have the current list of available widgets.- Parameters
width (int) – The width of the progress indicator expressed in characters. The resulting string of the concatenation of strings returned by each widget is left justified in a string of length width. The
Noneobject means that the width will set to number of columns of the terminal.- Raises
TypeError – Parameters type mismatch.
- Public Methods
This class has a number of public methods listed below.
- Using ProgressIndicatorWidget…
After created a class instance, you add one or more elementary widget to the progress indicator by calling the
add_widgetmethod. If this step is ignored, the progress indicator will be an empty string. After this step, you must call thestartmethod to initialise the widget with the lowest and the highest value of the monitored quantity. At each change of the value, you call theupdatemethod to print the progress bar on the standard output (sys.stdout). When the task completed, you call thefinishmethod.- Example of fetching a file
import urllib.request from support import progressindicator progress = progressindicator.ProgressIndicatorWidget(72) widget = progressindicator.SeparatorWidget( symbol="python-3.5.1-docs-text.zip: " ) progress.add_widget(widget) widget = progressindicator.PercentWidget() progress.add_widget(widget) widget = progressindicator.ProgressBarWidget() progress.add_widget(widget) widget = progressindicator.SeparatorWidget( symbol="python-3.5.1-docs-text.zip: " ) progress.add_widget(widget, True) widget = progressindicator.PrefixedQuantityWidget(symbol="B") progress.add_widget(widget, True) url = "https://docs.python.org/release/3.5.1/" \ "archives/python-3.5.1-docs-text.zip" with urllib.request.urlopen(url) as stream: content_length = int(stream.info()["Content-Length"]) length = 0 progress.start(length, content_length) progress.update(length) while True: data = stream.read(1500) if not data: break length += len(data) progress.update(length) progress.finish(length)
- add_widget(widget, is_completion=False)¶
Add an elementary widget to update the progress indicator widget.
- Parameters
widget (BaseWidget) – The widget to add. It must be an instance of the
BaseWidgetclass.is_completion (bool) –
Falseindicate that the widget will be added to the list of widget used when calling theProgressIndicatorWidget.updatemethod
- Raises
TypeError – Parameters type mismatch.
ValueError – Unsupported attributes values
- finish(value)¶
Compute the progress bar completion and return the computed string.
- start(minimum=0.0, maximum=inf)¶
Start the progress indicator widget.
- Parameters
- Raises
TypeError – Parameters type mismatch.
ValueError – Unsupported attributes values
- update(value)¶
Update the progress indicator widget
Note
To prevent the update flicking, the refresh period is limited (see
refreshment_thresholdattribute).- Parameters
value (int or float) – The current value of the monitored quantity.
- Raises
TypeError – Parameters type mismatch.
ValueError – Unsupported attributes values
- refreshment_threshold¶
The delay between two update of the display expressed in fraction of second. The default value is 8 times per seconds (0.125 s)
- Type
- class support.progressindicator.WidgetsCollection(max_length)¶
Bases:
objectWidgets collection
- Parameters
max_length (int) – The authorised maximum length of the widgets string expressed in characters. This string is the concatenation of strings returned by each widget. The addition of a widget (see
add_widget()), whose length makes the length of the widgets string exceeding the max_length, raises anValueErrorexception.- Raises
TypeError – Parameters type mismatch.
ValueError – Unsupported attributes values
- add_widget(widget)¶
Add an elementary widget to the collection.
- Parameters
widget (BaseWidget) – The widget to add. It must be an instance of the
BaseWidgetclass.- Raises
TypeError – Parameters type mismatch.
ValueError – Unsupported attributes values
- class support.progressindicator.BaseWidget(symbol='')¶
Bases:
objectBase class for all elementary widget.
- Parameters
symbol (str) – The symbol of the unit.
- Public Methods
This class has only one public method listed below.
- Methods to Override
This class is a abstract class, so the following method must be overridden.
- update(normal_value, dyn_range, value, duration, counter)¶
Update the elementary widget
- Parameters
normal_value (float) – The normalised value of the progression. This value is between 0 and 1.
dyn_range (float) – The dynamics range of the monitored quantity.
value (float) – The real value of the progress
duration (float) – The number of seconds since the starting point
counter (int) – The number of call of the method. This counter may be useful to animate a
throbber.
- Returns
a human readable string.
- Return type
- class support.progressindicator.PercentWidget(symbol='')¶
Bases:
support.progressindicator.BaseWidgetWidget to update the percentage of progress
The printed string have the following content:
nnn%wherennnis the percentage of progress- Parameters
symbol (str) – The symbol of the unit. This string is not used in this context, because a percentage have no unit.
- update(normal_value, dyn_range, value, duration, counter)¶
Display the elementary widget
- Parameters
normal_value (float) – The normalized value of the monitored quantity. This value is between 0 and 1.
dyn_range (float) – The normalized maximum value of the monitored quantity.
value (float) – The real value of the progress
duration (float) – The number of seconds since the starting point
counter (int) – The number of call of the method. This counter may be useful to animate a
throbber.
- Returns
a human readable string.
- Return type
- class support.progressindicator.RateWidget(symbol='')¶
Bases:
support.progressindicator.BaseWidgetWidget to update the rate of progress
The printed string have the following content:
rrrr XU/swhererrrris the rate.Xrepresent a multiple of the unit (G, M or k) andUis the unit symbol.- Parameters
symbol (str) – The symbol of the unit.
- update(normal_value, dyn_range, value, duration, counter)¶
Display the elementary widget
- Parameters
normal_value (float) – The normalized value of the monitored quantity. This value is between 0 and 1.
dyn_range (float) – The normalized maximum value of the monitored quantity.
value (float) – The real value of the progress
duration (float) – The number of seconds since the starting point
counter (int) – The number of call of the method. This counter may be useful to animate a
throbber.
- Returns
a human readable string.
- Return type
- class support.progressindicator.ETAWidget(symbol='')¶
Bases:
support.progressindicator.BaseWidgetWidget to update the estimated time to achieve the operation.
The printed string have the following content:
eta hh:mm:sswherehh:mm:ssis the estimated time to achieve the operation expressed in hour, minute and second.- Parameters
symbol (str) – The symbol of the unit. This string is not used in this context, because a time expression have no unit.
- update(normal_value, dyn_range, value, duration, counter)¶
Display the elementary widget
- Parameters
normal_value (float) – The normalized value of the monitored quantity. This value is between 0 and 1.
dyn_range (float) – The normalized maximum value of the monitored quantity.
value (float) – The real value of the progress
duration (float) – The number of seconds since the starting point
counter (int) – The number of call of the method. This counter may be useful to animate a
throbber.
- Returns
a human readable string.
- Return type
- class support.progressindicator.DurationWidget(symbol='')¶
Bases:
support.progressindicator.BaseWidgetWidget to update the operation duration.
The printed string have the following content:
hh:mm:sswherehh:mm:ssis the operation duration expressed in hour, minute and second.- Parameters
symbol (str) – The symbol of the unit. This string is not used in this context, because a time expression have no unit.
- update(normal_value, dyn_range, value, duration, counter)¶
Display the elementary widget
- Parameters
normal_value (float) – The normalized value of the monitored quantity. This value is between 0 and 1.
dyn_range (float) – The normalized maximum value of the monitored quantity.
value (float) – The real value of the progress
duration (float) – The number of seconds since the starting point
counter (int) – The number of call of the method. This counter may be useful to animate a
throbber.
- Returns
a human readable string.
- Return type
- class support.progressindicator.ValueWidget(symbol='')¶
Bases:
support.progressindicator.BaseWidgetWidget to update the real value.
The printed string have the following content:
lll,lll,lll,lll Uwherelll,lll,lll,lllis the value of the progress andUis the unit symbol. The formatter uses the current locale setting to insert the appropriate number separator characters (seestringmodule).- Parameters
symbol (str) – The symbol of the unit.
- update(normal_value, dyn_range, value, duration, counter)¶
Display the elementary widget
- Parameters
normal_value (float) – The normalized value of the monitored quantity. This value is between 0 and 1.
dyn_range (float) – The normalized maximum value of the monitored quantity.
value (float) – The real value of the progress
duration (float) – The number of seconds since the starting point
counter (int) – The number of call of the method. This counter may be useful to animate a
throbber.
- Returns
a human readable string.
- Return type
- class support.progressindicator.PrefixedValueWidget(symbol='')¶
Bases:
support.progressindicator.BaseWidgetWidget to update the real value using standard prefix for unit.
The printed string have the following content:
nnn XUwherennnis a multiple of the value.Xrepresent a multiple of the unit (G, M or k) andUis the unit symbol.- Parameters
symbol (str) – The symbol of the unit.
- update(normal_value, dyn_range, value, duration, counter)¶
Display the elementary widget
- Parameters
normal_value (float) – The normalized value of the monitored quantity. This value is between 0 and 1.
dyn_range (float) – The normalized maximum value of the monitored quantity.
value (float) – The real value of the progress
duration (float) – The number of seconds since the starting point
counter (int) – The number of call of the method. This counter may be useful to animate a
throbber.
- Returns
a human readable string.
- Return type
- class support.progressindicator.PrefixedQuantityWidget(symbol='')¶
Bases:
support.progressindicator.BaseWidgetWidget to update the monitored quantity using standard prefix for unit.
The printed string have the following content:
nnn XUwherennnis a multiple of the value.Xrepresent a multiple of the unit (G, M or k) andUis the unit symbol.- Parameters
symbol (str) – The symbol of the unit.
- update(normal_value, dyn_range, value, duration, counter)¶
Display the elementary widget
- Parameters
normal_value (float) – The normalized value of the monitored quantity. This value is between 0 and 1.
dyn_range (float) – The normalized maximum value of the monitored quantity.
value (float) – The real value of the progress
duration (float) – The number of seconds since the starting point
counter (int) – The number of call of the method. This counter may be useful to animate a
throbber.
- Returns
a human readable string.
- Return type
- class support.progressindicator.ProgressBarWidget(symbol='')¶
Bases:
support.progressindicator.BaseWidgetProgress bar widget.
This class implement a
progress barwidget.The printed string have the following content:
[============== ]where=is a step of the progression.- Parameters
symbol (str) – The symbol of the unit. This string is not used in this context, because a progress bar have no unit.
- update(normal_value, dyn_range, value, duration, counter)¶
Update the Progress bar widget
- Parameters
normal_value (float) – The normalized value of the monitored quantity. This value is between 0 and 1.
dyn_range (float) – The normalized maximum value of the monitored quantity.
value (float) – The real value of the progress
duration (float) – The number of seconds since the starting point
counter (int) – The number of call of the method. This counter may be useful to animate a
throbber.
- Returns
a human readable string.
- Return type
- class support.progressindicator.IndeterminateProgressBarWidget(symbol='')¶
Bases:
support.progressindicator.BaseWidgetIndeterminate progress bar widget.
This class implement an indeterminate
progress barwidget.The printed string have the following content:
[ **** ]where****is a maker moving from right to left.- Parameters
symbol (str) – The symbol of the unit. This string is not used in this context, because a progress bar have no unit.
- update(normal_value, dyn_range, value, duration, counter)¶
Update the Progress bar widget
- Parameters
normal_value (float) – The normalized value of the monitored quantity. This value is between 0 and 1.
dyn_range (float) – The normalized maximum value of the monitored quantity.
value (float) – The real value of the progress
duration (float) – The number of seconds since the starting point
counter (int) – The number of call of the method. This counter may be useful to animate a
throbber.
- Returns
a human readable string.
- Return type
- class support.progressindicator.SpinningWheelWidget(symbol='')¶
Bases:
support.progressindicator.BaseWidgetSpinning wheel widget.
This class implement a
throbberwidget.- Parameters
symbol (str) – The symbol of the unit. This string is not used in this context, because a spinning wheel have no unit.
- update(normal_value, dyn_range, value, duration, counter)¶
Update the Progress bar widget
- Parameters
normal_value (float) – The normalized value of the monitored quantity. This value is between 0 and 1.
dyn_range (float) – The normalized maximum value of the monitored quantity.
value (float) – The real value of the progress
duration (float) – The number of seconds since the starting point
counter (int) – The number of call of the method. This counter may be useful to animate a
throbber.
- Returns
a human readable string.
- Return type
- class support.progressindicator.SeparatorWidget(symbol='')¶
Bases:
support.progressindicator.BaseWidgetWidget to display a separator.
- Parameters
symbol (str) – The separator.
- update(normal_value, dyn_range, value, duration, counter)¶
Display the elementary widget
- Parameters
normal_value (float) – The normalized value of the progress. This value is between 0 and 1.
dyn_range (float) – The normalized maximum value of the monitored quantity.
value (float) – The real value of the progress
duration (int) – The number of seconds since the start
counter (int) – The number of call of the method. This counter may be useful to animate a
throbber.
- Returns
a human readable string.
- Return type
- class support.progressindicator.ScrollingTextWidget(symbol='')¶
Bases:
support.progressindicator.BaseWidgetWidget to display a scrolling text.
- Parameters
symbol (str) – The text.
- update(normal_value, dyn_range, value, duration, counter)¶
Display the elementary widget
- Parameters
normal_value (float) – The normalized value of the progress. This value is between 0 and 1.
dyn_range (float) – The normalized maximum value of the monitored quantity.
value (float) – The real value of the progress
duration (int) – The number of seconds since the start
counter (int) – The number of call of the method. This counter may be useful to animate a
throbber.
- Returns
a human readable string.
- Return type
Functions reference¶
This section details the specific functions used in this module.
- support.progressindicator.isu_format_prefix(value, unit)¶
Return a string using standard prefix for unit.
The returned string represent the value in a compliant International System of Units format, which means with a prefix for unit.
- support.progressindicator.new_download_throbber(title='')¶
Returns a throbber indicator to monitor a download process.
This widget uses the following widget with a width equal to the number of columns of the terminal:
ScrollingTextWidget,SpinningWheelWidget,PrefixedValueWidget,RateWidget,DurationWidget.
- support.progressindicator.new_download_progress(title='')¶
Returns a progress indicator to monitor a download process.
This widget uses the following widget with a width equal to the number of columns of the terminal:
ScrollingTextWidget,SpinningWheelWidget,PrefixedValueWidget,RateWidget,DurationWidget.
- support.progressindicator.new_download_null(title='')¶
Returns a progress indicator to monitor a download process.
This widget uses no widget. This is useful for very small downloads (a few kilobytes).
Data reference¶
This section details global data, including both variables and values used as ‘defined constants’.
- support.progressindicator.widget_classes_available = [<class 'support.progressindicator.PercentWidget'>, <class 'support.progressindicator.RateWidget'>, <class 'support.progressindicator.ETAWidget'>, <class 'support.progressindicator.DurationWidget'>, <class 'support.progressindicator.ValueWidget'>, <class 'support.progressindicator.PrefixedValueWidget'>, <class 'support.progressindicator.PrefixedQuantityWidget'>, <class 'support.progressindicator.ProgressBarWidget'>, <class 'support.progressindicator.IndeterminateProgressBarWidget'>, <class 'support.progressindicator.SpinningWheelWidget'>, <class 'support.progressindicator.SeparatorWidget'>, <class 'support.progressindicator.ScrollingTextWidget'>]¶
A set containing the class of the widget supported by this module on all platforms.
- Type