From 9aa5ea82751da101d7bba1729ef6aea46e1c1acc Mon Sep 17 00:00:00 2001 From: Ruckdeschel Oscar Date: Sat, 21 Oct 2017 20:07:00 +0200 Subject: [PATCH] Enable multiple progressbars be created. This is useful for e.g. multiple lined up downloads. --- clint/textui/progress.py | 5 ++++- examples/progressbar.py | 10 ++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/clint/textui/progress.py b/clint/textui/progress.py index da4bb9b..485e795 100644 --- a/clint/textui/progress.py +++ b/clint/textui/progress.py @@ -87,7 +87,10 @@ def show(self, progress, count=None): self.expected_size, self.etadisp)) STREAM.flush() - def done(self): + def done(self, create_new=False): + if create_new: + return Bar(self.label, self.width, self.hide, self.empty_char, + self.filled_char, self.expected_size, self.every) self.elapsed = time.time() - self.start elapsed_disp = self.format_time(self.elapsed) if not self.hide: diff --git a/examples/progressbar.py b/examples/progressbar.py index f165900..3c7d9a4 100755 --- a/examples/progressbar.py +++ b/examples/progressbar.py @@ -12,12 +12,18 @@ if __name__ == '__main__': + with progress.Bar(expected_size=100.) as bar: + for i in range(3): + for i in range(100): + sleep(0.01) + bar.show(i) + bar = bar.done(i is not 3) for i in progress.bar(range(100)): sleep(random() * 0.2) - + with progress.Bar(label="nonlinear", expected_size=10) as bar: last_val = 0 - for val in (1,2,3,9,10): + for val in (1, 2, 3, 9, 10): sleep(2 * (val - last_val)) bar.show(val) last_val = val