Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python2..../idlelib
File: CallTipWindow.py
"""A CallTip window class for Tkinter/IDLE.
[0] Fix | Delete
[1] Fix | Delete
After ToolTip.py, which uses ideas gleaned from PySol
[2] Fix | Delete
Used by the CallTips IDLE extension.
[3] Fix | Delete
"""
[4] Fix | Delete
from Tkinter import Toplevel, Label, LEFT, SOLID, TclError
[5] Fix | Delete
[6] Fix | Delete
HIDE_VIRTUAL_EVENT_NAME = "<<calltipwindow-hide>>"
[7] Fix | Delete
HIDE_SEQUENCES = ("<Key-Escape>", "<FocusOut>")
[8] Fix | Delete
CHECKHIDE_VIRTUAL_EVENT_NAME = "<<calltipwindow-checkhide>>"
[9] Fix | Delete
CHECKHIDE_SEQUENCES = ("<KeyRelease>", "<ButtonRelease>")
[10] Fix | Delete
CHECKHIDE_TIME = 100 # milliseconds
[11] Fix | Delete
[12] Fix | Delete
MARK_RIGHT = "calltipwindowregion_right"
[13] Fix | Delete
[14] Fix | Delete
class CallTip:
[15] Fix | Delete
[16] Fix | Delete
def __init__(self, widget):
[17] Fix | Delete
self.widget = widget
[18] Fix | Delete
self.tipwindow = self.label = None
[19] Fix | Delete
self.parenline = self.parencol = None
[20] Fix | Delete
self.lastline = None
[21] Fix | Delete
self.hideid = self.checkhideid = None
[22] Fix | Delete
self.checkhide_after_id = None
[23] Fix | Delete
[24] Fix | Delete
def position_window(self):
[25] Fix | Delete
"""Check if needs to reposition the window, and if so - do it."""
[26] Fix | Delete
curline = int(self.widget.index("insert").split('.')[0])
[27] Fix | Delete
if curline == self.lastline:
[28] Fix | Delete
return
[29] Fix | Delete
self.lastline = curline
[30] Fix | Delete
self.widget.see("insert")
[31] Fix | Delete
if curline == self.parenline:
[32] Fix | Delete
box = self.widget.bbox("%d.%d" % (self.parenline,
[33] Fix | Delete
self.parencol))
[34] Fix | Delete
else:
[35] Fix | Delete
box = self.widget.bbox("%d.0" % curline)
[36] Fix | Delete
if not box:
[37] Fix | Delete
box = list(self.widget.bbox("insert"))
[38] Fix | Delete
# align to left of window
[39] Fix | Delete
box[0] = 0
[40] Fix | Delete
box[2] = 0
[41] Fix | Delete
x = box[0] + self.widget.winfo_rootx() + 2
[42] Fix | Delete
y = box[1] + box[3] + self.widget.winfo_rooty()
[43] Fix | Delete
self.tipwindow.wm_geometry("+%d+%d" % (x, y))
[44] Fix | Delete
[45] Fix | Delete
def showtip(self, text, parenleft, parenright):
[46] Fix | Delete
"""Show the calltip, bind events which will close it and reposition it.
[47] Fix | Delete
"""
[48] Fix | Delete
# Only called in CallTips, where lines are truncated
[49] Fix | Delete
self.text = text
[50] Fix | Delete
if self.tipwindow or not self.text:
[51] Fix | Delete
return
[52] Fix | Delete
[53] Fix | Delete
self.widget.mark_set(MARK_RIGHT, parenright)
[54] Fix | Delete
self.parenline, self.parencol = map(
[55] Fix | Delete
int, self.widget.index(parenleft).split("."))
[56] Fix | Delete
[57] Fix | Delete
self.tipwindow = tw = Toplevel(self.widget)
[58] Fix | Delete
self.position_window()
[59] Fix | Delete
# remove border on calltip window
[60] Fix | Delete
tw.wm_overrideredirect(1)
[61] Fix | Delete
try:
[62] Fix | Delete
# This command is only needed and available on Tk >= 8.4.0 for OSX
[63] Fix | Delete
# Without it, call tips intrude on the typing process by grabbing
[64] Fix | Delete
# the focus.
[65] Fix | Delete
tw.tk.call("::tk::unsupported::MacWindowStyle", "style", tw._w,
[66] Fix | Delete
"help", "noActivates")
[67] Fix | Delete
except TclError:
[68] Fix | Delete
pass
[69] Fix | Delete
self.label = Label(tw, text=self.text, justify=LEFT,
[70] Fix | Delete
background="#ffffe0", relief=SOLID, borderwidth=1,
[71] Fix | Delete
font = self.widget['font'])
[72] Fix | Delete
self.label.pack()
[73] Fix | Delete
tw.update_idletasks()
[74] Fix | Delete
tw.lift() # work around bug in Tk 8.5.18+ (issue #24570)
[75] Fix | Delete
[76] Fix | Delete
self.checkhideid = self.widget.bind(CHECKHIDE_VIRTUAL_EVENT_NAME,
[77] Fix | Delete
self.checkhide_event)
[78] Fix | Delete
for seq in CHECKHIDE_SEQUENCES:
[79] Fix | Delete
self.widget.event_add(CHECKHIDE_VIRTUAL_EVENT_NAME, seq)
[80] Fix | Delete
self.widget.after(CHECKHIDE_TIME, self.checkhide_event)
[81] Fix | Delete
self.hideid = self.widget.bind(HIDE_VIRTUAL_EVENT_NAME,
[82] Fix | Delete
self.hide_event)
[83] Fix | Delete
for seq in HIDE_SEQUENCES:
[84] Fix | Delete
self.widget.event_add(HIDE_VIRTUAL_EVENT_NAME, seq)
[85] Fix | Delete
[86] Fix | Delete
def checkhide_event(self, event=None):
[87] Fix | Delete
if not self.tipwindow:
[88] Fix | Delete
# If the event was triggered by the same event that unbinded
[89] Fix | Delete
# this function, the function will be called nevertheless,
[90] Fix | Delete
# so do nothing in this case.
[91] Fix | Delete
return
[92] Fix | Delete
curline, curcol = map(int, self.widget.index("insert").split('.'))
[93] Fix | Delete
if curline < self.parenline or \
[94] Fix | Delete
(curline == self.parenline and curcol <= self.parencol) or \
[95] Fix | Delete
self.widget.compare("insert", ">", MARK_RIGHT):
[96] Fix | Delete
self.hidetip()
[97] Fix | Delete
else:
[98] Fix | Delete
self.position_window()
[99] Fix | Delete
if self.checkhide_after_id is not None:
[100] Fix | Delete
self.widget.after_cancel(self.checkhide_after_id)
[101] Fix | Delete
self.checkhide_after_id = \
[102] Fix | Delete
self.widget.after(CHECKHIDE_TIME, self.checkhide_event)
[103] Fix | Delete
[104] Fix | Delete
def hide_event(self, event):
[105] Fix | Delete
if not self.tipwindow:
[106] Fix | Delete
# See the explanation in checkhide_event.
[107] Fix | Delete
return
[108] Fix | Delete
self.hidetip()
[109] Fix | Delete
[110] Fix | Delete
def hidetip(self):
[111] Fix | Delete
if not self.tipwindow:
[112] Fix | Delete
return
[113] Fix | Delete
[114] Fix | Delete
for seq in CHECKHIDE_SEQUENCES:
[115] Fix | Delete
self.widget.event_delete(CHECKHIDE_VIRTUAL_EVENT_NAME, seq)
[116] Fix | Delete
self.widget.unbind(CHECKHIDE_VIRTUAL_EVENT_NAME, self.checkhideid)
[117] Fix | Delete
self.checkhideid = None
[118] Fix | Delete
for seq in HIDE_SEQUENCES:
[119] Fix | Delete
self.widget.event_delete(HIDE_VIRTUAL_EVENT_NAME, seq)
[120] Fix | Delete
self.widget.unbind(HIDE_VIRTUAL_EVENT_NAME, self.hideid)
[121] Fix | Delete
self.hideid = None
[122] Fix | Delete
[123] Fix | Delete
self.label.destroy()
[124] Fix | Delete
self.label = None
[125] Fix | Delete
self.tipwindow.destroy()
[126] Fix | Delete
self.tipwindow = None
[127] Fix | Delete
[128] Fix | Delete
self.widget.mark_unset(MARK_RIGHT)
[129] Fix | Delete
self.parenline = self.parencol = self.lastline = None
[130] Fix | Delete
[131] Fix | Delete
def is_active(self):
[132] Fix | Delete
return bool(self.tipwindow)
[133] Fix | Delete
[134] Fix | Delete
[135] Fix | Delete
def _calltip_window(parent): # htest #
[136] Fix | Delete
from Tkinter import Toplevel, Text, LEFT, BOTH
[137] Fix | Delete
[138] Fix | Delete
top = Toplevel(parent)
[139] Fix | Delete
top.title("Test calltips")
[140] Fix | Delete
top.geometry("200x100+%d+%d" % (parent.winfo_rootx() + 200,
[141] Fix | Delete
parent.winfo_rooty() + 150))
[142] Fix | Delete
text = Text(top)
[143] Fix | Delete
text.pack(side=LEFT, fill=BOTH, expand=1)
[144] Fix | Delete
text.insert("insert", "string.split")
[145] Fix | Delete
top.update()
[146] Fix | Delete
calltip = CallTip(text)
[147] Fix | Delete
[148] Fix | Delete
def calltip_show(event):
[149] Fix | Delete
calltip.showtip("(s=Hello world)", "insert", "end")
[150] Fix | Delete
def calltip_hide(event):
[151] Fix | Delete
calltip.hidetip()
[152] Fix | Delete
text.event_add("<<calltip-show>>", "(")
[153] Fix | Delete
text.event_add("<<calltip-hide>>", ")")
[154] Fix | Delete
text.bind("<<calltip-show>>", calltip_show)
[155] Fix | Delete
text.bind("<<calltip-hide>>", calltip_hide)
[156] Fix | Delete
text.focus_set()
[157] Fix | Delete
[158] Fix | Delete
if __name__=='__main__':
[159] Fix | Delete
from idlelib.idle_test.htest import run
[160] Fix | Delete
run(_calltip_window)
[161] Fix | Delete
[162] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function