I try to plug a PyGridTableBase derived object to a wx.Grid table and I face some problems to understand
how it works from inside. You will find enclosed a smippet of my code. Basically, the table will be embedded
in a notebook.
Here are my questions/problems:
- from wxwidgets documentation it is said that "The data can be stored in the way most convenient for the application but has to be provided in string form to wxGrid". I guess that with wxPython PyGridTablleBase objects this constraint is not compulsory anymore. Right ? (e.g. my code my dummy data is made of a dictionary whose keys are integers).
- when running the code and changing from one cell to another, the method GetValue of my PyGridTable object is called many many times. I can
not figure why. Is that normal ? If no, Would you have any idea how to avoid this?
from wxwidgets documentation I could read that when you bind your grid to a EVT_GRID_CELL_CHANGED event the method GetString applied on the event object should return the old cell value. When trying from my example, GetString() returns an empty string. Is this a bug or do I misunderstand something ?
I try to plug a PyGridTableBase derived object to a wx.Grid table and I
face some problems to understand
how it works from inside. You will find enclosed a smippet of my code.
Basically, the table will be embedded
in a notebook.
Here are my questions/problems:
- from wxwidgets documentation it is said that "The data can be
stored in the way most convenient for the application but has to be
provided in string form to wxGrid". I guess that with wxPython
PyGridTablleBase objects this constraint is not compulsory anymore.
Right ? (e.g. my code my dummy data is made of a dictionary whose keys
are integers).
More or less. The wrapper for GetValue will do the equivalent of str(value) on the value returned from the Python method, so as long as str() does the right thing for your data type then it should work fine. When using your own table you can also specify that columns have a different data type, such as integer or boolean, and then if the table can provide the values with that type (by overriding one of the CanGetValueAs* methods) then it may use something other than GetValue to fetch it, saving some string conversions. Personally I've usually found that it's easiest to just use the string values.
- when running the code and changing from one cell to another, the
method GetValue of my PyGridTable object is called many many times. I
can not figure why. Is that normal ? If no, Would you have any idea how
to avoid this?
Whenever a cell needs to be drawn the renderer will fetch the value from the table, and sometimes more cells than you expect will be in the update region depending on platform and what operation is being done on the grid. For example, changing the highlighted cell will probably result in that cell and all cells around it to be redrawn IIRC. Also I think that in some situations on Mac a Refresh() of a portion of the window will actually refresh the whole window, so all visible cells would be fetched in that case.
- from wxwidgets documentation I could read that when you bind your
grid to a EVT_GRID_CELL_CHANGED event the method GetString applied on
the event object should return the old cell value. When trying from my
example, GetString() returns an empty string. Is this a bug or do I
misunderstand something ?
It's working for me in my current 2.9.5 svn workspace.
I try to plug a
PyGridTableBase derived object to a wx.Grid table and I
face some problems to understand
how it works from inside. You will find enclosed a smippet of my code.
Basically, the table will be embedded
in a notebook.
Here are my questions/problems:
- from wxwidgets documentation it is said that "The data can be
stored in the way most convenient for the application but has to be
provided in string form to wxGrid". I guess that with wxPython
PyGridTablleBase objects this constraint is not compulsory anymore.
Right ? (e.g. my code my dummy data is made of a dictionary whose keys
are integers).
More or less. The wrapper for GetValue will do the equivalent of str(value) on the value returned from the Python method, so as long as str() does the right thing for your data type then it should work fine. When using your own
table you can also specify that columns have a different data type, such as integer or boolean, and then if the table can provide the values with that type (by overriding one of the CanGetValueAs* methods) then it may use something other than GetValue to fetch it, saving some string conversions. Personally I’ve usually found that it’s easiest to just use the string values.
- when running the code and changing from one cell to another, the
method GetValue of my PyGridTable object is called many many times. I
can not figure why. Is that normal ? If no, Would you have any idea how
to avoid this?
Whenever a cell needs to be drawn the renderer will fetch the value from the table, and sometimes more cells than you expect will be in the update region depending on platform and what operation is being done on the grid. For example, changing the highlighted cell will probably
result in that cell and all cells around it to be redrawn IIRC. Also I think that in some situations on Mac a Refresh() of a portion of the window will actually refresh the whole window, so all visible cells would be fetched in that case.
- from wxwidgets documentation I could read that when you bind your
grid to a EVT_GRID_CELL_CHANGED event the method GetString applied on
the event object should return the old cell value. When trying from my
example, GetString() returns an empty string. Is this a bug or do I
misunderstand something ?
It’s working for me in my current 2.9.5 svn workspace.