Capturing mouse position in wx.Grid

Hi,

I have a wx.grid.Grid object in one of my applications. I have had a
feature request to have cells in one column display a tooltip when moused
over. How do I bind EVT_MOTION to the cells in the grid? I've tried
binding to the panel, which is the parent of the grid and to the grid
object itself, but both of those don't work. If you know of a way to do
this, please let me know.

I am using wxPython 2.8.7.1, Python 2.4 on Windows XP. Thanks!

Mike Driscoll
Applications Specialist
MCIS - Technology Center

Bob Klahn wrote:

Hi Mike,

I suspect there's a better way, but what I've done in the past is to bind to the grid's "grid window" child. Its default name is "grid window,"
so in the grid's __init__ method, you can do this:

        for child in self.GetChildren(): if child.GetName() == 'grid window': child.Bind(wx.EVT_MOTION, self.OnMotion)

You can use self.GetGridWindow() instead and save yourself a bit of work.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Thanks for pointing out GetGridWindow, Robin.

There are still cases where a child loop like the one above, but without the name test, may be needed, e.g., to successfully bind set/kill focus events. My first attempts to bind such events were to the grid itself, which rarely worked. I wasn't sure what objects were actually getting the focus, so I set up a timer event to log a focus traceback every two seconds, which showed me that, in my particular application, the focus was sometimes on the grid window, and sometimes on one of the grid labels. Since I never needed to know which specific grid piece had the focus, a child loop was, I think, my best choice.

Bob

···

At 03:46 PM 2/28/2008, Robin Dunn wrote:

Bob Klahn wrote:

Hi Mike,
I suspect there's a better way, but what I've done in the past is to bind to the grid's "grid window" child. Its default name is "grid window,"
so in the grid's __init__ method, you can do this:
        for child in self.GetChildren():
            if child.GetName() == 'grid window':
                child.Bind(wx.EVT_MOTION, self.OnMotion)

You can use self.GetGridWindow() instead and save yourself a bit of work.