Bump to 2.3.1 to pick up the missing file.
[python/dscho.git] / Tools / idle / CallTipWindow.py
blobdb1e346c55dc54433299c042695d7bb31629af1e
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.
5 import os
6 from Tkinter import *
8 class CallTip:
10 def __init__(self, widget):
11 self.widget = widget
12 self.tipwindow = None
13 self.id = None
14 self.x = self.y = 0
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.
20 if len(text) >= 79:
21 text = text[:75] + ' ...'
22 self.text = text
24 if self.tipwindow or not self.text:
25 return
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'])
36 label.pack()
38 def hidetip(self):
39 tw = self.tipwindow
40 self.tipwindow = None
41 if tw:
42 tw.destroy()
45 ###############################
47 # Test Code
49 class container: # Conceptually an editor_window
50 def __init__(self):
51 root = Tk()
52 text = self.text = Text(root)
53 text.pack(side=LEFT, fill=BOTH, expand=1)
54 text.insert("insert", "string.split")
55 root.update()
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)
63 text.focus_set()
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()
72 def main():
73 # Test code
74 c=container()
76 if __name__=='__main__':
77 main()