1 # A CallTip window class for Tkinter/IDLE.
2 # After ToolTip.py, which uses ideas gleaned from PySol
4 # Used by the CallTips IDLE extension.
10 def __init__(self
, widget
):
16 def showtip(self
, text
):
17 # SF bug 546078: IDLE calltips cause application error.
18 # There were crashes on various Windows flavors, and even a
19 # crashing X server on Linux, with very long calltips.
21 text
= text
[:75] + ' ...'
24 if self
.tipwindow
or not self
.text
:
26 self
.widget
.see("insert")
27 x
, y
, cx
, cy
= self
.widget
.bbox("insert")
28 x
= x
+ self
.widget
.winfo_rootx() + 2
29 y
= y
+ cy
+ self
.widget
.winfo_rooty()
30 self
.tipwindow
= tw
= Toplevel(self
.widget
)
31 tw
.wm_overrideredirect(1)
32 tw
.wm_geometry("+%d+%d" % (x
, y
))
33 label
= Label(tw
, text
=self
.text
, justify
=LEFT
,
34 background
="#ffffe0", relief
=SOLID
, borderwidth
=1,
35 font
= self
.widget
['font'])
45 ###############################
49 class container
: # Conceptually an editor_window
52 text
= self
.text
= Text(root
)
53 text
.pack(side
=LEFT
, fill
=BOTH
, expand
=1)
54 text
.insert("insert", "string.split")
56 self
.calltip
= CallTip(text
)
58 text
.event_add("<<calltip-show>>", "(")
59 text
.event_add("<<calltip-hide>>", ")")
60 text
.bind("<<calltip-show>>", self
.calltip_show
)
61 text
.bind("<<calltip-hide>>", self
.calltip_hide
)
64 # root.mainloop() # not in idle
66 def calltip_show(self
, event
):
67 self
.calltip
.showtip("Hello world")
69 def calltip_hide(self
, event
):
70 self
.calltip
.hidetip()
76 if __name__
=='__main__':