Custom tooltip issues

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?

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?

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?

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?

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?

Thanks,

-Chris

ToolTips.py (3.6 KB)

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Hello Chris,

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:

Well, maybe it is too late for me in the evening to wxPythoning, but I
am unable to get any tooltip visible. If I click on the top panel, I
get a very fast flash of a tooltip that suddenly disappears.

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?

Uhm, you should check if hasattr(self, "tooltip") or you will get a
bunch of AttributeErrors. However, after fixing this, I don't see any
tooltip anywhere, no matter if I click, or wait without moving the
mouse... weird, what's wrong with tooltips?!?!
However, I don't think that the call to Destroy() is safe, I get a lot
of PyDeadObjectErrors... maybe wx.TipWindow behaves like wx.BusyInfo?
You may try to call "del self.tooltip" to see if anything changes.

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?

I can't see any tooltip :frowning:
This is Windows XP, wxPython 2.7.0.1 latest pre-release, Python 2.4.3.

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?

You may take a look at the BalloonTip control I wrote few months ago.

http://xoomer.alice.it/infinity77/eng/freeware.html#balloontip

Ok, it displays ballon-type tips, but this is easily changed. The only
problem I see with custom tooltips, is that they will almost surely
steal the focus from your widget/app, unless you restore the focus
where it was...

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."

http://xoomer.virgilio.it/infinity77/

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!