Wx.Grid and popup over cells
massi_srb at msn.com
Tue Oct 14 16:22:53 CEST 2008
On 14 Ott, 16:13, Mike Driscoll <kyoso... at gmail.com> wrote:
> On Oct 14, 5:21 am, Massi <massi_... at msn.com> wrote:
> > Hi everyone,
> > I'm writing a python script which uses a grid (PyGridTableBase) whose
> > cells can contain very large values (not only numbers, but also
> > strings). I've also written a custom renderer which dinamically shows
> > only the first n characters (according to the width of the cell)
> > replacing the last ones with dots. Now I would like to know if it is
> > possible to have a popup which shows the whole contents of a certain
> > cell when the mouse stops over the cell itself. Any ideas?
> > Thanks in advance.
> > Massi
> First off, let me recommend the wxPython mailing list for questions of
> this sort. You'll probably get more relevant help quicker if you go
> that route.
> Anyway, I've done tooltips on cells in a grid before and you'll need
> the same concept to use a pop-up dialog too. To begin, you'll want to
> bind to the mouse event, EVT_MOTION, like this:
> self.myGrid.GetGridWindow().Bind(wx.EVT_MOTION, self.onMouseOver)
> Next, you'll need to do something like the following in your mouse
> over function:
> def onMouseOver(self, event):
> Method to calculate where the mouse is pointing and
> then set the tooltip dynamically.
> # Use CalcUnscrolledPosition() to get the mouse position
> within the
> # entire grid including what's offscreen
> x, y =
> coords = self.totals_sheet.XYToCell(x, y)
> # you only need these if you need the value in the cell
> row = coords
> col = coords
> event.GetEventObject().SetToolTipString("My amazing tooltip")
> Hopefully that will get you going. If not, just ask more questions
> (here or at the wxPython list).
> Mike Driscoll
> Blog: http://blog.pythonlibrary.org
> Python Extension Building Network: http://www.pythonlibrary.org
That's exactly what I needed, thank you!
More information about the Python-list