Updating a wxGrid based on a wxPyGridTableBase

I am programmatically updating selected values in a wxPyGridtableBase based
on user actions. The changed GridTable values are not reflected visually in
the Grid until the user clicks somewhere in the Grid and then the affected
cells update. If I execute the following code after updating the GridTable
values then the affected Grid cells do appropriately reflect the changes in
the GridTable.

msg = wxGridTableMessage(grid.GetTable(),
wxGRIDTABLE_REQUEST_VIEW_GET_VALUES)
grid.ProcessTableMessage(msg)

Not that this is particularly complicated but I would have thought that
there would be a simple grid.Update() or grid.UpdateCell(row,col) method,
but I have looked through the docs and can't find one. Is the code above
the appropriate way to update a grid even if only a single GridTable value
has been changed?

Steve Zatz wrote:

I am programmatically updating selected values in a wxPyGridtableBase

based

on user actions. The changed GridTable values are not reflected visually

in

the Grid until the user clicks somewhere in the Grid and then the affected
cells update. If I execute the following code after updating the

GridTable

values then the affected Grid cells do appropriately reflect the changes

in

the GridTable.

msg = wxGridTableMessage(grid.GetTable(),
wxGRIDTABLE_REQUEST_VIEW_GET_VALUES)
grid.ProcessTableMessage(msg)

Not that this is particularly complicated but I would have thought that
there would be a simple grid.Update() or grid.UpdateCell(row,col) method,
but I have looked through the docs and can't find one. Is the code above
the appropriate way to update a grid even if only a single GridTable value
has been changed?

I am not in front of my system right now, so I cannot check this, but I am
sure that I just call grid.SetCellValue(row,col,value). This invokes my
routine that updates the underlying table, and then grid.GetCellValue is
called automatically to refresh the display.

I hope I have got this right - if it does not work, let me know and I will
check properly.

Frank Millman

Zatz, Steve wrote:

I am programmatically updating selected values in a wxPyGridtableBase based
on user actions. The changed GridTable values are not reflected visually in
the Grid until the user clicks somewhere in the Grid and then the affected
cells update. If I execute the following code after updating the GridTable
values then the affected Grid cells do appropriately reflect the changes in
the GridTable.

msg = wxGridTableMessage(grid.GetTable(),
wxGRIDTABLE_REQUEST_VIEW_GET_VALUES)
grid.ProcessTableMessage(msg)

Not that this is particularly complicated but I would have thought that
there would be a simple grid.Update() or grid.UpdateCell(row,col) method,
but I have looked through the docs and can't find one. Is the code above
the appropriate way to update a grid even if only a single GridTable value
has been changed?

I think you can also do the following to refresh only the area of the window that the cell occupies. The wxGrid's paint handler is optimized to only fetch values for the cells that need drawn.

  grid.GetGridWindow().Refresh(True, grid.CellToRect(row, col))

Hmm... Looking at the code that rect may not be correct. You may have to adjust it for the scrolled position too...

Anyway, there is some work going on to streamline and improve the wxGrid for 2.5. Perhaps if you enter a feature request about this then an RefreshCell(row, col) method can be added too.

···

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

Anyway, there is some work going on to streamline and improve the wxGrid
for 2.5. Perhaps if you enter a feature request about this then an
RefreshCell(row, col) method can be added too.

I could not find any way to get the displayed row numbers in a grid from the
existing wxPython wrappers. I would like to be able to do this.

Is there a method that I am not aware of in wxGrid that gives this kind of
information?
-Rick King

Rick King wrote:

Anyway, there is some work going on to streamline and improve the wxGrid
for 2.5. Perhaps if you enter a feature request about this then an
RefreshCell(row, col) method can be added too.

I could not find any way to get the displayed row numbers in a grid from the
existing wxPython wrappers. I would like to be able to do this.

Hmm. I couldn't find it either. I was expecting something like GetFirstVisible, but I guess that is another class.

Is there a method that I am not aware of in wxGrid that gives this kind of
information?

There is the XYToCell, YToRow and XToCol methods that convert window coordinantes to grid cell coords.

···

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

There is the XYToCell, YToRow and XToCol methods that convert window
coordinantes to grid cell coords.

True - these seem relatively straight forward. Thanks.
-Rick King