I have noticed a problem with agw SuperTooltip. Here is a program that
demonstrates it:
import wx
from agw import supertooltip as STT
TIP_MSG="""This is button (%s,%s)
This demonstration program shows what happens if the tooltip target
widget is at the edge of the screen. Instead of placing the tip window
under the mouse position, we should place it smartly. E.g. when the
widget is at the bottom of the screen, then the tooltip window should
be placed ABOVE the widget, so that all of the contents are
visible."""
class Main(wx.Frame):
def __init__(self):
wx.Frame.__init__(self,None,-1,title="Tooltip test")
sizer = wx.GridBagSizer()
for row in range(10):
for col in range(10):
btn = wx.Button(self,-1,"%s,%s"%(row,col))
tip = STT.SuperToolTip("Tooptip for %s,%s"%(row,col))
tip.SetHeader(TIP_MSG%(row,col))
tip.SetTarget(btn)
tip.SetDrawHeaderLine(True)
sizer.Add(btn, (row,col), (1,1), wx.EXPAND)
for row in range(10):
sizer.AddGrowableRow(row)
for col in range(10):
sizer.AddGrowableCol(col)
self.SetSizer(sizer)
self.Maximize()
app = wx.App(redirect=None)
frame = Main()
frame.Show()
app.MainLoop()
If you place the mouse over a button, then the tooltip is always
appears with its upper left corner positioned to the current mouse
position. One problem is that the target widget may be near the edge
of the screen. In that case, the tooltip window will be partly
invisible. The other problem is that sometimes the client area of the
widget is important to the end user. Consider a big text editor
window, where the user is supposed to write in multiple lines of text.
Most likely, the tooltip window will be shown in the middle of the
text area, preventing the user to see what he is typing.
I have a patch for this problem that can be applied against the
current subversion repository. But I'm not sure how to submit a patch.
I'm using google groups and as far as I know, this is the only way to
post to the list. But Google doesn't allow me to attach files. So I'll
just copy the changes here.
Change #1. into class TooptipWindowBase, create this new method:
def CalculateBestPosition(self,widget):
screen = wx.ClientDisplayRect()[2:]
left,top = widget.ClientToScreenXY(0,0)
right,bottom = widget.ClientToScreenXY(*widget.GetClientRect()
[2:])
size = self.GetSize()
if right+size[0]>screen[0]:
xpos = left-size[0]
else:
xpos = right
if bottom+size[1]>screen[1]:
ypos = top-size[1]
else:
ypos = bottom
self.SetPosition((xpos,ypos))
Change #2. Wherever SetPosition() was called, call
CalculateBestPosition() instead.
Then you can run the test app, and you will see that the tooltip is
place to the bottom right of the widget, except near the screen edges.
E.g. for a widget that is on the bottom left site, the tooltip will be
placed at the top right corder of the client rect of the widget etc.
I have another idea about how to make this better, and another "bug"
that can be fixed. But first I would like to know your opinion about
this.
Best,
Laszlo
Thanks,
Laszlo