Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python2..../idlelib
File: ToolTip.py
# general purpose 'tooltip' routines - currently unused in idlefork
[0] Fix | Delete
# (although the 'calltips' extension is partly based on this code)
[1] Fix | Delete
# may be useful for some purposes in (or almost in ;) the current project scope
[2] Fix | Delete
# Ideas gleaned from PySol
[3] Fix | Delete
[4] Fix | Delete
from Tkinter import *
[5] Fix | Delete
[6] Fix | Delete
class ToolTipBase:
[7] Fix | Delete
[8] Fix | Delete
def __init__(self, button):
[9] Fix | Delete
self.button = button
[10] Fix | Delete
self.tipwindow = None
[11] Fix | Delete
self.id = None
[12] Fix | Delete
self.x = self.y = 0
[13] Fix | Delete
self._id1 = self.button.bind("<Enter>", self.enter)
[14] Fix | Delete
self._id2 = self.button.bind("<Leave>", self.leave)
[15] Fix | Delete
self._id3 = self.button.bind("<ButtonPress>", self.leave)
[16] Fix | Delete
[17] Fix | Delete
def enter(self, event=None):
[18] Fix | Delete
self.schedule()
[19] Fix | Delete
[20] Fix | Delete
def leave(self, event=None):
[21] Fix | Delete
self.unschedule()
[22] Fix | Delete
self.hidetip()
[23] Fix | Delete
[24] Fix | Delete
def schedule(self):
[25] Fix | Delete
self.unschedule()
[26] Fix | Delete
self.id = self.button.after(1500, self.showtip)
[27] Fix | Delete
[28] Fix | Delete
def unschedule(self):
[29] Fix | Delete
id = self.id
[30] Fix | Delete
self.id = None
[31] Fix | Delete
if id:
[32] Fix | Delete
self.button.after_cancel(id)
[33] Fix | Delete
[34] Fix | Delete
def showtip(self):
[35] Fix | Delete
if self.tipwindow:
[36] Fix | Delete
return
[37] Fix | Delete
# The tip window must be completely outside the button;
[38] Fix | Delete
# otherwise when the mouse enters the tip window we get
[39] Fix | Delete
# a leave event and it disappears, and then we get an enter
[40] Fix | Delete
# event and it reappears, and so on forever :-(
[41] Fix | Delete
x = self.button.winfo_rootx() + 20
[42] Fix | Delete
y = self.button.winfo_rooty() + self.button.winfo_height() + 1
[43] Fix | Delete
self.tipwindow = tw = Toplevel(self.button)
[44] Fix | Delete
tw.wm_overrideredirect(1)
[45] Fix | Delete
tw.wm_geometry("+%d+%d" % (x, y))
[46] Fix | Delete
self.showcontents()
[47] Fix | Delete
[48] Fix | Delete
def showcontents(self, text="Your text here"):
[49] Fix | Delete
# Override this in derived class
[50] Fix | Delete
label = Label(self.tipwindow, text=text, justify=LEFT,
[51] Fix | Delete
background="#ffffe0", relief=SOLID, borderwidth=1)
[52] Fix | Delete
label.pack()
[53] Fix | Delete
[54] Fix | Delete
def hidetip(self):
[55] Fix | Delete
tw = self.tipwindow
[56] Fix | Delete
self.tipwindow = None
[57] Fix | Delete
if tw:
[58] Fix | Delete
tw.destroy()
[59] Fix | Delete
[60] Fix | Delete
class ToolTip(ToolTipBase):
[61] Fix | Delete
def __init__(self, button, text):
[62] Fix | Delete
ToolTipBase.__init__(self, button)
[63] Fix | Delete
self.text = text
[64] Fix | Delete
def showcontents(self):
[65] Fix | Delete
ToolTipBase.showcontents(self, self.text)
[66] Fix | Delete
[67] Fix | Delete
class ListboxToolTip(ToolTipBase):
[68] Fix | Delete
def __init__(self, button, items):
[69] Fix | Delete
ToolTipBase.__init__(self, button)
[70] Fix | Delete
self.items = items
[71] Fix | Delete
def showcontents(self):
[72] Fix | Delete
listbox = Listbox(self.tipwindow, background="#ffffe0")
[73] Fix | Delete
listbox.pack()
[74] Fix | Delete
for item in self.items:
[75] Fix | Delete
listbox.insert(END, item)
[76] Fix | Delete
[77] Fix | Delete
def _tooltip(parent):
[78] Fix | Delete
root = Tk()
[79] Fix | Delete
root.title("Test tooltip")
[80] Fix | Delete
width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
[81] Fix | Delete
root.geometry("+%d+%d"%(x, y + 150))
[82] Fix | Delete
label = Label(root, text="Place your mouse over buttons")
[83] Fix | Delete
label.pack()
[84] Fix | Delete
button1 = Button(root, text="Button 1")
[85] Fix | Delete
button2 = Button(root, text="Button 2")
[86] Fix | Delete
button1.pack()
[87] Fix | Delete
button2.pack()
[88] Fix | Delete
ToolTip(button1, "This is tooltip text for button1.")
[89] Fix | Delete
ListboxToolTip(button2, ["This is","multiple line",
[90] Fix | Delete
"tooltip text","for button2"])
[91] Fix | Delete
root.mainloop()
[92] Fix | Delete
[93] Fix | Delete
if __name__ == '__main__':
[94] Fix | Delete
from idlelib.idle_test.htest import run
[95] Fix | Delete
run(_tooltip)
[96] Fix | Delete
[97] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function