Force a virtual grid to reload?

How do you tell a grid with a virtual table that it needs to reload (because the data has changed)? The demo file GridHugeTable.py is my starting point.

In particular, when HugeTable is instantiated, the grid calls GetNumberRows() once immediately after init, but never again. How do I tell it that another row has been added and it needs to take another look?

Thanks,
Michael

Michael,

How do you tell a grid with a virtual table that it needs to reload (because the data has changed)? The demo file GridHugeTable.py is my starting point.

In particular, when HugeTable is instantiated, the grid calls GetNumberRows() once immediately after init, but never again. How do I tell it that another row has been added and it needs to take another look?

Thanks,
Michael

Did you try the ForceRefresh() method? I think that may be what you're looking for...

···

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org
Python Extension Building Network: http://www.pythonlibrary.org

Mike Driscoll wrote:

How do you tell a grid with a virtual table that it needs to reload (because the data has changed)? The demo file GridHugeTable.py is my starting point.

In particular, when HugeTable is instantiated, the grid calls GetNumberRows() once immediately after init, but never again. How do I tell it that another row has been added and it needs to take another look?

Did you try the ForceRefresh() method? I think that may be what you're looking for...

Thanks. It doesn't seem to work as such. In particular ForceRefresh() doesn't seem to cause the grid to call GetNumberRows(). I think it is more concerned with screen refresh than the underlying data.

I'm hoping I don't have to destroy the table and create a new one every time the underlying data changes.

Thanks,
Michael

Michael Hipp wrote:

Mike Driscoll wrote:

How do you tell a grid with a virtual table that it needs to reload (because the data has changed)? The demo file GridHugeTable.py is my starting point.

In particular, when HugeTable is instantiated, the grid calls GetNumberRows() once immediately after init, but never again. How do I tell it that another row has been added and it needs to take another look?

Did you try the ForceRefresh() method? I think that may be what you're looking for...

Thanks. It doesn't seem to work as such. In particular ForceRefresh() doesn't seem to cause the grid to call GetNumberRows(). I think it is more concerned with screen refresh than the underlying data.

I'm hoping I don't have to destroy the table and create a new one every time the underlying data changes.

Thanks,
Michael
____________

Weird. Robin's book has that method under the section on adding and deleting rows, columns and cells and the way it was worded I thought it would work. Here's the quote: "In general, if you make a programmatic change to your grid that is not showing up, it's a good idea to try inserting a ForceRefresh() call to ensure that your change is displayed". On re-reading that, I can see how it might just be a refresh call though.

How are you adding data? Are you using AppendCols() or AppendRows() or are you just changing the data itself outside of your GUI?

Michael Hipp wrote:

Mike Driscoll wrote:

How do you tell a grid with a virtual table that it needs to reload (because the data has changed)? The demo file GridHugeTable.py is my starting point.

In particular, when HugeTable is instantiated, the grid calls GetNumberRows() once immediately after init, but never again. How do I tell it that another row has been added and it needs to take another look?

Did you try the ForceRefresh() method? I think that may be what you're looking for...

Thanks. It doesn't seem to work as such. In particular ForceRefresh() doesn't seem to cause the grid to call GetNumberRows(). I think it is more concerned with screen refresh than the underlying data.

I'm hoping I don't have to destroy the table and create a new one every time the underlying data changes.

No, you don't need to do that. You are using a virtual grid bound to a data table, and the table has changed but now you need to notify the grid, using the function wx.grid.GRIDTABLE_NOTIFY_ROWS_APPENDED()

Here's some example code in Dabo's dGrid control. Note that there are two functions, one for when the column count changes, and one for when the row count changes:

http://trac.dabodev.com/browser/trunk/dabo/ui/uiwx/dGrid.py#L3073

You should wrap these calls in grid.BeginBatch()/EndBatch() calls if you are processing more than one row or column at a time.

HTH
Paul

Mike Driscoll wrote:

How are you adding data? Are you using AppendCols() or AppendRows() or are you just changing the data itself outside of your GUI?

I'm adding or removing rows outside of the Grid or GUI. That's part of the attraction of virtual grids is the ease of doing so. I'm not even sure what those methods would in the virtual case.

Thanks,
Michael

Michael Hipp wrote:

Mike Driscoll wrote:

How are you adding data? Are you using AppendCols() or AppendRows() or are you just changing the data itself outside of your GUI?

I'm adding or removing rows outside of the Grid or GUI. That's part of the attraction of virtual grids is the ease of doing so. I'm not even sure what those methods would in the virtual case.

Thanks,
Michael

Huh...I think that section of the book is kind of confusing then. Oh well. I've never messed with the virtual grid so just ignore my ramblings. I'm sure Paul's suggestions were correct as I've seen that before...

Mike

Mike Driscoll wrote:

Michael Hipp wrote:

Mike Driscoll wrote:

How are you adding data? Are you using AppendCols() or AppendRows() or are you just changing the data itself outside of your GUI?

I'm adding or removing rows outside of the Grid or GUI. That's part of the attraction of virtual grids is the ease of doing so. I'm not even sure what those methods would in the virtual case.

Huh...I think that section of the book is kind of confusing then. Oh well. I've never messed with the virtual grid so just ignore my ramblings. I'm sure Paul's suggestions were correct as I've seen that before...

After a bit of experimenting, the ForceRefresh() call seems to do a great job of putting things in order when the data has changed but the row/col count stayed the same. I'm using it after doing a sort. This makes it appear like every cell is suddenly different but that one call makes everything right on the screen.

Michael

Mike Driscoll wrote:

Michael Hipp wrote:

Mike Driscoll wrote:

How do you tell a grid with a virtual table that it needs to reload (because the data has changed)? The demo file GridHugeTable.py is my starting point.

In particular, when HugeTable is instantiated, the grid calls GetNumberRows() once immediately after init, but never again. How do I tell it that another row has been added and it needs to take another look?

Did you try the ForceRefresh() method? I think that may be what you're looking for...

Thanks. It doesn't seem to work as such. In particular ForceRefresh() doesn't seem to cause the grid to call GetNumberRows(). I think it is more concerned with screen refresh than the underlying data.

I'm hoping I don't have to destroy the table and create a new one every time the underlying data changes.

Thanks,
Michael
____________

Weird. Robin's book has that method under the section on adding and deleting rows, columns and cells and the way it was worded I thought it would work. Here's the quote: "In general, if you make a programmatic change to your grid that is not showing up, it's a good idea to try inserting a ForceRefresh() call to ensure that your change is displayed". On re-reading that, I can see how it might just be a refresh call though.

ForceRefresh simply ensures that all visible cells are redrawn, fetching the data for those cells in the process.

As Paul pointed out, when the table changes dimensions it needs to send a message to the view (the grid) to tell it what happened. Search in the demo modules for GridTableMessage for some examples.

···

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