How to AppendRows() to wx.grid.Grid

I'm really puzzled because my code is not working as expected. In the
method I'm debugging are these lines:

   self.dataGrid.ClearGrid()
   nRows = self.table.GetNumberRows()
         self.dataGrid.AppendRows(nRows - 1)
         self.dataGrid.ForceRefresh()

   When I walk through the method using winpdb, nRows is correctly assigned
the value of 114. (The grid is initialized with 1 row.) However, nothing
happens when 'self.dataGrid.AppendRows(nRows - 1)' is executed; therefore,
there's nothing to refresh.

   Because the data are managed by a grid table, in the class
dataTable(wx.grid.PyGridTableBase) I created a method to approve the
addition of rows to the display grid:

   def AppendRows(self, numRows=1):
           return self.GetNumberRows() - 1

   There must be something wrong with my syntax in either or both of these
two methods, but I cannot find the error(s) from the book or online docs. A
clue is appreciated.

Rich

···

--
Richard B. Shepard, Ph.D. | Integrity Credibility
Applied Ecosystem Services, Inc. | Innovation
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863

Appends one or more new rows to the bottom of the grid and returns true if
successful. The updateLabels argument is not used at present. If you are
using a derived grid table class you will need to override
wxGridTableBase::AppendRows<wx_wxgridtablebase.html#wxgridtablebaseappendrows>

Raffaello,

   Done the above, as noted in my message.

This is simply copied from the documentation, but from your mail I
understand that you are really using a table, and if so
self.dataGrid.AppendRows does not work.

   Oh? This is counter to what the book and on-line docs indicate. If my data
are stored in a database table and retrieved into a list of tuples, I cannot
dynamically size the table to accommodate all data rows? If that's the case,
I'm in a real bind because the grid widget wants to be initialized when the
application is invoked, and the size of the grid cannot be known then.

   How do I size the grid to the number of tuples in the list?

Rich

···

On Fri, 30 May 2008, raffaello wrote:

--
Richard B. Shepard, Ph.D. | Integrity Credibility
Applied Ecosystem Services, Inc. | Innovation
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863

Rafaello,

   That it is. Thank you very much.

Rich

···

On Fri, 30 May 2008, raffaello wrote:

And the problem of adding rows should be solved.

--
Richard B. Shepard, Ph.D. | Integrity Credibility
Applied Ecosystem Services, Inc. | Innovation
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863

Don’t mention it.
I hope that Robin is not reading us, but the more I delve into wx.grid the less I see the marginal utility of the tablebase.

···

2008/5/30 Rich Shepard rshepard@appl-ecosys.com:

On Fri, 30 May 2008, raffaello wrote:

And the problem of adding rows should be solved.

Rafaello,

That it is. Thank you very much.

Rich

Richard B. Shepard, Ph.D. | Integrity Credibility

Applied Ecosystem Services, Inc. | Innovation

<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863


wxpython-users mailing list

wxpython-users@lists.wxwidgets.org

http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

raffaello wrote:

Don't mention it.
I hope that Robin is not reading us, but the more I delve
into wx.grid the less I see the marginal utility of the tablebase.

IMHO there are several uses -

1. If your data is very large - see the demo for an example of a grid
consisting of 10000 columns x 10000 rows. Response is instant. If you tried
this with a normal grid it would be much slower.

2. If you do not want all columns or rows to be displayed. You can play
tricks with setting row heights or column widths to zero, but if there are a
lot of them, or they change dynamically, it can be more effective to
maintain a mapping between the actual data and the visible data, and use
that to determine what to actually display.

3. If you have an indirect link between the actual data and the data to
display. I use this technique throughout my system, as I use a grid to
display the entire contents of a database table. I want my system to be
scalable, so the table may have 20 rows or 20 million rows. I do not read in
the entire contents of the table up front, I open a database cursor, and
'fetch' the data required in the GetValue() method of the tablebase. It
works very well.

In response to Rich's original question, this is how I append rows to a grid

···

-

        msg = wx.grid.GridTableMessage(self.tablebase,
            wx.grid.GRIDTABLE_NOTIFY_ROWS_APPENDED,noRows)
        self.ProcessTableMessage(msg)

where self is an instance of wx.grid.Grid.

I just had a look at the docs to quote you a reference, but I cannot see
where I got this information from - it has been working for years without
any problems. You can find an example of this in demo/GridCustTable.py.

HTH

Frank Millman