sfepy.base.progressbar module

Text progressbar library for python.

This library provides a text mode progressbar. This is tipically used to display the progress of a long running operation, providing a visual clue that processing is underway.

The ProgressBar class manages the progress, and the format of the line is given by a number of widgets. A widget is an object that may display diferently depending on the state of the progress. There are three types of widget: - a string, which always shows itself; - a ProgressBarWidget, which may return a diferent value every time it’s update method is called; and - a ProgressBarWidgetHFill, which is like ProgressBarWidget, except it expands to fill the remaining width of the line.

The progressbar module is very easy to use, yet very powerful. And automatically supports features like auto-resizing when available.

class sfepy.base.progressbar.Bar(marker='#', left='|', right='|')[source]

The bar of progress. It will strech to fill the line.

update(pbar, width)[source]
class sfepy.base.progressbar.ETA[source]

Widget for the Estimated Time of Arrival

format_time(seconds)[source]
update(pbar)[source]
class sfepy.base.progressbar.FileTransferSpeed[source]

Widget for showing the transfer speed (useful for file transfer).

update(pbar)[source]
class sfepy.base.progressbar.MyBar(text, verbose=True)[source]

Encapsulation of a nice progress bar

init(max)[source]
update(i)[source]
class sfepy.base.progressbar.Percentage[source]

Just the percentage done.

update(pbar)[source]
class sfepy.base.progressbar.ProgressBar(maxval=100, widgets=[<sfepy.base.progressbar.Percentage object at 0xb176f0c>, ' ', <sfepy.base.progressbar.Bar object at 0xb176f2c>], term_width=None, fd=<open file '<stderr>', mode 'w'>)[source]

This is the ProgressBar class, it updates and prints the bar.

The term_width parameter may be an integer. Or None, in which case it will try to guess it, if it fails it will default to 80 columns.

The simple use is like this: >>> pbar = ProgressBar().start() >>> for i in xrange(100): ... # do something ... pbar.update(i+1) ... >>> pbar.finish()

But anything you want to do is possible (well, almost anything). You can supply different widgets of any type in any order. And you can even write your own widgets! There are many widgets already shipped and you should experiment with them.

When implementing a widget update method you may access any attribute or function of the ProgressBar object calling the widget’s update method. The most important attributes you would like to access are: - currval: current value of the progress, 0 <= currval <= maxval - maxval: maximum (and final) value of the progress - finished: True if the bar is have finished (reached 100%), False o/w - start_time: first time update() method of ProgressBar was called - seconds_elapsed: seconds elapsed since start_time - percentage(): percentage of the progress (this is a method)

finish()[source]

Used to tell the progress is finished.

handle_resize(signum, frame)[source]
percentage()[source]

Returns the percentage of the progress.

start()[source]

Start measuring time, and prints the bar at 0%.

It returns self so you can use it like this: >>> pbar = ProgressBar().start() >>> for i in xrange(100): ... # do something ... pbar.update(i+1) ... >>> pbar.finish()

update(value)[source]

Updates the progress bar to a new value.

class sfepy.base.progressbar.ProgressBarWidget[source]

This is an element of ProgressBar formatting.

The ProgressBar object will call it’s update value when an update is needed. It’s size may change between call, but the results will not be good if the size changes drastically and repeatedly.

update(pbar)[source]

Returns the string representing the widget.

The parameter pbar is a reference to the calling ProgressBar, where one can access attributes of the class for knowing how the update must be made.

At least this function must be overriden.

class sfepy.base.progressbar.ProgressBarWidgetHFill[source]

This is a variable width element of ProgressBar formatting.

The ProgressBar object will call it’s update value, informing the width this object must the made. This is like TeX hfill, it will expand to fill the line. You can use more than one in the same line, and they will all have the same width, and together will fill the line.

update(pbar, width)[source]

Returns the string representing the widget.

The parameter pbar is a reference to the calling ProgressBar, where one can access attributes of the class for knowing how the update must be made. The parameter width is the total horizontal width the widget must have.

At least this function must be overriden.

class sfepy.base.progressbar.ReverseBar(marker='#', left='|', right='|')[source]

The reverse bar of progress, or bar of regress. :)

update(pbar, width)[source]
class sfepy.base.progressbar.RotatingMarker(markers='|/-\')[source]

A rotating marker for filling the bar of progress.

update(pbar)[source]
sfepy.base.progressbar.progressbar(text='calculating', maxval=100)[source]

Returns a useful default progressbar.

Usage:

pbar=progressbar(maxval=10000) for i in range(10000):

pbar.update(i) #do some heavy calculation in each step

pbar.finish()