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
29 # assist in breaking circular references
31 assert type(obj) is types.InstanceType
32 for k in obj.__dict__.keys():
33 obj.__dict__[k] = None
36 def after(widget, ms, func, *args):
37 timer = apply(widget.after, (ms, func) + args)
38 command = widget._tclCommands[-1]
39 return (timer, command, widget)
43 t[2].after_cancel(t[0])
45 t[2].deletecommand(t[1])
46 except Tkinter.TclError:
50 def __init__(self,widget,text=None):
57 self.bindings.append(self.widget.bind("<Enter>", self._enter))
58 self.bindings.append(self.widget.bind("<Leave>", self._leave))
59 self.bindings.append(self.widget.bind("<ButtonPress>", self._leave))
60 # user overrideable settings
61 self.time = 1000 # milliseconds
62 self.relief = Tkinter.SOLID
63 self.justify = Tkinter.LEFT
69 def setText(self, text):
73 if self.bindings and self.widget:
74 self.widget.unbind("<Enter>", self.bindings[0])
75 self.widget.unbind("<Leave>", self.bindings[1])
76 self.widget.unbind("<ButtonPress>", self.bindings[2])
83 def _enter(self, *event):
84 after_cancel(self.timer)
85 self.timer = after(self.widget, self.time, self._showTip)
87 def _leave(self, *event):
88 after_cancel(self.timer)
94 self.tooltip.destroy()
95 destruct(self.tooltip)
99 if self.tooltip or not self.text:
101 c = self.widget.__class__
102 if c in (Tkinter.Button,):
103 if self.widget["state"] == Tkinter.DISABLED:
105 x = self.widget.winfo_rootx()
106 y = self.widget.winfo_rooty() + self.widget.winfo_height()
109 self.tooltip = Tkinter.Toplevel()
110 self.tooltip.wm_iconify()
111 self.tooltip.wm_overrideredirect(1)
112 self.tooltip.wm_protocol("WM_DELETE_WINDOW", self.destroy)
113 self.label = Tkinter.Label(self.tooltip, text=self.text,
114 relief=self.relief, justify=self.justify,
115 fg=self.fg, bg=self.bg, bd=1, takefocus=0)
116 self.label.pack(ipadx=1, ipady=1)
117 self.tooltip.wm_geometry("%+d%+d" % (x, y))
118 self.tooltip.wm_deiconify()
120 if __name__ == "__main__":
122 label = Tkinter.Label(root, text="coucou")
124 tp=TOOLTIP(label,"texte d'aide")