Skip to content

Commit

Permalink
Merge pull request #14 from rgeoghegan/master
Browse files Browse the repository at this point in the history
Change default progressbar to show off more features. Also prevent two progressbars from sharing the same default widgets.
  • Loading branch information
wolph committed Nov 19, 2014
2 parents b439851 + 3f644be commit e8bf887
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions progressbar/__init__.py
Expand Up @@ -128,16 +128,15 @@ class ProgressBar(object):

_DEFAULT_MAXVAL = 100
_DEFAULT_TERMSIZE = 80
_DEFAULT_WIDGETS = [Percentage(), ' ', Bar()]

def __init__(self, maxval=None, widgets=None, term_width=None, poll=0.1,
left_justify=True, fd=sys.stderr, redirect_stderr=False,
redirect_stdout=False):
'''Initializes a progress bar with sane defaults'''

# Don't share a reference with any other progress bars
if widgets is None:
widgets = list(self._DEFAULT_WIDGETS)
# Don't share widgets with any other progress bars
widgets = self.default_widgets()

self.maxval = maxval
self.widgets = widgets
Expand Down Expand Up @@ -169,6 +168,12 @@ def __init__(self, maxval=None, widgets=None, term_width=None, poll=0.1,
self.start_time = None
self.update_interval = 1

def default_widgets(self):
return [
Percentage(), ' (', SimpleProgress(), ')', ' ', Bar(), ' ',
Timer(), ' ', AdaptiveETA(),
]

def __call__(self, iterable, maxval=None):
'Use a ProgressBar to iterate through an iterable'
if maxval is None:
Expand Down

0 comments on commit e8bf887

Please sign in to comment.