CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Public Attributes | Static Public Attributes | Properties | Private Member Functions | Private Attributes | Static Private Attributes
progressbar.ProgressBar Class Reference
Inheritance diagram for progressbar.ProgressBar:

Public Member Functions

def __call__
 
def __init__
 
def __iter__
 
def __next__
 
def finish
 
def percentage
 
def start
 
def update
 

Public Attributes

 currval
 
 fd
 
 finished
 
 last_update_time
 
 left_justify
 
 maxval
 
 next_update
 
 num_intervals
 
 poll
 
 seconds_elapsed
 
 signal_set
 
 start_time
 
 term_width
 
 update_interval
 
 widgets
 

Static Public Attributes

 next = __next__
 

Properties

 percent = property(percentage)
 

Private Member Functions

def _env_size
 
def _format_line
 
def _format_widgets
 
def _handle_resize
 
def _need_update
 
def _update_widgets
 

Private Attributes

 __iterable
 
 _time_sensitive
 

Static Private Attributes

tuple __slots__
 
int _DEFAULT_MAXVAL = 100
 
int _DEFAULT_TERMSIZE = 80
 

Detailed Description

The ProgressBar class which updates and prints the bar.

A common way of using it is like:
>>> pbar = ProgressBar().start()
>>> for i in range(100):
...    # do something
...    pbar.update(i+1)
...
>>> pbar.finish()

You can also use a ProgressBar as an iterator:
>>> progress = ProgressBar()
>>> for i in progress(some_iterable):
...    # do something
...

Since the progress bar is incredibly customizable you can specify
different widgets of any type in any order. You can even write your own
widgets! However, since there are already a good number of widgets you
should probably play around with them before moving on to create your own
widgets.

The term_width parameter represents the current terminal width. If the
parameter is set to an integer then the progress bar will use that,
otherwise it will attempt to determine the terminal width falling back to
80 columns if the width cannot be determined.

When implementing a widget's update method you are passed a reference to
the current progress bar. As a result, you have access to the
ProgressBar's methods and attributes. Although there is nothing preventing
you from changing the ProgressBar you should treat it as read only.

Useful methods and attributes include (Public API):
 - currval: current progress (0 <= currval <= maxval)
 - maxval: maximum (and final) value
 - finished: True if the bar has finished (reached 100%)
 - start_time: the time when start() method of ProgressBar was called
 - seconds_elapsed: seconds elapsed since start_time and last call to
                    update
 - percentage(): progress in percent [0..100]

Definition at line 163 of file progressbar.py.

Constructor & Destructor Documentation

def progressbar.ProgressBar.__init__ (   self,
  maxval = None,
  widgets = None,
  term_width = None,
  poll = 1,
  left_justify = True,
  fd = sys.stderr 
)
Initializes a progress bar with sane defaults

Definition at line 216 of file progressbar.py.

Member Function Documentation

def progressbar.ProgressBar.__call__ (   self,
  iterable 
)

Definition at line 247 of file progressbar.py.

def progressbar.ProgressBar.__iter__ (   self)

Definition at line 260 of file progressbar.py.

def progressbar.ProgressBar.__next__ (   self)

Definition at line 264 of file progressbar.py.

def progressbar.ProgressBar._env_size (   self)
private

Definition at line 280 of file progressbar.py.

def progressbar.ProgressBar._format_line (   self)
private

Definition at line 327 of file progressbar.py.

def progressbar.ProgressBar._format_widgets (   self)
private

Definition at line 300 of file progressbar.py.

def progressbar.ProgressBar._handle_resize (   self,
  signum = None,
  frame = None 
)
private

Definition at line 286 of file progressbar.py.

def progressbar.ProgressBar._need_update (   self)
private

Definition at line 336 of file progressbar.py.

def progressbar.ProgressBar._update_widgets (   self)
private

Definition at line 344 of file progressbar.py.

def progressbar.ProgressBar.finish (   self)

Definition at line 403 of file progressbar.py.

def progressbar.ProgressBar.percentage (   self)

Definition at line 293 of file progressbar.py.

def progressbar.ProgressBar.start (   self)
Starts measuring time, and prints the bar at 0%.

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

Definition at line 374 of file progressbar.py.

def progressbar.ProgressBar.update (   self,
  value = None 
)

Definition at line 351 of file progressbar.py.

Referenced by Vispa.Gui.ZoomableWidget.ZoomableWidget.setZoom().

Member Data Documentation

progressbar.ProgressBar.__iterable
private

Definition at line 236 of file progressbar.py.

tuple progressbar.ProgressBar.__slots__
staticprivate
Initial value:
1 = ('currval', 'fd', 'finished', 'last_update_time',
2  'left_justify', 'maxval', 'next_update', 'num_intervals',
3  'poll', 'seconds_elapsed', 'signal_set', 'start_time',
4  'term_width', 'update_interval', 'widgets', '_time_sensitive',
5  '__iterable')

Definition at line 206 of file progressbar.py.

int progressbar.ProgressBar._DEFAULT_MAXVAL = 100
staticprivate

Definition at line 212 of file progressbar.py.

int progressbar.ProgressBar._DEFAULT_TERMSIZE = 80
staticprivate

Definition at line 213 of file progressbar.py.

progressbar.ProgressBar._time_sensitive
private

Definition at line 347 of file progressbar.py.

progressbar.ProgressBar.currval

Definition at line 238 of file progressbar.py.

progressbar.ProgressBar.fd

Definition at line 221 of file progressbar.py.

progressbar.ProgressBar.finished

Definition at line 239 of file progressbar.py.

progressbar.ProgressBar.last_update_time

Definition at line 240 of file progressbar.py.

progressbar.ProgressBar.left_justify

Definition at line 222 of file progressbar.py.

progressbar.ProgressBar.maxval

Definition at line 219 of file progressbar.py.

progressbar.ProgressBar.next = __next__
static

Definition at line 277 of file progressbar.py.

progressbar.ProgressBar.next_update

Definition at line 369 of file progressbar.py.

progressbar.ProgressBar.num_intervals

Definition at line 389 of file progressbar.py.

progressbar.ProgressBar.poll

Definition at line 241 of file progressbar.py.

progressbar.ProgressBar.seconds_elapsed

Definition at line 242 of file progressbar.py.

progressbar.ProgressBar.signal_set

Definition at line 224 of file progressbar.py.

progressbar.ProgressBar.start_time

Definition at line 243 of file progressbar.py.

progressbar.ProgressBar.term_width

Definition at line 226 of file progressbar.py.

progressbar.ProgressBar.update_interval

Definition at line 244 of file progressbar.py.

progressbar.ProgressBar.widgets

Definition at line 220 of file progressbar.py.

Property Documentation

progressbar.ProgressBar.percent = property(percentage)
static

Definition at line 297 of file progressbar.py.