[wxPython] One more grid issue

Hi Robin et al.,

nearly finished with the basics of my current project, at least
one grid issue remain:

type problems

I've combined some grids, based on wxPyGridTableBase with
a sql interface and a custom grid editor. The records contain
ints, floats and strings as usual. When loading records into
the grid, ints are going through as ints. The column dataType
is set to wxGRID_VALUE_NUMBER. After editing such an int value
I tried to store the value into the table as int, but failed,
because SetValue is expecting val as a string value:
grid.GetTable().SetValue(row, col, val) # update the table
This results is automagic type changes of all edited fields.
This won't harm, unless I want to act on some values. Do I
need to mess with type conversion code, or are there other
ways to handle this issue? I thought, the column datatypes
interface was made to ensure type safety on the grid.

Thanks in advance
Pete

···

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/wxpython-users

type problems

I've combined some grids, based on wxPyGridTableBase with
a sql interface and a custom grid editor. The records contain
ints, floats and strings as usual. When loading records into
the grid, ints are going through as ints. The column dataType
is set to wxGRID_VALUE_NUMBER. After editing such an int value
I tried to store the value into the table as int, but failed,
because SetValue is expecting val as a string value:

By default the table interface only allows string to pass to and from the
table, and it tries to do conversions where possible. If you want to use
other types, your table needs to let the grid (well the editors actually)
know that other types are possible by overriding the following methods
(shown in C++ syntax):

    bool CanGetValueAs( int row, int col, const wxString& typeName );
    bool CanSetValueAs( int row, int col, const wxString& typeName );

They should return true for the types your table supports. By default they
return false for all but wxGRID_VALUE_STRING and the standard editors fall
back to using strings and doing type conversions even if they would rather
have an int or something.

Your table can then override the following to actually transfer those
alternate types:

    long GetValueAsLong( int row, int col );
    double GetValueAsDouble( int row, int col );
    bool GetValueAsBool( int row, int col );
    void SetValueAsLong( int row, int col, long value );
    void SetValueAsDouble( int row, int col, double value );
    void SetValueAsBool( int row, int col, bool value );

I should probably add methods for passing arbitrary Python objects to and
from the table and editors, but these will let you handle al the basic
types, even from the standard editors.

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com
http://wxPython.org Java give you jitters?
http://wxPROs.com Relax with wxPython!

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/wxpython-users