summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib/CallTipWindow.py
diff options
context:
space:
mode:
authorDavid Scherer <dscherer@cmu.edu>2000-08-15 01:13:23 (GMT)
committerDavid Scherer <dscherer@cmu.edu>2000-08-15 01:13:23 (GMT)
commit7aced17437a6b05bc4b0b5ff93aa6a5d3a374d68 (patch)
treece0576a16111fd86ac5f56ff4ec1500f29c4f8db /Lib/idlelib/CallTipWindow.py
parent33a6da9971a923ceaaee1406d0feaa64b8d1759a (diff)
downloadcpython-7aced17437a6b05bc4b0b5ff93aa6a5d3a374d68.zip
cpython-7aced17437a6b05bc4b0b5ff93aa6a5d3a374d68.tar.gz
cpython-7aced17437a6b05bc4b0b5ff93aa6a5d3a374d68.tar.bz2
Initial revision
Diffstat (limited to 'Lib/idlelib/CallTipWindow.py')
-rw-r--r--Lib/idlelib/CallTipWindow.py71
1 files changed, 71 insertions, 0 deletions
diff --git a/Lib/idlelib/CallTipWindow.py b/Lib/idlelib/CallTipWindow.py
new file mode 100644
index 0000000..cbeab8c
--- /dev/null
+++ b/Lib/idlelib/CallTipWindow.py
@@ -0,0 +1,71 @@
+# A CallTip window class for Tkinter/IDLE.
+# After ToolTip.py, which uses ideas gleaned from PySol
+
+# Used by the CallTips IDLE extension.
+import os
+from Tkinter import *
+
+class CallTip:
+
+ def __init__(self, widget):
+ self.widget = widget
+ self.tipwindow = None
+ self.id = None
+ self.x = self.y = 0
+
+ def showtip(self, text):
+ self.text = text
+ if self.tipwindow or not self.text:
+ return
+ self.widget.see("insert")
+ x, y, cx, cy = self.widget.bbox("insert")
+ x = x + self.widget.winfo_rootx() + 2
+ y = y + cy + self.widget.winfo_rooty()
+ self.tipwindow = tw = Toplevel(self.widget)
+ tw.wm_overrideredirect(1)
+ tw.wm_geometry("+%d+%d" % (x, y))
+ label = Label(tw, text=self.text, justify=LEFT,
+ background="#ffffe0", relief=SOLID, borderwidth=1,
+ font = self.widget['font'])
+ label.pack()
+
+ def hidetip(self):
+ tw = self.tipwindow
+ self.tipwindow = None
+ if tw:
+ tw.destroy()
+
+
+###############################
+#
+# Test Code
+#
+class container: # Conceptually an editor_window
+ def __init__(self):
+ root = Tk()
+ text = self.text = Text(root)
+ text.pack(side=LEFT, fill=BOTH, expand=1)
+ text.insert("insert", "string.split")
+ root.update()
+ self.calltip = CallTip(text)
+
+ text.event_add("<<calltip-show>>", "(")
+ text.event_add("<<calltip-hide>>", ")")
+ text.bind("<<calltip-show>>", self.calltip_show)
+ text.bind("<<calltip-hide>>", self.calltip_hide)
+
+ text.focus_set()
+ # root.mainloop() # not in idle
+
+ def calltip_show(self, event):
+ self.calltip.showtip("Hello world")
+
+ def calltip_hide(self, event):
+ self.calltip.hidetip()
+
+def main():
+ # Test code
+ c=container()
+
+if __name__=='__main__':
+ main()