[wxPython-users] Custom tooltip issues
Robin Dunn
robin at alldunn.com
Fri Sep 15 19:54:22 PDT 2006
Christopher Barker wrote:
> Hi all,
>
> I'm trying to work out how to use tooltips with wx.lib.floatcanvas. As I
> was thinking about this, Martin Spacek posted a sample of how to do it
> with wx and matplotlib to the MPL list.
>
> However, his methods don't quite work right on wxGTK. I've been playing
> around with this, and am not getting it to work like I want it to.
> Ideally, I want to be able to pop up a tooltip wherever and whenever I
> want, but it's looking to be impossible. I'm guessing that wx.ToolTip is
> using the native tooltip support, and thus has little control over
> behavior.
>
> I have a few particular issues, maybe someone has some ideas of how to
> improve them. Enclosed is a small demo app. It has two panels, each with
> slightly different tooltip behavior attempted.
>
> The top panel shows a tooltip when the mouse is clicked. This works OK.
> However, getting it to go away is a trick. I tried to use:
>
> wx.TipWindow.SetBoundingRect()
>
> but it seems to have the opposite behavior than I expected. Now the tip
> window goes away when the mouse passes over the tip, NOT when it leaves
> the region specified by the rect. What am I doing wrong?
First the rect needs to be in screen coords, not client coords. If you
change it to look like this then it works on Windows:
pt = self.ClientToScreen(event.GetPosition())
r = wx.RectPS(pt, (10,10))
self.tooltip.SetBoundingRect(r)
I'm not sure what's going on with the other platforms though. Looks
like it isn't capturing the mouse or or is losing the capture or
something...
>
> I also tried to have the TipWindow destroyed when the mouse left the
> window, but it seems I don't get the EVT_LEAVE_WINDOW when the tooltip
> is active -- weird. I also don't know how to make it go away -- should
> .Destroy() work?
It has a Close method that should be used instead.
>
> The bottom Panel has a tooltip that shows the mouse coords. Ideally it
> would follow the mouse around. I think that works on Windows, but on
> wxGTK, it follows the x-coord, but stays at the bottom of the Panel. Can
> I fix that?
That is a limitation of GTK, or how wxGTK is using it, or something like
that. When you're using a tooltip for a smallish control then putting
the tip at the bottom edge of the control is fine, but I agree that it
is not so nice for larger items...
>
> Also, I tried to make it so the tip would only show when the mouse was
> over the rectangle, but once ToolTip.Enable(False) is called,
> ToolTip.Enable(True) doesn't bring it back.
>
> Can anyone figure out how to do this on all platforms? (wxMac is worse,
> I think)
>
> I also wonder what the "global" means with that call:
>
> """
> wxToolTip::Enable
>
> Enable or disable tooltips globally.
> """
>
> Global to what? the application? the Window? the Frame?
The application.
>
> If none of this can be made to work right, is it possible to make a
> Custom pop-up Window that looks like a tooltip?
wx.TipWindow is essentially either a wx.PopupTransientWindow, or a
wx.Frame (on mac where there isn't a popup window implementation yet.)
so it shouldn't be too hard to roll your own however you like.
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
More information about the wxpython-users
mailing list