repopulating grid can't forcerefresh to upate values

Someone wrote in November 2006:

hello i’m going crazy trying to make this bloody grid show it’s new
data, it refuses to show it’s new data even on forcerefresh

self.RosterStaffGrid.ClearGrid
()

   for memeber in Staff:
       Phone = str(memeber[0])
       Name = memeber[1]
       Group = memeber[2]
       if Group == self.parent.GetPageText([self.id](http://self.id)).split(': ')[0]:
           self.RosterStaffGrid.table.data.append

([Phone,Name,‘’])

           print self.RosterStaffGrid.table.data
   self.RosterStaffGrid.ForceRefresh()    

As you’re using a custom TableBase, you have to tell the UI that the
data has
changed, by sending some event, whose name I do not remember at the
moment. Have
a look at the wxPython demo, there is at least one grid demo from
which you can
copy the necessary parts.

yeah i thought thats what ForceRefresh did?

To which Robin Dunn responded:

If you’re adding new data then you need to tell the grid that there are
new rows by sending it a GridTableMessage. See GridCustTable.py in the
demo.

Oh, brother. I just dragged myself through the same swamp and eventually found this post in the archives after driving myself crazy trying to get a grid to refresh itself after appending rows.

Here’s the necessary code:

    msg = wx.grid.GridTableMessage(wx.grid.GridTableMessage(self,
        wx.grid.GRIDTABLE_NOTIFY_ROWS_APPENDED, 1))
    self.GetView().ProcessTableMessage(msg)

And my additional notes on this: (I don’t mean to be too boisterous, but I can’t help mentioning these)

First, it seems superfluous to send this “extra” notification when we’ve already called grid.AppendRows(). What use is it to have the grid still have no idea that rows have been appended even after its AppendRows() method has been called, until it specifically receives additional notification? However, I understand this is in the hands of wxWidgets, and not its Python wrapper.

I do realize that in order to maintain the important separation of model and view, some message passing etc. is always going to be necessary. But to have the grid look the other way, even though it had to approve the append before it could occur, until it is told twice, seems ridiculous. Am I missing something in the works?

Second, there seems to be no permutation, subset, or reasonable superset of the string ‘GridTableMessage’ showing up anywhere in the wxPython documentation (i mean specifically in the file wx.chm, 2.8.4). Nor does it turn up (unless I’m mistaken) in wxPython In Action.

Third – as if there were some sort of conspiracy to prevent access to the answer to this presumably common pitfall – when you attempt to search in the wxPython demos (2.8.4) for ‘gridtablemessage’, first the code for GridCustTable.py is not in the Code tab of the appropriate demo where it would be expected. Instead it’s in a page linked from the Overview tab. In addition, when you initiate a text search (via keyboard) for, say, ‘gridtablemessage’, the demo window forces the focus back to the Code window, preventing the search from doing anything. I suppose this could be applauded because it effectively forces the reader to read the code (though oddly located) more thoroughly in order to come up with the needed lines.

I love wxPython! But this is about the hardest I’ve had to work for an arcane answer to a common pitfall in a long while.

Hi Eric,

<snip>
<snap>

<missing beginning tag <rant>

Oh, brother. I just dragged myself through the same swamp and eventually
found this post in the archives after driving myself crazy trying to get a
grid to refresh itself after appending rows.

Here's the necessary code:

        msg = wx.grid.GridTableMessage(wx.grid.GridTableMessage(self,
            wx.grid.GRIDTABLE_NOTIFY_ROWS_APPENDED, 1))
        self.GetView().ProcessTableMessage(msg)

And my additional notes on this: (I don't mean to be too boisterous, but I
can't help mentioning these)

First, it seems superfluous to send this "extra" notification when we've
already called grid.AppendRows(). What use is it to have the grid still have
no idea that rows have been appended even after its AppendRows() method has
been called, until it specifically receives additional notification?
However, I understand this is in the hands of wxWidgets, and not its Python
wrapper.

I do realize that in order to maintain the important separation of model and
view, some message passing etc. is always going to be necessary. But to
have the grid look the other way, even though it had to approve the append
before it could occur, until it is told twice, seems ridiculous. Am I
missing something in the works?

Second, there seems to be no permutation, subset, or reasonable superset of
the string 'GridTableMessage' showing up anywhere in the wxPython
documentation (i mean specifically in the file wx.chm, 2.8.4). Nor does it
turn up (unless I'm mistaken) in wxPython In Action.

Third -- as if there were some sort of conspiracy to prevent access to the
answer to this presumably common pitfall -- when you attempt to search in
the wxPython demos (2.8.4) for 'gridtablemessage', first the code for
GridCustTable.py is not in the Code tab of the appropriate demo where it
would be expected. Instead it's in a page linked from the Overview tab. In
addition, when you initiate a text search (via keyboard) for, say,
'gridtablemessage', the demo window forces the focus back to the Code
window, preventing the search from doing anything. I suppose this could be
applauded because it effectively forces the reader to read the code (though
oddly located) more thoroughly in order to come up with the needed lines.

I love wxPython! But this is about the hardest I've had to work for an
arcane answer to a common pitfall in a long while.

</rant>

I agree that sometimes wxGrid is a bad beast you have to fight with.
Most of the problems, from my point of view, come from the fact that
wxGrid is a very complex class, capable to do so many things...
sometimes I feel like you.
However, I saw so many beautiful things implemented with wxGrid (i.e.,
Julianne Sharer "Fripp" application,
http://fripp.netcipia.net/xwiki/bin/view/Main/WebHome), that I think
we are lucky in having such a powerful class.
I don't know if a better/easier implementation of wxGrid is possible:
but even if it is, someone has to take the burden of rewriting the
entire thing in a more straightforward way: it's a long and hard job.
I have been tempted to convert the famous MFC grid at codeproject
(http://www.codeproject.com/miscctrl/gridctrl.asp), but every time I
have been discouraged by the length and complexity of the code: my
sloppiness in coding in Python will probably end up in a slow, bad
performing kitchen sink.
However, about your rant, it's usually helpful to look at the Wiki:

1) wxPython-based:

http://wiki.wxpython.org/wxGrid

And specifically:

http://wiki.wxpython.org/wxGrid#head-99a55be9e3a0bdefe66603b371f7695308223846

2) wxWidget based:

http://www.wxwidgets.org/wiki/index.php/WxGrid#Update_wxGrid_display_on_wxGridTableBase_data_changes

HTH.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.virgilio.it/infinity77/

···

On 5/26/07, Eric Ongerth wrote:

Aha! There’s the missing link. I have not been paying enough attention to the Wiki. Thank you!

p.s. - I don’t know how I made such a typo in my code snippet… "
wx.grid.GridTableMessage(" was only supposed to be included once, not twice in a row.

···

On 5/26/07, Andrea Gavana andrea.gavana@gmail.com wrote:

However, about your rant, it’s usually helpful to look at the Wiki:

  1. wxPython-based:

http://wiki.wxpython.org/wxGrid

And specifically:


http://wiki.wxpython.org/wxGrid#head-99a55be9e3a0bdefe66603b371f7695308223846

However, about your rant, it’s usually helpful to look at the Wiki:

  1. wxPython-based:


http://wiki.wxpython.org/wxGrid

And specifically:

[

http://wiki.wxpython.org/wxGrid#head-99a55be9e3a0bdefe66603b371f7695308223846](http://wiki.wxpython.org/wxGrid#head-99a55be9e3a0bdefe66603b371f7695308223846)

Hmm, this is odd:
Quoting from the following wxPyWiki page:


http://wiki.wxpython.org/AppendingGridTable

## Introduction Gives a way to append a line into a Grid table used with a Grid.

What Objects are Involved

wxgrid, wxgridtablebase

Process Overview

There
are plenty of sample in the wxPy demo showing how to create/modify a
Grid, but not to show how to insert/append a row. This is particularly
difficult in the case of the Grid table as the appenrows/insertrows
functions does not work. This
sample processes by destroying and creating again the Grid. As the
refresh method does not work on Windows XP, a workaround is got by
getting and setting the size

... The author of the page proceeds to give an example app -- which appears to correctly use the wxGRIDTABLE_NOTIFY_ROWS_APPENDED message -- but instead of writing his own AppendRows override method within his custom GridTableBase class and sending the necessary message from there, he sends it from within his SetValue method. He does not override wx.PyGridTableBase.AppendRows() as far as I can tell.

If I’m not mistaken, in order for the AppendRows action to work properly in a Grid that uses a GridTableBase, we’re required to override the AppendRows function and it must return True or else wx considers the Append action rejected or vetoed by the Table.

The wiki page I’m referring to is set as “immutable” so I could not post this as comments. Unless I’m really missing something, the page is misleading – suggesting that a non-broken mechanism in wxPython is broken when in fact it is not. It’s definitely not necessary to destroy and recreate your entire grid every time a row is appended or inserted.

Perhaps this is a temporal difference – maybe the page was written during an earlier version with different behavior.
FYI…

···

On 5/26/07, Andrea Gavana andrea.gavana@gmail.com wrote: