[wxPython-users] Grid Values: Getting and Setting
Werner F. Bruhin
werner.bruhin at free.fr
Sun Sep 2 00:49:20 PDT 2007
Rich,
Rich Shepard wrote:
> 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)
SetValue and GetValue "work" on one row/column and give you just that
one value, so you would only want to update the changed row/column and
not all of them in SetValue.
...
> Now the OnSave() function bound to the button calls
> dataTable.SetValue().
I would think that in OnSave() you would want to do dbconnection.commit()
Werner
More information about the wxpython-users
mailing list