wx.grid.GridTableBase¶
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
Class Hierarchy¶
Known Subclasses¶
Methods Summary¶
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. |
Properties Summary¶
See |
|
See |
|
See |
|
See |
|
See |
|
Class API¶
- class wx.grid.GridTableBase(Object)¶
Possible constructors:
GridTableBase() -> None
The almost abstract base class for grid tables.
Methods¶
- __init__(self)¶
Default constructor.
- Return type:
None
- AppendCols(self, numCols=1)¶
Exactly the same as
AppendRows
but for columns.- Parameters:
numCols (int)
- Return type:
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 leaveInsertRows
unimplemented.- Parameters:
numRows (int) – The number of rows to add.
- Return type:
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
forGRID_VALUE_NUMBER
but also forGRID_VALUE_STRING
indicating that the value can be coerced to a string form.- Parameters:
row (int)
col (int)
typeName (string)
- Return type:
bool
- CanHaveAttributes(self)¶
Returns
True
if this table supports attributes orFalse
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
.- Return type:
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 returnTrue
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 byGetTypeName
) 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.- Parameters:
col (int)
- Return type:
bool
Added 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.- Parameters:
row (int)
col (int)
typeName (string)
- Return type:
bool
See also
- Clear(self)¶
Clear the table contents.
This method is used by
wx.grid.Grid.ClearGrid
.- Return type:
None
- DeleteCols(self, pos=0, numCols=1)¶
Exactly the same as
DeleteRows
but for columns.- Parameters:
pos (int)
numCols (int)
- Return type:
bool
- DeleteRows(self, pos=0, numRows=1)¶
Delete rows from the table.
- Parameters:
pos (int) – The first row to delete.
numRows (int) – The number of rows to delete.
- Return type:
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.- Parameters:
row (int)
col (int)
kind (GridCellAttr.wxAttrKind)
- Return type:
- 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 bySetAttrProvider
nor created on demand by any other methods.- Return type:
- 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.- Parameters:
row (int)
col (int)
kind (GridCellAttr.wxAttrKind)
- Return type:
wx.grid.GridCellAttrPtr
Added in version 4.1/wxWidgets-3.1.4.
- GetColLabelValue(self, col)¶
Return the label of the specified column.
- Parameters:
col (int)
- Return type:
str
- 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 aconst_cast
from their methods.- Return type:
int
- GetCornerLabelValue(self)¶
Return the label of the grid’s corner.
- Return type:
str
Added 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,- Return type:
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.- Return type:
int
- GetRowLabelValue(self, row)¶
Return the label of the specified row.
- Parameters:
row (int)
- Return type:
str
- 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 aconst_cast
from their methods.- Return type:
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
.- Parameters:
row (int)
col (int)
- Return type:
str
- GetValue(self, row, col)¶
Must be overridden to implement accessing the table values as text.
- Parameters:
row (int)
col (int)
- Return type:
Any
- GetValueAsBool(self, row, col)¶
Returns the value of the given cell as a boolean.
This should only be called if
CanGetValueAs
returnsTrue
when called withGRID_VALUE_BOOL
argument. Default implementation always returnFalse
.- Parameters:
row (int)
col (int)
- Return type:
bool
- GetValueAsDouble(self, row, col)¶
Returns the value of the given cell as a double.
This should only be called if
CanGetValueAs
returnsTrue
when called withGRID_VALUE_FLOAT
argument. Default implementation always return 0.0.- Parameters:
row (int)
col (int)
- Return type:
float
- GetValueAsLong(self, row, col)¶
Returns the value of the given cell as a long.
This should only be called if
CanGetValueAs
returnsTrue
when called withGRID_VALUE_NUMBER
argument. Default implementation always return 0.- Parameters:
row (int)
col (int)
- Return type:
int
- InsertCols(self, pos=0, numCols=1)¶
Exactly the same as
InsertRows
but for columns.- Parameters:
pos (int)
numCols (int)
- Return type:
bool
- InsertRows(self, pos=0, numRows=1)¶
Insert additional rows into the table.
- Parameters:
pos (int) – The position of the first new row.
numRows (int) – The number of rows to insert.
- Return type:
bool
- IsEmpty(self, coords)¶
Same as
IsEmptyCell
but taking wx.grid.GridCellCoords.Notice that this method is not virtual, only
IsEmptyCell
should be overridden.- Parameters:
coords (wx.grid.GridCellCoords)
- Return type:
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 byGetValue
, is empty.- Parameters:
row (int)
col (int)
- Return type:
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.- Parameters:
attr (wx.grid.GridCellAttr)
row (int)
col (int)
- Return type:
None
- 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 overrideCanHaveAttributes
to returnFalse
.- Parameters:
attrProvider (wx.grid.GridCellAttrProvider)
- Return type:
None
- 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.- Parameters:
attr (wx.grid.GridCellAttr)
col (int)
- Return type:
None
- SetColLabelValue(self, col, label)¶
Exactly the same as
SetRowLabelValue
but for columns.- Parameters:
col (int)
label (string)
- Return type:
None
- 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.- Parameters:
`` (string)
- Return type:
None
Added 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.- Parameters:
attr (wx.grid.GridCellAttr)
row (int)
- Return type:
None
- 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.- Parameters:
row (int)
label (string)
- Return type:
None
- SetValue(self, row, col, value)¶
Must be overridden to implement setting the table values as text.
- Parameters:
row (int)
col (int)
value (string)
- Return type:
None
- SetValueAsBool(self, row, col, value)¶
Sets the value of the given cell as a boolean.
This should only be called if
CanSetValueAs
returnsTrue
when called withGRID_VALUE_BOOL
argument. Default implementation doesn’t do anything.- Parameters:
row (int)
col (int)
value (bool)
- Return type:
None
- SetValueAsDouble(self, row, col, value)¶
Sets the value of the given cell as a double.
This should only be called if
CanSetValueAs
returnsTrue
when called withGRID_VALUE_FLOAT
argument. Default implementation doesn’t do anything.- Parameters:
row (int)
col (int)
value (float)
- Return type:
None
- SetValueAsLong(self, row, col, value)¶
Sets the value of the given cell as a long.
This should only be called if
CanSetValueAs
returnsTrue
when called withGRID_VALUE_NUMBER
argument. Default implementation doesn’t do anything.- Parameters:
row (int)
col (int)
value (long)
- Return type:
None
- 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.- Parameters:
grid (wx.grid.Grid)
- Return type:
None
Properties¶
- AttrProvider¶
See
GetAttrProvider
andSetAttrProvider
- ColsCount¶
See
GetColsCount
- CornerLabelValue¶
- NumberCols¶
See
GetNumberCols
- NumberRows¶
See
GetNumberRows
- RowsCount¶
See
GetRowsCount