Permalink
Browse files

Quick implementation check with minor tweaks

 - cleaned up doc strings + added missing doc strings
 - updated the version and the release date
 - removed the need for basestring
 - if possible the classes use metaclass "ABCMeta" to enforce abstract methods
 - added slots to all the widgets
 - replaced loops with math whenever possible
 - left and right borders for the progress bar can now be animated

 - added a poll attribute which allows the time sensitive widgets to be
   redrawn when poll seconds have passed

 - added additional logging to the examples through a decorator
  • Loading branch information...
1 parent fde028a commit 12984d2b5616d7dfeb40c8192c1644cf19e8d3f2 @terencehonles terencehonles committed May 15, 2011
Showing with 326 additions and 216 deletions.
  1. +4 −4 README
  2. +21 −9 examples.py
  3. +301 −203 progressbar.py
View
8 README
@@ -1,15 +1,15 @@
-Text progressbar library for python.
+Text progress bar library for python.
-This library provides a text mode progressbar. This is typically used
+This library provides a text mode progress bar. This is typically 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
+display differently 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
+- a ProgressBarWidget, which may return a different 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.
View
@@ -6,14 +6,27 @@
from progressbar import ProgressBar, Percentage, Bar, ETA, FileTransferSpeed, \
RotatingMarker, ReverseBar, SimpleProgress
+def example(fn):
+ try: name = 'Example %d' % int(fn.__name__[7:])
+ except: name = fn.__name__
+
+ def wrapped():
+ sys.stdout.write('Running: %s\n' % name)
+ fn()
+ sys.stdout.write('Finished: %s\n\n' % name)
+
+ return wrapped
+
+
+@example
def example0():
pbar = ProgressBar(widgets=[Percentage(), Bar()], maxval=300).start()
for i in range(300):
time.sleep(0.01)
pbar.update(i+1)
pbar.finish()
- sys.stdout.write('\n')
+@example
def example1():
widgets = ['Test: ', Percentage(), ' ', Bar(marker=RotatingMarker()),
' ', ETA(), ' ', FileTransferSpeed()]
@@ -22,8 +35,8 @@ def example1():
# do something
pbar.update(10*i+1)
pbar.finish()
- sys.stdout.write('\n')
+@example
def example2():
class CrazyFileTransferSpeed(FileTransferSpeed):
"It's bigger between 45 and 80 percent"
@@ -42,17 +55,17 @@ def update(self, pbar):
# do something
pbar.update(5*i+1)
pbar.finish()
- sys.stdout.write('\n')
+@example
def example3():
widgets = [Bar('>'), ' ', ETA(), ' ', ReverseBar('<')]
pbar = ProgressBar(widgets=widgets, maxval=10000000).start()
for i in range(1000000):
# do something
pbar.update(10*i+1)
pbar.finish()
- sys.stdout.write('\n')
+@example
def example4():
widgets = ['Test: ', Percentage(), ' ',
Bar(marker='0',left='[',right=']'),
@@ -63,35 +76,34 @@ def example4():
time.sleep(0.2)
pbar.update(i)
pbar.finish()
- sys.stdout.write('\n')
+@example
def example5():
pbar = ProgressBar(widgets=[SimpleProgress()], maxval=17).start()
for i in range(17):
time.sleep(0.2)
pbar.update(i + 1)
pbar.finish()
- sys.stdout.write('\n')
+@example
def example6():
pbar = ProgressBar().start()
for i in range(100):
time.sleep(0.01)
pbar.update(i + 1)
pbar.finish()
- sys.stdout.write('\n')
+@example
def example7():
pbar = ProgressBar() # Progressbar can guess maxval automatically.
for i in pbar(range(80)):
time.sleep(0.01)
- sys.stdout.write('\n')
+@example
def example8():
pbar = ProgressBar(maxval=80) # Progressbar can't guess maxval.
for i in pbar((i for i in range(80))):
time.sleep(0.01)
- sys.stdout.write('\n')
if __name__ == '__main__':
example0()
Oops, something went wrong.

0 comments on commit 12984d2

Please sign in to comment.