problem refreshing single cells in a Grid

Thanks again, Robin. The following code seems to do the trick (not sure if all my variable names
make sense). As I write this, though, I wonder if I should add a test for the rectScreen X and Y
values < 0, and if so, set them to zero? I think this would occur if a cell is only partially
visible at the top of the window. I don't know what RefreshRect would do with negative X and Y
values.

    def refreshCell(self, row, col):
        """Force refresh of a single grid cell."""
        if self.IsVisible(row, col, wholeCellVisible = False):
            rect = self.CellToRect(row, col)
            # CellToRect returns coordinates in the 'virtual' window. We must translate them
            # to screen coordinates for RefreshRect.
            xUnit, yUnit = self.GetScrollPixelsPerUnit()
            xStart, yStart = self.GetViewStart()
            xStartPix = xStart * xUnit
            yStartPix = yStart * yUnit
            rectScreen = wx.Rect(rect.GetX() - xStartPix,
                                 rect.GetY() - yStartPix,
                                 rect.GetWidth(),
                                 rect.GetHeight())
            self.GetGridWindow().RefreshRect(rectScreen)

Feeling much better now,

Rad Widmer

···

----- Original Message -----
From: "Robin Dunn" <robin@alldunn.com>
To: <wxPython-users@lists.wxwidgets.org>
Sent: Wednesday, August 04, 2004 12:59 PM
Subject: Re: [wxPython-users] problem refreshing single cells in a Grid

Rad Widmer wrote:
> I tried adding the GetGridWindow call as Robin suggested. Now what I see is the refreshCell

works OK

> if the grid is not scrolled down (i.e., row 1 is the first row displayed). If I scroll down at

all,

> then refreshCell doesn't work.
>
> When I looked further, I found that wxGrid.CellToRect returns coordinates relative to the

'virtual'

> window. That is, these coordinates do not change as the grid window is scrolled. For example, a

cell

> in row one will always have a y value of zero, cells in row two will always have y values of 20,
> etc. It also appears that wxWindow.RefreshRect wants screen (non-virtual) coordinates. So

somehow

> the coordinates from CellToRect need to be translated to screen coordinates.
>

Look at wx.ScrolledWindow's GetViewStart and GetScrollPixelsPerUnit methods.

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

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org