""" Print status dots Revision History ---------------- Version 1.0 -- December 28, 1998, Andrew Sterian (asterian@umich.edu) * Initial release """ import sys _enable=1 _count=0 _dots=0 _total=0 _fid = None def Enable(onoff): "Set boolean state of dot display" global _enable _enable = onoff def InitDots(N, fid=None, NumDots=80): "Initialize dot display for N iterations of something" global _dots global _count global _enable global _total global _fid if not _enable: return _fid = fid if not _fid: _fid=sys.stdout if N >= 1: _dots = (N-1)/NumDots+1 _total = (N-1)/_dots _fid.write('*' * _total) _fid.flush() else: _dots = 0 _total = 0 _count = _dots def Dot(): "Count down one iteration" global _dots global _count global _enable global _total global _fid if not _enable: return if _total <= 0: return _count = _count - 1 if _count <= 0: _fid.write('\b \b') _fid.flush() _count = _dots _total = _total - 1 def Clear(): "Erase all remaining dots" global _dots global _count global _total global _enable if not _enable: return if _total > 0: _fid.write('\b \b' * _total) _fid.flush() _total = _dots = _count = 0 if __name__ == "__main__": import time print 'Testing dots...' InitDots(1000) for i in range(1000): time.sleep(0.001) Dot() print 'Testing clear function...' InitDots(1000) for i in range(500): time.sleep(0.001) Dot() Clear() print 'Testing alternate stream and dot count...' InitDots(1000, sys.stderr, 40) for i in range(1000): time.sleep(0.001) Dot()