rescaleProgress now deals with two-element and non-tuple yields
This commit is contained in:
parent
800ab23427
commit
c7b009b59c
@ -12,15 +12,26 @@ def rescaleProgress(iterable, start, end):
|
|||||||
Given an iterable that yields (current, maximum, status) tuples, rescales current and maximum
|
Given an iterable that yields (current, maximum, status) tuples, rescales current and maximum
|
||||||
to fit within the range [start, end]. `current` is assumed to start at zero.
|
to fit within the range [start, end]. `current` is assumed to start at zero.
|
||||||
|
|
||||||
|
Use rescaleProgress to combine multiple progress-yielding iterables by assigning
|
||||||
|
a different range to each iterable.
|
||||||
|
|
||||||
:param iterable:
|
:param iterable:
|
||||||
:param start:
|
:param start:
|
||||||
:param end:
|
:param end:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
d = end - start
|
d = end - start
|
||||||
|
status = ""
|
||||||
|
|
||||||
for current, maximum, status in iterable:
|
for progress in iterable:
|
||||||
yield start + current * d / maximum, end, status
|
if isinstance(progress, tuple):
|
||||||
|
current, maximum = progress[:2]
|
||||||
|
if len(progress) > 2:
|
||||||
|
status = progress[2]
|
||||||
|
|
||||||
|
yield start + current * d / maximum, end, status
|
||||||
|
else:
|
||||||
|
yield progress
|
||||||
|
|
||||||
|
|
||||||
def enumProgress(collection, start, end=None):
|
def enumProgress(collection, start, end=None):
|
||||||
@ -28,6 +39,9 @@ def enumProgress(collection, start, end=None):
|
|||||||
Iterate through a collection, yielding (progress, value) tuples. `progress` is the value
|
Iterate through a collection, yielding (progress, value) tuples. `progress` is the value
|
||||||
between `start` and `end` proportional to the progress through the collection.
|
between `start` and `end` proportional to the progress through the collection.
|
||||||
|
|
||||||
|
Use enumProgress to report the progress of iterating through a collection, scaled
|
||||||
|
to a fixed amount of progress.
|
||||||
|
|
||||||
:param collection:
|
:param collection:
|
||||||
:param progress:
|
:param progress:
|
||||||
:return:
|
:return:
|
||||||
|
Reference in New Issue
Block a user