1 # $Header: /home/eficas/CVSROOT/EficasV1/Tools/foztools/foztools.py,v 1.1.1.1 2001/12/04 15:38:23 eficas Exp $
3 ###########################################################################
4 # This is a set of Python widgets, built on top of pythonTk. They are
5 # designed to be highly customizable, flexible, and useful. They are
6 # also all built from the base PythonTk widgets so no other external
7 # libraries are needed.
9 # Use it in good health. It's hereby released under the GPL, if you
10 # have questions about the GPL contact the Free Software Foundation.
12 # Author: Gary D. Foster <Gary.Foster@corp.sun.com>
13 # with some ideas stolen from Mitch Chapman's stuff.
15 ###########################################################################
17 __version__ = "$Revision: 1.1.1.1 $"
23 def __init__(self, master=None, orientation="horizontal", min=0, max=100,
24 width=100, height=25, autoLabel="true", appearance="sunken",
25 fillColor="blue", background="black", labelColor="yellow",
26 labelText="", labelFormat="%d%%", value=50, bd=2):
27 # preserve various values
29 self.orientation=orientation
34 self.autoLabel=autoLabel
35 self.fillColor=fillColor
36 self.labelColor=labelColor
37 self.background=background
38 self.labelText=labelText
39 self.labelFormat=labelFormat
41 self.frame=Tk.Frame(master, relief=appearance, bd=bd)
42 self.canvas=Tk.Canvas(self.frame, height=height, width=width, bd=0,
43 highlightthickness=0, background=background)
44 self.scale=self.canvas.create_rectangle(0, 0, width, height,
46 self.label=self.canvas.create_text(self.canvas.winfo_reqwidth() / 2,
47 height / 2, text=labelText,
48 anchor="c", fill=labelColor)
50 self.canvas.pack(side='top', fill='x', expand='no')
53 # Trim the values to be between min and max
59 # Preserve the new value
61 # Adjust the rectangle
62 if self.orientation == "horizontal":
65 float(value) / self.max * self.width, self.height)
68 0, self.height - (float(value) / self.max*self.height),
69 self.width, self.height)
70 # Now update the colors
71 c.itemconfig(self.scale, fill=self.fillColor)
72 c.itemconfig(self.label, fill=self.labelColor)
73 # And update the label
74 if self.autoLabel=="true":
75 c.itemconfig(self.label, text=self.labelFormat % value)
77 c.itemconfig(self.label, text=self.labelFormat % self.labelText)
81 def __init__(self, master=None, width=25, height=25, appearance="sunken",
82 onColor="green", offColor="black", onLabelColor="black",
83 offLabelColor="green", onLabelText="", offLabelText="",
85 # preserve various values
88 self.offColor=offColor
89 self.onLabelColor=onLabelColor
90 self.offLabelColor=offLabelColor
91 self.onLabelText=onLabelText
92 self.offLabelText=offLabelText
94 self.frame=Tk.Frame(master, relief=appearance, bd=bd)
95 self.canvas=Tk.Canvas(self.frame, height=height, width=width, bd=0,
97 self.light=self.canvas.create_rectangle(0, 0, width, height,
99 self.label=self.canvas.create_text(self.canvas.winfo_reqwidth() / 2,
100 height / 2, text=onLabelText,
101 anchor="c", fill=onLabelColor)
103 self.canvas.pack(side="top", fill='x', expand='no')
107 # now update the status
109 c.itemconfig(self.light, fill=self.onColor)
110 c.itemconfig(self.label, fill=self.onLabelColor)
111 c.itemconfig(self.label, text=self.onLabelText)
113 c.itemconfig(self.light, fill=self.offColor)
114 c.itemconfig(self.label, fill=self.offLabelColor)
115 c.itemconfig(self.label, text=self.offLabelText)
130 class Blinker(Indicator):
131 def __init__(self, master=None, blinkrate=1, enabled=1, width=25,
132 height=25, appearance="sunken", onColor="green",
133 offColor="black", onLabelColor="black", offLabelColor="green",
134 onLabelText="", offLabelText="", on=1, bd=2):
135 self.blinkrate=blinkrate
137 Indicator.__init__(self, master, width=width, height=height,
138 appearance=appearance, onColor=onColor,
139 offColor=offColor, onLabelColor=onLabelColor,
140 offLabelColor=offLabelColor,
141 onLabelText=onLabelText,
142 offLabelText=offLabelText, on=on, bd=bd)
147 Indicator.update(self)
148 self.frame.after(self.blinkrate * 1000, self.update)