-
Notifications
You must be signed in to change notification settings - Fork 0
/
progressBar.py
58 lines (47 loc) · 1.15 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
import sys
import time
import threading
class progressor:
def __init__(self, ptype):
self.type = ptype
def start(self):
if self.type == 'rotor':
self.counter = rotor()
elif self.type == 'linear':
self.counter = linear()
self.t = threading.Thread(target=self.counter.start)
self.t.start()
def stop(self):
self.counter.stop()
def update(self, value, eta='-'):
self.counter.progress = value
self.counter.eta = eta
class rotor:
def __init__(self):
self.running = False
self.elements = ['/','-','\\']
def start(self):
self.running = True
i=0
while self.running:
if(i > 100):
i = 0
print ' {}\r'.format(self.elements[i%3]),
sys.stdout.flush()
i+=1
time.sleep(.2)
return True
def stop(self):
self.running = False
class linear:
def __init__(self):
self.progress = 0
self.elements = ['#','#','-']
self.eta = '-'
def start(self):
while self.progress <= 100:
print ' [{}{}{}] {}%\t\t{} sec\r'.format(self.elements[0]*(self.progress/5), self.elements[1],self.elements[2]*(20-(self.progress/5)), self.progress, self.eta),
sys.stdout.flush()
return True
def stop(self):
self.progress = 101