Phoenix Logo

phoenix_title 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.


class_hierarchy Class Hierarchy

Inheritance diagram for class GridTableBase:


sub_classes Known Subclasses

wx.grid.GridStringTable


method_summary Methods Summary

__init__ Default constructor.
AppendCols Exactly the same as AppendRows but for columns.
AppendRows Append additional rows at the end of the table.
CanGetValueAs Returns True if the value of the given cell can be accessed as if it were of the specified type.
CanHaveAttributes Returns True if this table supports attributes or False otherwise.
CanSetValueAs Returns True if the value of the given cell can be set as if it were of the specified type.
Clear Clear the table contents.
DeleteCols Exactly the same as DeleteRows but for columns.
DeleteRows Delete rows from the table.
GetAttr Return the attribute for the given cell.
GetAttrProvider Returns the attribute provider currently being used.
GetColLabelValue Return the label of the specified column.
GetColsCount Return the number of columns in the table.
GetNumberCols Must be overridden to return the number of columns in the table.
GetNumberRows Must be overridden to return the number of rows in the table.
GetRowLabelValue Return the label of the specified row.
GetRowsCount Return the number of rows in the table.
GetTypeName Returns the type of the value in the given cell.
GetValue Must be overridden to implement accessing the table values as text.
GetValueAsBool Returns the value of the given cell as a boolean.
GetValueAsDouble Returns the value of the given cell as a double.
GetValueAsLong Returns the value of the given cell as a long.
GetView Returns the last grid passed to SetView .
InsertCols Exactly the same as InsertRows but for columns.
InsertRows Insert additional rows into the table.
IsEmpty Same as IsEmptyCell but taking wx.grid.GridCellCoords.
IsEmptyCell May be overridden to implement testing for empty cells.
SetAttr Set attribute of the specified cell.
SetAttrProvider Associate this attributes provider with the table.
SetColAttr Set attribute of the specified column.
SetColLabelValue Exactly the same as SetRowLabelValue but for columns.
SetRowAttr Set attribute of the specified row.
SetRowLabelValue Set the given label for the specified row.
SetValue Must be overridden to implement setting the table values as text.
SetValueAsBool Sets the value of the given cell as a boolean.
SetValueAsDouble Sets the value of the given cell as a double.
SetValueAsLong Sets the value of the given cell as a long.
SetView Called by the grid when the table is associated with it.

api Class API



class wx.grid.GridTableBase(Object)

Possible constructors:

GridTableBase()

The almost abstract base class for grid tables.


Methods



__init__(self)

Default constructor.



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 leave InsertRows 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 for GRID_VALUE_NUMBER but also for GRID_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 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.

Return type:bool


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

CanGetValueAs



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.

Parameters:
  • pos (int) –
  • numCols (int) –
Return type:

bool



DeleteRows(self, pos=0, numRows=1)

Delete rows from the table.

Notice that currently deleting a row intersecting a multi-cell (see SetCellSize()) is not supported and will result in a crash.

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.

Parameters:
  • row (int) –
  • col (int) –
  • kind (GridCellAttr.wxAttrKind) –
Return type:

wx.grid.GridCellAttr



GetAttrProvider(self)

Returns the attribute provider currently being used.

This function may return None if the attribute provider hasn’t been neither associated with this table by SetAttrProvider nor created on demand by any other methods.

Return type: wx.grid.GridCellAttrProvider


GetColLabelValue(self, col)

Return the label of the specified column.

Parameters:col (int) –
Return type: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.

Return type:int


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: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.

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:

string



GetValue(self, row, col)

Must be overridden to implement accessing the table values as text.

Parameters:
  • row (int) –
  • col (int) –
Return type:

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.

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 returns True when called with GRID_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 returns True when called with GRID_VALUE_NUMBER argument. Default implementation always return 0.

Parameters:
  • row (int) –
  • col (int) –
Return type:

long



GetView(self)

Returns the last grid passed to SetView .

Return type: wx.grid.Grid


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 by GetValue , 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:


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.

Parameters: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.

Parameters:


SetColLabelValue(self, col, label)

Exactly the same as SetRowLabelValue but for columns.

Parameters:
  • col (int) –
  • label (string) –


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:


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) –


SetValue(self, row, col, value)

Must be overridden to implement setting the table values as text.

Parameters:
  • 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.

Parameters:
  • 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.

Parameters:
  • 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.

Parameters:
  • 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.

Parameters:grid (wx.grid.Grid) –

Properties



AttrProvider

See GetAttrProvider and SetAttrProvider



ColsCount

See GetColsCount



NumberCols

See GetNumberCols



NumberRows

See GetNumberRows



RowsCount

See GetRowsCount



View

See GetView and SetView