summaryrefslogtreecommitdiff
path: root/uitools/ProgressBar.py
blob: 0098ead43ee46cd5eb4563b7d4feac4d9ef33f81 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
######################################################################
# This module provides a progress bar, analogous to the progress
# sliders in Win 3.1 or the progress slider in Netscape Nav.
# 
# Mitch Chapman
#---------------------------------------------------------------------
# $Log: ProgressBar.py,v $
# Revision 1.1  1996/12/01 22:58:54  mchapman
# Initial revision
#
######################################################################

__version__ = "$Revision: 1.1 $"

import Tkinter; Tk=Tkinter

######################################################################
# This class provides a progress slider embedded within a Tk frame.
######################################################################
class T:
    ##################################################################
    # Initialize a new instance.
    ##################################################################
    def __init__(self, master=None, height=25, fillColor="blue"):
	# Put the sunken relief on the frame, not the canvas.
	# This way, if some subclass decides to embed a window within
	# the canvas, the window won't ever draw itself into the
	# relief area.
	self.master = master
	self.frame = Tk.Frame(master, relief='sunken', bd=2)
	self.canvas = Tk.Canvas(self.frame, height=height, bd=0,
				highlightthickness=0)
	self.scale = self.canvas.create_rectangle(-10, -10, 0, height,
						  fill=fillColor)
	self.canvas.pack(side='top', fill='x', expand='no')

    ##################################################################
    # Specify the completion value for self.
    # percentComplete must be in the range 0..100, inclusive.
    ##################################################################
    def update(self, percentComplete):
	c = self.canvas
	width, height = c.winfo_reqwidth(), c.winfo_reqheight()
	c.coords(self.scale, -10, -10,
		 percentComplete * width / 100.0, height)
	c.update_idletasks()


######################################################################
# Main function for unit testing.
######################################################################
def main():
    class Test:
	def __init__(self):
	    self.progress = T()
	    self.fraction = 0
	    self.progress.frame.pack()
	    self.progress.frame.after(1000, self.update)
	    
	def update(self, event=None):
	    self.fraction = self.fraction + 1
	    self.progress.update(self.fraction)
	    self.progress.frame.after(30, self.update)

    t = Test()
    Tk.mainloop()

if __name__ == "__main__":
    main()