[wxPython-users] Grid Values: Getting and Setting

Rich Shepard rshepard at appl-ecosys.com
Sat Sep 1 15:49:49 PDT 2007


On Fri, 31 Aug 2007, Paul McNett wrote:

> It seems backwards, yes, until you flip your mind around and realize that
> these methods are meant to be overridden by you, and that from the Grid's
> perspective, it is asking the Table object for the value, hence whatever
> is returned by Table.GetValue() is what gets displayed in that cell by the
> grid.

Paul,

   That's what I suspected, and it's nice to have my uncertainty erased.
Thank you.

> You don't need to iterate the cells to get the values. Just override
> Table.SetValue() and at that time write the value to the proper row and
> field in the structure representing your database table.

   OK. The application uses SQLite3 as the backend with pysqlite2 as the
glue. In class dataTable() I now have:

   def SetValue(self, row, col, value):
     stmt = """INSERT or REPLACE into Data (comp, subcomp, var, curr1, curr2,
                                            curr3, curr4, curr5, curr6, curr7,
                                            curr8, curr9, curr10, curr11,
                                            curr12, noact, alt2, alt3, alt4,
                                            alt5, alt6, alt7, alt8, alt9, alt10,
                                            alt11, alt12, alt13, alt14, alt15,
                                            alt16, alt17, alt18
 					   values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,
 					   ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,
 					   ?,?)"""
     self.cur.execute(stmt)

   With other widgets, I follow the stmt with a list of fields holding the
values to be inserted/updated in the table. Does this look reasonable for
writing grid data?

> Ditto, by the way, for getting the values from the database table. Override 
> GetValue() to retrieve the value for your cell from the data structure.

   This I did already. It was going the other way that lost me.

> Then when the user chooses to save(), you don't need to find anything from 
> the grid at all: just iterate through your table representation and 
> insert/update/delete as needed.

   Now the OnSave() function bound to the button calls dataTable.SetValue().

Again, thanks,

Rich

-- 
Richard B. Shepard, Ph.D.               |    The Environmental Permitting
Applied Ecosystem Services, Inc.        |         Accelerators(TM)
<http://www.appl-ecosys.com>     Voice: 503-667-4517      Fax: 503-667-8863




More information about the wxpython-users mailing list