-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomProgress.py
More file actions
31 lines (23 loc) · 1023 Bytes
/
Copy pathCustomProgress.py
File metadata and controls
31 lines (23 loc) · 1023 Bytes
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
import progressbar
class PBar:
def __init__(self, label, maxValue=100, minValue = 0, width=120):
widgets = [label.ljust(22), ' ', progressbar.Percentage(), ' ', progressbar.Bar(), ' ',
progressbar.Timer(), ' ', progressbar.ETA(format_finished=' ')]
self.minValue = minValue
self.maxValue = maxValue
self.bar = progressbar.ProgressBar(widgets=widgets, maxval=maxValue, term_width=width).start()
def __enter__(self):
return self
def __exit__(self, exc_type, exc_val, exc_tb):
if exc_type:
print(f"An exception of type {exc_type} occurred.")
return False
def do_something(self):
print("Doing something within the context")
def update(self, value):
clamped = min(max(value, self.minValue), self.maxValue)
self.bar.update(clamped)
def getTime(self):
return (self.bar.last_update_time - self.bar.start_time).total_seconds()
def finish(self):
self.bar.finish()