The almost abstract base class for grid tables.
A grid table is responsible for storing the grid data and, indirectly, grid cell attributes. The data can be stored in the way most convenient for the application but has to be provided in string form to wx.grid.Grid. It is also possible to provide cells values in other formats if appropriate, e.g. as numbers.
This base class is not quite abstract as it implements a trivial strategy for storing the attributes by forwarding it to wx.grid.GridCellAttrProvider and also provides stubs for some other functions. However it does have a number of pure virtual methods which must be implemented in the derived classes.
See also
Default constructor. |
|
Exactly the same as |
|
Append additional rows at the end of the table. |
|
Returns |
|
Returns |
|
Override to return |
|
Returns |
|
Clear the table contents. |
|
Exactly the same as |
|
Delete rows from the table. |
|
Return the attribute for the given cell. |
|
Returns the attribute provider currently being used. |
|
Return the attribute for the given cell. |
|
Return the label of the specified column. |
|
Return the number of columns in the table. |
|
Return the label of the grid’s corner. |
|
Must be overridden to return the number of columns in the table. |
|
Must be overridden to return the number of rows in the table. |
|
Return the label of the specified row. |
|
Return the number of rows in the table. |
|
Returns the type of the value in the given cell. |
|
Must be overridden to implement accessing the table values as text. |
|
Returns the value of the given cell as a boolean. |
|
Returns the value of the given cell as a double. |
|
Returns the value of the given cell as a long. |
|
Returns the last grid passed to |
|
Exactly the same as |
|
Insert additional rows into the table. |
|
Same as |
|
May be overridden to implement testing for empty cells. |
|
Set attribute of the specified cell. |
|
Associate this attributes provider with the table. |
|
Set attribute of the specified column. |
|
Exactly the same as |
|
Set the given label for the grid’s corner. |
|
Set attribute of the specified row. |
|
Set the given label for the specified row. |
|
Must be overridden to implement setting the table values as text. |
|
Sets the value of the given cell as a boolean. |
|
Sets the value of the given cell as a double. |
|
Sets the value of the given cell as a long. |
|
Called by the grid when the table is associated with it. |
See |
|
See |
|
See |
|
See |
|
See |
|
wx.grid.
GridTableBase
(Object)¶Possible constructors:
GridTableBase()
The almost abstract base class for grid tables.
__init__
(self)¶Default constructor.
AppendCols
(self, numCols=1)¶Exactly the same as AppendRows
but for columns.
numCols (int) –
bool
AppendRows
(self, numRows=1)¶Append additional rows at the end of the table.
This method is provided in addition to InsertRows
as some data models may only support appending rows to them but not inserting them at arbitrary locations. In such case you may implement this method only and leave InsertRows
unimplemented.
numRows (int) – The number of rows to add.
bool
CanGetValueAs
(self, row, col, typeName)¶Returns True
if the value of the given cell can be accessed as if it were of the specified type.
By default the cells can only be accessed as strings. Note that a cell could be accessible in different ways, e.g. a numeric cell may return True
for GRID_VALUE_NUMBER
but also for GRID_VALUE_STRING
indicating that the value can be coerced to a string form.
row (int) –
col (int) –
typeName (string) –
bool
CanHaveAttributes
(self)¶Returns True
if this table supports attributes or False
otherwise.
By default, the table automatically creates a wx.grid.GridCellAttrProvider when this function is called if it had no attribute provider before and returns True
.
bool
CanMeasureColUsingSameAttr
(self, col)¶Override to return True
if the same attribute can be used for measuring all cells in the given column.
This function is provided for optimization purposes: it returns False
by default, but can be overridden to return True
when all the cells in the same grid column use sensibly the same attribute, i.e. they use the same renderer (either explicitly, or implicitly, due to their type as returned by GetTypeName
) and the font of the same size.
Returning True
from this function allows AutoSizeColumns() to skip looking up the attribute and the renderer for each individual cell, which results in very noticeable performance improvements for the grids with many rows.
col (int) –
bool
New in version 4.1/wxWidgets-3.1.4.
CanSetValueAs
(self, row, col, typeName)¶Returns True
if the value of the given cell can be set as if it were of the specified type.
row (int) –
col (int) –
typeName (string) –
bool
See also
Clear
(self)¶Clear the table contents.
This method is used by wx.grid.Grid.ClearGrid
.
DeleteCols
(self, pos=0, numCols=1)¶Exactly the same as DeleteRows
but for columns.
pos (int) –
numCols (int) –
bool
DeleteRows
(self, pos=0, numRows=1)¶Delete rows from the table.
pos (int) – The first row to delete.
numRows (int) – The number of rows to delete.
bool
GetAttr
(self, row, col, kind)¶Return the attribute for the given cell.
By default this function is simply forwarded to wx.grid.GridCellAttrProvider.GetAttr
but it may be overridden to handle attributes directly in the table.
Prefer to use GetAttrPtr
to avoid the need to call DecRef() on the returned pointer manually.
row (int) –
col (int) –
kind (GridCellAttr.wxAttrKind) –
GetAttrProvider
(self)¶Returns the attribute provider currently being used.
This function may return None
if the attribute provider hasn’t been either associated with this table by SetAttrProvider
nor created on demand by any other methods.
GetAttrPtr
(self, row, col, kind)¶Return the attribute for the given cell.
This method is identical to GetAttr
, but returns a smart pointer, which frees the caller from the need to call DecRef() manually.
row (int) –
col (int) –
kind (GridCellAttr.wxAttrKind) –
wx.grid.GridCellAttrPtr
New in version 4.1/wxWidgets-3.1.4.
GetColLabelValue
(self, col)¶Return the label of the specified column.
col (int) –
string
GetColsCount
(self)¶Return the number of columns in the table.
This method is not virtual and is only provided as a convenience for the derived classes which can’t call GetNumberCols
without a const_cast
from their methods.
int
GetCornerLabelValue
(self)¶Return the label of the grid’s corner.
string
New in version 4.1/wxWidgets-3.1.2.
GetNumberCols
(self)¶Must be overridden to return the number of columns in the table.
For backwards compatibility reasons, this method is not const. Use GetColsCount
instead of it in methods of derived table classes,
int
GetNumberRows
(self)¶Must be overridden to return the number of rows in the table.
For backwards compatibility reasons, this method is not const. Use GetRowsCount
instead of it in methods of derived table classes.
int
GetRowLabelValue
(self, row)¶Return the label of the specified row.
row (int) –
string
GetRowsCount
(self)¶Return the number of rows in the table.
This method is not virtual and is only provided as a convenience for the derived classes which can’t call GetNumberRows
without a const_cast
from their methods.
int
GetTypeName
(self, row, col)¶Returns the type of the value in the given cell.
By default all cells are strings and this method returns GRID_VALUE_STRING
.
row (int) –
col (int) –
string
GetValue
(self, row, col)¶Must be overridden to implement accessing the table values as text.
row (int) –
col (int) –
PyObject
GetValueAsBool
(self, row, col)¶Returns the value of the given cell as a boolean.
This should only be called if CanGetValueAs
returns True
when called with GRID_VALUE_BOOL
argument. Default implementation always return False
.
row (int) –
col (int) –
bool
GetValueAsDouble
(self, row, col)¶Returns the value of the given cell as a double.
This should only be called if CanGetValueAs
returns True
when called with GRID_VALUE_FLOAT
argument. Default implementation always return 0.0.
row (int) –
col (int) –
float
GetValueAsLong
(self, row, col)¶Returns the value of the given cell as a long.
This should only be called if CanGetValueAs
returns True
when called with GRID_VALUE_NUMBER
argument. Default implementation always return 0.
row (int) –
col (int) –
long
InsertCols
(self, pos=0, numCols=1)¶Exactly the same as InsertRows
but for columns.
pos (int) –
numCols (int) –
bool
InsertRows
(self, pos=0, numRows=1)¶Insert additional rows into the table.
pos (int) – The position of the first new row.
numRows (int) – The number of rows to insert.
bool
IsEmpty
(self, coords)¶Same as IsEmptyCell
but taking wx.grid.GridCellCoords.
Notice that this method is not virtual, only IsEmptyCell
should be overridden.
coords (wx.grid.GridCellCoords) –
bool
IsEmptyCell
(self, row, col)¶May be overridden to implement testing for empty cells.
This method is used by the grid to test if the given cell is not used and so whether a neighbouring cell may overflow into it. By default it only returns True
if the value of the given cell, as returned by GetValue
, is empty.
row (int) –
col (int) –
bool
SetAttr
(self, attr, row, col)¶Set attribute of the specified cell.
By default this function is simply forwarded to wx.grid.GridCellAttrProvider.SetAttr
.
The table takes ownership of attr
, i.e. will call DecRef() on it.
attr (wx.grid.GridCellAttr) –
row (int) –
col (int) –
SetAttrProvider
(self, attrProvider)¶Associate this attributes provider with the table.
The table takes ownership of attrProvider pointer and will delete it when it doesn’t need it any more. The pointer can be None
, however this won’t disable attributes management in the table but will just result in a default attributes being recreated the next time any of the other functions in this section is called. To completely disable the attributes support, should this be needed, you need to override CanHaveAttributes
to return False
.
attrProvider (wx.grid.GridCellAttrProvider) –
SetColAttr
(self, attr, col)¶Set attribute of the specified column.
By default this function is simply forwarded to wx.grid.GridCellAttrProvider.SetColAttr
.
The table takes ownership of attr
, i.e. will call DecRef() on it.
attr (wx.grid.GridCellAttr) –
col (int) –
SetColLabelValue
(self, col, label)¶Exactly the same as SetRowLabelValue
but for columns.
col (int) –
label (string) –
SetCornerLabelValue
(self)¶Set the given label for the grid’s corner.
The default version does nothing, i.e. the label is not stored. You must override this method in your derived class if you wish wx.grid.Grid.GetCornerLabelValue
to work.
`` (string) –
New in version 4.1/wxWidgets-3.1.2.
SetRowAttr
(self, attr, row)¶Set attribute of the specified row.
By default this function is simply forwarded to wx.grid.GridCellAttrProvider.SetRowAttr
.
The table takes ownership of attr
, i.e. will call DecRef() on it.
attr (wx.grid.GridCellAttr) –
row (int) –
SetRowLabelValue
(self, row, label)¶Set the given label for the specified row.
The default version does nothing, i.e. the label is not stored. You must override this method in your derived class if you wish wx.grid.Grid.SetRowLabelValue
to work.
row (int) –
label (string) –
SetValue
(self, row, col, value)¶Must be overridden to implement setting the table values as text.
row (int) –
col (int) –
value (string) –
SetValueAsBool
(self, row, col, value)¶Sets the value of the given cell as a boolean.
This should only be called if CanSetValueAs
returns True
when called with GRID_VALUE_BOOL
argument. Default implementation doesn’t do anything.
row (int) –
col (int) –
value (bool) –
SetValueAsDouble
(self, row, col, value)¶Sets the value of the given cell as a double.
This should only be called if CanSetValueAs
returns True
when called with GRID_VALUE_FLOAT
argument. Default implementation doesn’t do anything.
row (int) –
col (int) –
value (float) –
SetValueAsLong
(self, row, col, value)¶Sets the value of the given cell as a long.
This should only be called if CanSetValueAs
returns True
when called with GRID_VALUE_NUMBER
argument. Default implementation doesn’t do anything.
row (int) –
col (int) –
value (long) –
SetView
(self, grid)¶Called by the grid when the table is associated with it.
The default implementation stores the pointer and returns it from its GetView
and so only makes sense if the table cannot be associated with more than one grid at a time.
grid (wx.grid.Grid) –
AttrProvider
¶See GetAttrProvider
and SetAttrProvider
ColsCount
¶See GetColsCount
CornerLabelValue
¶NumberCols
¶See GetNumberCols
NumberRows
¶See GetNumberRows
RowsCount
¶See GetRowsCount