forked from REDxEYE/io_mesh_SourceMDL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
progressBar.py
83 lines (67 loc) · 2.32 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import sys
import time
# def update_progress(job_title, progress):
# length = 20 # modify this to change the length
# block = int(round(length*progress))
# msg = "\r{0}: [{1}] {2}%".format(job_title, "#"*block + "-"*(length-block), round(progress*100, 2))
# if progress >= 1: msg += " DONE\r\n"
# sys.stdout.write(msg)
# sys.stdout.flush()
#
# # Test
# for i in range(100):
# time.sleep(0.1)
# update_progress("Some job", i/100.0)
# update_progress("Some job", 1)
class Progress_bar:
def __init__(self, desc, max_, len_):
self.len = len_
self.max = max_
self.desc = desc
self.curr = 0
self.draw()
def increment(self, val):
self.curr += val
self.draw()
@property
def state(self):
return self.curr, self.max
@property
def is_done(self):
return self.curr >= self.max
@is_done.setter
def is_done(self, value):
self.curr = self.max
@property
def as_percent(self):
return (self.curr / self.max) * 100
@property
def as_float(self):
if self.max == 0:
return 1
return self.curr / self.max
def draw(self):
if self.is_done:
sys.stdout.write('\r')
bar = '{name} [{progress}] {curr}/{max} Done '.format(name=self.desc, progress='#' * round(
self.len * self.as_float) + ' ' * round(self.len * (1 - self.as_float)), curr=self.curr, max=self.max)
sys.stdout.write(bar)
sys.stdout.write('\n')
else:
sys.stdout.write('\r')
bar = '{name} [{progress}] {curr}/{max} {percent:4}% '.format(name=self.desc, progress='#' * round(
self.len * self.as_float) + ' ' * round(self.len * (1 - self.as_float)), curr=self.curr, max=self.max,
percent=round(self.as_percent, 2))
sys.stdout.write(bar)
sys.stdout.flush()
if __name__ == '__main__':
a = Progress_bar(desc='Importing vertex indexes', max_=100, len_=20)
a2 = Progress_bar(desc='Generating model_path', max_=100, len_=20)
while not a2.is_done:
if a.is_done:
a2.increment(1)
a2.draw()
else:
a.increment(1)
a.draw()
time.sleep(0.02)