- Added percentage meter to progress bar.

This commit is contained in:
ccremers 2004-11-19 11:22:03 +00:00
parent 5bf97e7c52
commit 149e2e5646

View File

@ -138,7 +138,12 @@ LastProgress = {}
ProgressBarWidth = 50 ProgressBarWidth = 50
def ShowProgress (i,n,txt): def ShowProgress (i,n,txt):
factor = int((ProgressBarWidth * i) / n) def IntegerPart (x):
return int (( x * i ) / n)
percentage = IntegerPart (100)
factor = IntegerPart (ProgressBarWidth)
showme = 0 showme = 0
if LastProgress.has_key(n): if LastProgress.has_key(n):
if LastProgress[n]<>(factor,txt): if LastProgress[n]<>(factor,txt):
@ -154,13 +159,13 @@ def ShowProgress (i,n,txt):
else: else:
bar = bar + "." bar = bar + "."
i = i+1 i = i+1
bar = bar + "] " + txt bar = bar + "] %3d%% " % percentage + txt
sys.stderr.write(bar) sys.stderr.write(bar)
sys.stderr.flush() sys.stderr.flush()
LastProgress[n] = (factor, txt) LastProgress[n] = (factor, txt)
def ClearProgress (n,txt): def ClearProgress (n,txt):
bar = " " * (1 + ProgressBarWidth + 2 + len(txt)) bar = " " * (1 + ProgressBarWidth + 2 + 5 + len(txt))
sys.stderr.write("\r" + bar + "\r") sys.stderr.write("\r" + bar + "\r")
sys.stderr.flush() sys.stderr.flush()