1 # -*- coding: utf-8 -*-
2 # CONFIGURATION MANAGEMENT OF EDF VERSION
3 # ======================================================================
4 # COPYRIGHT (C) 1991 - 2002 EDF R&D WWW.CODE-ASTER.ORG
5 # THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
6 # IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE AS PUBLISHED BY
7 # THE FREE SOFTWARE FOUNDATION; EITHER VERSION 2 OF THE LICENSE, OR
8 # (AT YOUR OPTION) ANY LATER VERSION.
10 # THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT
11 # WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF
12 # MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU
13 # GENERAL PUBLIC LICENSE FOR MORE DETAILS.
15 # YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE
16 # ALONG WITH THIS PROGRAM; IF NOT, WRITE TO EDF R&D CODE_ASTER,
17 # 1 AVENUE DU GENERAL DE GAULLE, 92141 CLAMART CEDEX, FRANCE.
20 # ======================================================================
22 Ce module propose la classe TOOLTIP pour
23 mettre en oeuvre les bulles d'aide
30 # assist in breaking circular references
32 assert type(obj) is types.InstanceType
33 for k in obj.__dict__.keys():
34 obj.__dict__[k] = None
37 def after(widget, ms, func, *args):
38 timer = apply(widget.after, (ms, func) + args)
39 command = widget._tclCommands[-1]
40 return (timer, command, widget)
44 t[2].after_cancel(t[0])
46 t[2].deletecommand(t[1])
47 except Tkinter.TclError:
51 def __init__(self,widget,text=None):
58 self.bindings.append(self.widget.bind("<Enter>", self._enter))
59 self.bindings.append(self.widget.bind("<Leave>", self._leave))
60 self.bindings.append(self.widget.bind("<ButtonPress>", self._leave))
61 # user overrideable settings
62 self.time = 1000 # milliseconds
63 self.relief = Tkinter.SOLID
64 self.justify = Tkinter.LEFT
70 def setText(self, text):
74 if self.bindings and self.widget:
75 self.widget.unbind("<Enter>", self.bindings[0])
76 self.widget.unbind("<Leave>", self.bindings[1])
77 self.widget.unbind("<ButtonPress>", self.bindings[2])
84 def _enter(self, *event):
85 after_cancel(self.timer)
86 self.timer = after(self.widget, self.time, self._showTip)
88 def _leave(self, *event):
89 after_cancel(self.timer)
95 self.tooltip.destroy()
96 destruct(self.tooltip)
100 if self.tooltip or not self.text:
102 c = self.widget.__class__
103 if c in (Tkinter.Button,):
104 if self.widget["state"] == Tkinter.DISABLED:
106 x = self.widget.winfo_rootx()
107 y = self.widget.winfo_rooty() + self.widget.winfo_height()
110 self.tooltip = Tkinter.Toplevel()
111 self.tooltip.wm_iconify()
112 self.tooltip.wm_overrideredirect(1)
113 self.tooltip.wm_protocol("WM_DELETE_WINDOW", self.destroy)
114 self.label = Tkinter.Label(self.tooltip, text=self.text,
115 relief=self.relief, justify=self.justify,
116 fg=self.fg, bg=self.bg, bd=1, takefocus=0)
117 self.label.pack(ipadx=1, ipady=1)
118 self.tooltip.wm_geometry("%+d%+d" % (x, y))
119 self.tooltip.wm_deiconify()
121 if __name__ == "__main__":
123 label = Tkinter.Label(root, text="coucou")
125 tp=TOOLTIP(label,"texte d'aide")