1 # -*- coding: utf-8 -*-
2 # $Header: /home/eficas/CVSROOT/EficasV1/Tools/foztools/foztools.py,v 1.2.8.1 2006/03/10 15:08:29 eficas Exp $
4 ###########################################################################
5 # This is a set of Python widgets, built on top of pythonTk. They are
6 # designed to be highly customizable, flexible, and useful. They are
7 # also all built from the base PythonTk widgets so no other external
8 # libraries are needed.
10 # Use it in good health. It's hereby released under the GPL, if you
11 # have questions about the GPL contact the Free Software Foundation.
13 # Author: Gary D. Foster <Gary.Foster@corp.sun.com>
14 # with some ideas stolen from Mitch Chapman's stuff.
16 ###########################################################################
18 __version__ = "$Revision: 1.2.8.1 $"
24 def __init__(self, master=None, orientation="horizontal", min=0, max=100,
25 width=100, height=25, autoLabel="true", appearance="sunken",
26 fillColor="blue", background="black", labelColor="yellow",
27 labelText="", labelFormat="%d%%", value=50, bd=2):
28 # preserve various values
30 self.orientation=orientation
35 self.autoLabel=autoLabel
36 self.fillColor=fillColor
37 self.labelColor=labelColor
38 self.background=background
39 self.labelText=labelText
40 self.labelFormat=labelFormat
42 self.frame=Tk.Frame(master, relief=appearance, bd=bd)
43 self.canvas=Tk.Canvas(self.frame, height=height, width=width, bd=0,
44 highlightthickness=0, background=background)
45 self.scale=self.canvas.create_rectangle(0, 0, width, height,
47 self.label=self.canvas.create_text(self.canvas.winfo_reqwidth() / 2,
48 height / 2, text=labelText,
49 anchor="c", fill=labelColor)
51 self.canvas.pack(side='top', fill='x', expand='no')
54 # Trim the values to be between min and max
60 # Preserve the new value
62 # Adjust the rectangle
63 if self.orientation == "horizontal":
66 float(value) / self.max * self.width, self.height)
69 0, self.height - (float(value) / self.max*self.height),
70 self.width, self.height)
71 # Now update the colors
72 c.itemconfig(self.scale, fill=self.fillColor)
73 c.itemconfig(self.label, fill=self.labelColor)
74 # And update the label
75 if self.autoLabel=="true":
76 c.itemconfig(self.label, text=self.labelFormat % value)
78 c.itemconfig(self.label, text=self.labelFormat % self.labelText)
82 def __init__(self, master=None, width=25, height=25, appearance="sunken",
83 onColor="green", offColor="black", onLabelColor="black",
84 offLabelColor="green", onLabelText="", offLabelText="",
86 # preserve various values
89 self.offColor=offColor
90 self.onLabelColor=onLabelColor
91 self.offLabelColor=offLabelColor
92 self.onLabelText=onLabelText
93 self.offLabelText=offLabelText
95 self.frame=Tk.Frame(master, relief=appearance, bd=bd)
96 self.canvas=Tk.Canvas(self.frame, height=height, width=width, bd=0,
98 self.light=self.canvas.create_rectangle(0, 0, width, height,
100 self.label=self.canvas.create_text(self.canvas.winfo_reqwidth() / 2,
101 height / 2, text=onLabelText,
102 anchor="c", fill=onLabelColor)
104 self.canvas.pack(side="top", fill='x', expand='no')
108 # now update the status
110 c.itemconfig(self.light, fill=self.onColor)
111 c.itemconfig(self.label, fill=self.onLabelColor)
112 c.itemconfig(self.label, text=self.onLabelText)
114 c.itemconfig(self.light, fill=self.offColor)
115 c.itemconfig(self.label, fill=self.offLabelColor)
116 c.itemconfig(self.label, text=self.offLabelText)
131 class Blinker(Indicator):
132 def __init__(self, master=None, blinkrate=1, enabled=1, width=25,
133 height=25, appearance="sunken", onColor="green",
134 offColor="black", onLabelColor="black", offLabelColor="green",
135 onLabelText="", offLabelText="", on=1, bd=2):
136 self.blinkrate=blinkrate
138 Indicator.__init__(self, master, width=width, height=height,
139 appearance=appearance, onColor=onColor,
140 offColor=offColor, onLabelColor=onLabelColor,
141 offLabelColor=offLabelColor,
142 onLabelText=onLabelText,
143 offLabelText=offLabelText, on=on, bd=bd)
148 Indicator.update(self)
149 self.frame.after(self.blinkrate * 1000, self.update)