Skip to content

Instantly share code, notes, and snippets.

@00krishna
Last active September 7, 2015 17:31
Show Gist options
  • Save 00krishna/9dc1dbeb183c54c39c1e to your computer and use it in GitHub Desktop.
Save 00krishna/9dc1dbeb183c54c39c1e to your computer and use it in GitHub Desktop.
Python progressive progressbar working example
__author__ = 'krishnab'
from time import sleep
from blessings import Terminal
from progressive.bar import Bar
from progressive.tree import ProgressTree, Value, BarDescriptor
def progbar(_outer, _inner):
leaf_values = [Value(0) for i in range(2)]
test_d = {
'Link pages scraped': BarDescriptor(value=leaf_values[0],
type=Bar, kwargs=dict(max_value = _outer,width="50%")),
'Articles collected': BarDescriptor(value = leaf_values[1],
type=Bar, kwargs=dict(max_value= _inner,width="10%"))
}
def incr_value(obj, _counter_outer, _counter_inner):
if _counter_inner < _outer:
leaf_values[0].value += 1
if _counter_outer < _inner:
leaf_values[1].value += 1
def are_we_done(obj):
if _counter_inner == _outer and _counter_outer == _inner:
return(True)
else:
return(False)
# Create blessings.Terminal instance
t = Terminal()
# Initialize a ProgressTree instance
n = ProgressTree(term=t)
# We'll use the make_room method to make sure the terminal
# is filled out with all the room we need
n.make_room(test_d)
_counter_inner = 0
_counter_outer = 0
while not are_we_done(test_d):
sleep(2)
n.cursor.restore()
# We use our incr_value method to bump the fake numbers
incr_value(test_d,_counter_outer, _counter_inner)
# Actually draw out the bars
n.draw(test_d)
_counter_inner += 1
_counter_outer += 1
if __name__ == '__main__':
progbar(100, 20)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment