Wx.Grid and popup over cells

M

Massi

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
 
M

Mike Driscoll

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:

<code>

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 =
self.totals_sheet.CalcUnscrolledPosition(event.GetX(),event.GetY())

coords = self.totals_sheet.XYToCell(x, y)
# you only need these if you need the value in the cell
row = coords[0]
col = coords[1]
event.GetEventObject().SetToolTipString("My amazing tooltip")

</code>

Hopefully that will get you going. If not, just ask more questions
(here or at the wxPython list).
 
M

Massi

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.

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:

<code>

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 =
self.totals_sheet.CalcUnscrolledPosition(event.GetX(),event.GetY())

coords = self.totals_sheet.XYToCell(x, y)
# you only need these if you need the value in the cell
row = coords[0]
col = coords[1]
event.GetEventObject().SetToolTipString("My amazing tooltip")

</code>

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,691
Members
48,796
Latest member
Greg L.

Latest Threads

Top