ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/NinoCode/Tool_Box/textProgressIndicator.py
Revision: 8
Committed: Sat May 5 04:21:19 2012 UTC (13 years, 10 months ago) by ninoborges
Content type: text/x-python
File size: 2498 byte(s)
Log Message:
Initial Import

File Contents

# Content
1 # CLASS NAME: DLLInterface
2 #
3 # Author: Larry Bates (lbates@syscononline.com)
4 #
5 # Written: 12/09/2002
6 #
7 # Released under: GNU GENERAL PUBLIC LICENSE
8 #
9 #
10 class progressbarClass:
11 def __init__(self, finalcount, progresschar=None):
12 import sys
13 self.finalcount=finalcount
14 self.blockcount=0
15 #
16 # See if caller passed me a character to use on the
17 # progress bar (like "*"). If not use the block
18 # character that makes it look like a real progress
19 # bar.
20 #
21 if not progresschar: self.block=chr(178)
22 else: self.block=progresschar
23 #
24 # Get pointer to sys.stdout so I can use the write/flush
25 # methods to display the progress bar.
26 #
27 self.f=sys.stdout
28 #
29 # If the final count is zero, don't start the progress gauge
30 #
31 if not self.finalcount : return
32 self.f.write('\n------------------ % Progress -------------------1\n')
33 self.f.write(' 1 2 3 4 5 6 7 8 9 0\n')
34 self.f.write('----0----0----0----0----0----0----0----0----0----0\n')
35 return
36
37 def progress(self, count):
38 #
39 # Make sure I don't try to go off the end (e.g. >100%)
40 #
41 count=min(count, self.finalcount)
42 #
43 # If finalcount is zero, I'm done
44 #
45 if self.finalcount:
46 percentcomplete=int(round(100*count/self.finalcount))
47 if percentcomplete < 1: percentcomplete=1
48 else:
49 percentcomplete=100
50
51 #print "percentcomplete=",percentcomplete
52 blockcount=int(percentcomplete/2)
53 #print "blockcount=",blockcount
54 if blockcount > self.blockcount:
55 for i in range(self.blockcount,blockcount):
56 self.f.write(self.block)
57 self.f.flush()
58
59 if percentcomplete == 100: self.f.write("\n")
60 self.blockcount=blockcount
61 return
62
63 if __name__ == "__main__":
64 from time import sleep
65 pb=progressbarClass(8,"*")
66 count=0
67 while count<9:
68 count+=1
69 pb.progress(count)
70 sleep(0.2)
71
72 pb=progressbarClass(100)
73 pb.progress(20)
74 sleep(0.2)
75 pb.progress(47)
76 sleep(0.2)
77 pb.progress(90)
78 sleep(0.2)
79 pb.progress(100)
80 print "testing 1:"
81 pb=progressbarClass(1)
82 pb.progress(1)