[wxPython-users] Capturing mouse position in wx.Grid
Robin Dunn
robin at alldunn.com
Tue Mar 4 12:54:08 PST 2008
Mike Driscoll wrote:
> Robin et al,
>
>> -----Original Message-----
>> From: Robin Dunn [mailto:robin at alldunn.com]
>> Sent: Friday, February 29, 2008 4:57 PM
>> To: wxPython-users at lists.wxwidgets.org
>> Subject: Re: [wxPython-users] Capturing mouse position in wx.Grid
>>
>> Mike Driscoll wrote:
>>
>>> In my handler, I was using GetPosition(), but that always
>> returns the
>>> same tuple no matter where I move the mouse.
>> The mouse event's GetPosition()? Strange, that should be working...
>> Can you make a small sample?
>>
>>> Right now, what I want is to be
>>> able to mouse over any cell in a certain column and grab
>> that cell's
>>> contents and multiply it by a value which is then displayed in the
>>> tooltip.
>>>
>>> I'm sure there's a way to get the mouse position and
>> translate it into
>>> a (row, col) tuple, but I just don't see how to do it at the moment.
>> coords = grid.XTToCell(x, y)
>>
>> --
>> Robin Dunn
>> Software Craftsman
>> http://wxPython.org Java give you jitters? Relax with wxPython!
>>
>>
>
> It looks like these XYToCell, YToRow, and XToCol methods don't work quite
> the way I need. My grid actually has scroll bars that go to the right and
> left as well as up and down (I didn't think to mention this earlier;
> sorry!). All of these methods only calculate on what is currently shown
> onscreen, which breaks their functionality for my purposes anyway. For
> example, if I need the cell value in (0,0) and I've scrolled 3 columns to
> the right, then I end up with (0,3)'s value instead.
The Grid class derives from wx.ScrolledWindow, so try passing the mouse
position through the CalcUnscrolledPosition method to get the logical
coordinates, and then converting that to a cell position.
>
> Also, when I tried to set the tooltip string for the cell I was mousing
> over by doing the following:
>
> event.GetEventObject().SetToolTipString('My message')
>
> it didn't always update when I'd move to another cell and instead,
> retained the previous value of the tooltip. Does anyone know how to fix
> either of these issues?
IIRC you can work around this by first setting the tooltip string to "",
or maybe it was setting the tooltip to None... Another possibility is
to use the wx.TipWindow instead. You'll have more control over it that
way. Basically the issue here is that the tooltip is associated with
the whole window, not each cell, but the tooltips are designed to be set
once and forgotten.
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
More information about the wxpython-users
mailing list