1 # CONFIGURATION MANAGEMENT OF EDF VERSION
2 # ======================================================================
3 # COPYRIGHT (C) 1991 - 2002 EDF R&D WWW.CODE-ASTER.ORG
4 # THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
5 # IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE AS PUBLISHED BY
6 # THE FREE SOFTWARE FOUNDATION; EITHER VERSION 2 OF THE LICENSE, OR
7 # (AT YOUR OPTION) ANY LATER VERSION.
9 # THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT
10 # WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF
11 # MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU
12 # GENERAL PUBLIC LICENSE FOR MORE DETAILS.
14 # YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE
15 # ALONG WITH THIS PROGRAM; IF NOT, WRITE TO EDF R&D CODE_ASTER,
16 # 1 AVENUE DU GENERAL DE GAULLE, 92141 CLAMART CEDEX, FRANCE.
19 # ======================================================================
21 Ce module propose la classe TOOLTIP pour
22 mettre en oeuvre les bulles d'aide
28 def __init__(self,widget):
35 self.bindings.append(self.widget.bind("<Enter>", self._enter))
36 self.bindings.append(self.widget.bind("<Leave>", self._leave))
37 self.bindings.append(self.widget.bind("<ButtonPress>", self._leave))
38 # user overrideable settings
39 self.time = 1000 # milliseconds
40 self.relief = Tkinter.SOLID
41 self.justify = Tkinter.LEFT
47 def setText(self, text):
51 if self.bindings and self.widget:
52 self.widget.unbind("<Enter>", self.bindings[0])
53 self.widget.unbind("<Leave>", self.bindings[1])
54 self.widget.unbind("<ButtonPress>", self.bindings[2])
61 def _enter(self, *event):
62 after_cancel(self.timer)
63 self.timer = after(self.widget, self.time, self._showTip)
65 def _leave(self, *event):
66 after_cancel(self.timer)
72 self.tooltip.destroy()
73 destruct(self.tooltip)
77 if self.tooltip or not self.text:
79 c = self.widget.__class__
80 if c in (Tkinter.Button,):
81 if self.widget["state"] == Tkinter.DISABLED:
83 x = self.widget.winfo_rootx()
84 y = self.widget.winfo_rooty() + self.widget.winfo_height()
87 self.tooltip = Tkinter.Toplevel()
88 self.tooltip.wm_iconify()
89 self.tooltip.wm_overrideredirect(1)
90 self.tooltip.wm_protocol("WM_DELETE_WINDOW", self.destroy)
91 self.label = Tkinter.Label(self.tooltip, text=self.text,
92 relief=self.relief, justify=self.justify,
93 fg=self.fg, bg=self.bg, bd=1, takefocus=0)
94 self.label.pack(ipadx=1, ipady=1)
95 self.tooltip.wm_geometry("%+d%+d" % (x, y))
96 self.tooltip.wm_deiconify()