-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgressBar.py
53 lines (41 loc) · 1.81 KB
/
ProgressBar.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
import colorama
import cursor
class ProgressBar:
"""
This class defines a simple, lightweight and generic progress bar.
"""
def __init__(self, total):
self.total = total
self.color_below_half = colorama.Fore.RED
self.color_above_half = colorama.Fore.YELLOW
self.color_above_eighty_percent = colorama.Fore.GREEN
def print(self, progress):
cursor.hide()
print(self.getProgessBarString(progress) , end='\r')
if progress == self.total:
print(colorama.Fore.RESET)
cursor.show()
return self
def getProgessBarString(self, progress):
no_of_bars = int((progress)/self.total * 100)
no_of_dashes = 100 - no_of_bars
if no_of_bars < 50:
return self.color_below_half + '\r|{0}{1}| {2}%'.format(
'█' * no_of_bars, '-' * no_of_dashes, round(float((progress)/self.total * 100), 2))
elif no_of_bars < 80:
return self.color_above_half + '\r|{0}{1}| {2}%'.format(
'█' * no_of_bars, '-' * no_of_dashes, round(float((progress)/self.total * 100), 2))
else:
return self.color_above_eighty_percent + '\r|{0}{1}| {2}%'.format(
'█' * no_of_bars, '-' * no_of_dashes, round(float((progress)/self.total * 100), 2))
def resetTotal(self, total):
self.total = total
return self
def resetColors(self, color_below_half=colorama.Fore.RED, color_above_half=colorama.Fore.YELLOW, color_above_eighty_percent=colorama.Fore.GREEN):
self.color_below_half = color_below_half
self.color_above_half = color_above_half
self.color_above_eighty_percent = color_above_eighty_percent
return self
def __del__(self):
print(colorama.Fore.RESET)
del self.total