mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
M CallTipWindow.py
M CallTips.py Calltip fetch was erroring when an Edit window was used without a Shell. Also, fix CallTipWindow.py so test code will run and add a comment about a bug which causes the calltip window to override all others.
This commit is contained in:
parent
7e5c6a02eb
commit
e54710bd72
2 changed files with 34 additions and 15 deletions
|
@ -1,7 +1,9 @@
|
||||||
# A CallTip window class for Tkinter/IDLE.
|
"""A CallTip window class for Tkinter/IDLE.
|
||||||
# After ToolTip.py, which uses ideas gleaned from PySol
|
|
||||||
|
|
||||||
# Used by the CallTips IDLE extension.
|
After ToolTip.py, which uses ideas gleaned from PySol
|
||||||
|
Used by the CallTips IDLE extension.
|
||||||
|
|
||||||
|
"""
|
||||||
from Tkinter import *
|
from Tkinter import *
|
||||||
|
|
||||||
class CallTip:
|
class CallTip:
|
||||||
|
@ -13,13 +15,11 @@ class CallTip:
|
||||||
self.x = self.y = 0
|
self.x = self.y = 0
|
||||||
|
|
||||||
def showtip(self, text):
|
def showtip(self, text):
|
||||||
# SF bug 546078: IDLE calltips cause application error.
|
" Display text in calltip window"
|
||||||
# There were crashes on various Windows flavors, and even a
|
# truncate overly long calltip
|
||||||
# crashing X server on Linux, with very long calltips.
|
|
||||||
if len(text) >= 79:
|
if len(text) >= 79:
|
||||||
text = text[:75] + ' ...'
|
text = text[:75] + ' ...'
|
||||||
self.text = text
|
self.text = text
|
||||||
|
|
||||||
if self.tipwindow or not self.text:
|
if self.tipwindow or not self.text:
|
||||||
return
|
return
|
||||||
self.widget.see("insert")
|
self.widget.see("insert")
|
||||||
|
@ -27,6 +27,10 @@ class CallTip:
|
||||||
x = x + self.widget.winfo_rootx() + 2
|
x = x + self.widget.winfo_rootx() + 2
|
||||||
y = y + cy + self.widget.winfo_rooty()
|
y = y + cy + self.widget.winfo_rooty()
|
||||||
self.tipwindow = tw = Toplevel(self.widget)
|
self.tipwindow = tw = Toplevel(self.widget)
|
||||||
|
# XXX 12 Dec 2002 KBK The following command has two effects: It removes
|
||||||
|
# the calltip window border (good) but also causes (at least on
|
||||||
|
# Linux) the calltip to show as a top level window, burning through
|
||||||
|
# any other window dragged over it. Also, shows on all viewports!
|
||||||
tw.wm_overrideredirect(1)
|
tw.wm_overrideredirect(1)
|
||||||
tw.wm_geometry("+%d+%d" % (x, y))
|
tw.wm_geometry("+%d+%d" % (x, y))
|
||||||
try:
|
try:
|
||||||
|
@ -68,7 +72,7 @@ class container: # Conceptually an editor_window
|
||||||
text.bind("<<calltip-hide>>", self.calltip_hide)
|
text.bind("<<calltip-hide>>", self.calltip_hide)
|
||||||
|
|
||||||
text.focus_set()
|
text.focus_set()
|
||||||
# root.mainloop() # not in idle
|
root.mainloop()
|
||||||
|
|
||||||
def calltip_show(self, event):
|
def calltip_show(self, event):
|
||||||
self.calltip.showtip("Hello world")
|
self.calltip.showtip("Hello world")
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
"""CallTips.py - An IDLE Extension to Jog Your Memory
|
"""CallTips.py - An IDLE Extension to Jog Your Memory
|
||||||
|
|
||||||
Call Tips are floating windows which display function/method parameter
|
Call Tips are floating windows which display function, class, and method
|
||||||
information as you open the parameter parenthesis, and which disappear when you
|
parameter and docstring information when you type an opening parenthesis, and
|
||||||
type the closing parenthesis. Future plans include extending the functionality
|
which disappear when you type a closing parenthesis.
|
||||||
to include class attributes.
|
|
||||||
|
Future plans include extending the functionality to include class attributes.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
import sys
|
import sys
|
||||||
|
@ -82,8 +83,21 @@ class CallTips:
|
||||||
return str[i:]
|
return str[i:]
|
||||||
|
|
||||||
def fetch_tip(self, name):
|
def fetch_tip(self, name):
|
||||||
interp = self.editwin and self.editwin.flist.pyshell.interp
|
"""Return the argument list and docstring of a function or class
|
||||||
rpcclt = interp and interp.rpcclt
|
|
||||||
|
If there is a Python subprocess, get the calltip there. Otherwise,
|
||||||
|
either fetch_tip() is running in the subprocess itself or it was called
|
||||||
|
in an IDLE EditorWindow before any script had been run.
|
||||||
|
|
||||||
|
The subprocess environment is that of the most recently run script. If
|
||||||
|
two unrelated modules are being edited some calltips in the current
|
||||||
|
module may be inoperative if the module was not the last to run.
|
||||||
|
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
rpcclt = self.editwin.flist.pyshell.interp.rpcclt
|
||||||
|
except:
|
||||||
|
rpcclt = None
|
||||||
if rpcclt:
|
if rpcclt:
|
||||||
return rpcclt.remotecall("exec", "get_the_calltip",
|
return rpcclt.remotecall("exec", "get_the_calltip",
|
||||||
(name,), {})
|
(name,), {})
|
||||||
|
@ -92,6 +106,7 @@ class CallTips:
|
||||||
return get_arg_text(entity)
|
return get_arg_text(entity)
|
||||||
|
|
||||||
def get_entity(self, name):
|
def get_entity(self, name):
|
||||||
|
"Lookup name in a namespace spanning sys.modules and __main.dict__"
|
||||||
if name:
|
if name:
|
||||||
namespace = sys.modules.copy()
|
namespace = sys.modules.copy()
|
||||||
namespace.update(__main__.__dict__)
|
namespace.update(__main__.__dict__)
|
||||||
|
@ -112,7 +127,7 @@ def _find_constructor(class_ob):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_arg_text(ob):
|
def get_arg_text(ob):
|
||||||
# Get a string describing the arguments for the given object.
|
"Get a string describing the arguments for the given object"
|
||||||
argText = ""
|
argText = ""
|
||||||
if ob is not None:
|
if ob is not None:
|
||||||
argOffset = 0
|
argOffset = 0
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue