-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogress.py
56 lines (47 loc) · 1.73 KB
/
progress.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import sys
""" display: PREFIX [#########= ] 50% SUFFIX """
"""http://thelivingpearl.com/2012/12/31/creating-progress-bars-with-python/"""
class Progressbar:
def __init__(self, steps=100, prefix="Progress:", suffix=None, symbol="#",
active="=", brackets="[]", percent=True, size=40):
self.steps = steps
self.prefix = prefix
self.suffix = suffix
self.symbol = symbol
self.active = active
self.brackets = brackets
self.percent = percent
self.size = size #Visual size in spaces
self.state = 0
self.printbar()
def printbar(self, end=1):
out1 = "{0} {1}".format(self.prefix,self.brackets[0])
out2 = (self.symbol)*self.state + " "*(self.size-self.state)
out3 = "{0}".format(self.brackets[1])
if self.percent==True: out3 = out3+" {0}% ".format(int(100.0*(float(self.state)/float(self.size))))
if self.suffix != None: out3 = out3 + self.suffix
out = out1+out2+out3
width = len(out)+2
print(out)
if end==1: print('\b'*width)
sys.stdout.flush()
def updatebar(self, prog, suff=None):
if prog >= 1.0: self.endbar(); return
complete = int(self.size*prog)
if complete > self.state:
self.state = complete
self.printbar()
def updatesuffix(self):
return -1
def endbar(self):
self.state = self.size
self.printbar(0)
print(" Done!")
if __name__=="__main__":
import time
testbar = Progressbar(prefix="TONS OF STUFF YAAAAAAAAAA", suffix="MORE STUFF!!!")
#testbar.displaybar()
for i in range(101):
time.sleep(0.1)
testbar.updatebar(i/100.0)
print("Test Successful")