Salome HOME
AY a ajouté l'interception de l'exception levée lorsque la chaine passée
[tools/eficas.git] / Tools / foztools / foztools.py
1 # $Header: /home/eficas/CVSROOT/EficasV1/Tools/foztools/foztools.py,v 1.1.1.1 2001/12/04 15:38:23 eficas Exp $
2
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.
8 #
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.
11 #
12 # Author: Gary D. Foster <Gary.Foster@corp.sun.com>
13 #  with some ideas stolen from Mitch Chapman's stuff.
14 #
15 ###########################################################################
16
17 __version__ = "$Revision: 1.1.1.1 $"
18
19 import Tkinter
20 Tk=Tkinter
21
22 class Slider:
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
28         self.master=master
29         self.orientation=orientation
30         self.min=min
31         self.max=max
32         self.width=width
33         self.height=height
34         self.autoLabel=autoLabel
35         self.fillColor=fillColor
36         self.labelColor=labelColor
37         self.background=background
38         self.labelText=labelText
39         self.labelFormat=labelFormat
40         self.value=value
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,
45                                                 fill=fillColor)
46         self.label=self.canvas.create_text(self.canvas.winfo_reqwidth() / 2,
47                                            height / 2, text=labelText,
48                                            anchor="c", fill=labelColor)
49         self.update()
50         self.canvas.pack(side='top', fill='x', expand='no')
51
52     def update(self):
53         # Trim the values to be between min and max
54         value=self.value
55         if value > self.max:
56             value = self.max
57         if value < self.min:
58             value = self.min
59         # Preserve the new value
60         c=self.canvas
61         # Adjust the rectangle
62         if self.orientation == "horizontal":
63             c.coords(self.scale,
64                      0, 0,
65                      float(value) / self.max * self.width, self.height)
66         else:
67             c.coords(self.scale,
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)
76         else:
77             c.itemconfig(self.label, text=self.labelFormat % self.labelText)
78         c.update_idletasks()
79
80 class Indicator:
81     def __init__(self, master=None, width=25, height=25, appearance="sunken",
82                  onColor="green", offColor="black", onLabelColor="black",
83                  offLabelColor="green", onLabelText="", offLabelText="",
84                  on=1, bd=2):
85         # preserve various values
86         self.master=master
87         self.onColor=onColor
88         self.offColor=offColor
89         self.onLabelColor=onLabelColor
90         self.offLabelColor=offLabelColor
91         self.onLabelText=onLabelText
92         self.offLabelText=offLabelText
93         self.on=on
94         self.frame=Tk.Frame(master, relief=appearance, bd=bd)
95         self.canvas=Tk.Canvas(self.frame, height=height, width=width, bd=0,
96                               highlightthickness=0)
97         self.light=self.canvas.create_rectangle(0, 0, width, height,
98                                                 fill=onLabelColor)
99         self.label=self.canvas.create_text(self.canvas.winfo_reqwidth() / 2,
100                                            height / 2, text=onLabelText,
101                                            anchor="c", fill=onLabelColor)
102         self.update()
103         self.canvas.pack(side="top", fill='x', expand='no')
104
105     def update(self):
106         c=self.canvas
107         # now update the status
108         if self.on:
109             c.itemconfig(self.light, fill=self.onColor)
110             c.itemconfig(self.label, fill=self.onLabelColor)
111             c.itemconfig(self.label, text=self.onLabelText)
112         else:
113             c.itemconfig(self.light, fill=self.offColor)
114             c.itemconfig(self.label, fill=self.offLabelColor)
115             c.itemconfig(self.label, text=self.offLabelText)
116         c.update_idletasks()
117
118     def toggle(self):
119         self.on=not self.on
120         self.update()
121
122     def turnon(self):
123         self.on=1
124         self.update()
125
126     def turnoff(self):
127         self.on=0
128         self.update()
129
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
136         self.enabled=enabled
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)
143
144     def update(self):
145         if self.enabled:
146             self.on=not self.on
147         Indicator.update(self)
148         self.frame.after(self.blinkrate * 1000, self.update)
149
150