wx.grid.GridTableBase

Inheritance diagram for wx.grid.GridTableBase:



Description

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.

Derived From

Known Subclasses

wx.grid.GridStringTable, wx.grid.PyGridTableBase

Class API

Methods

__init__()
No docstrings available for this method.

AppendCols(numCols=1)

Exactly the same as AppendRows but for columns.

Parameters:

  • numCols (long): The number of columns to add.

Returns:

bool


AppendRows(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 (long) : The number of rows to add.

Returns:

bool


CanGetValueAs(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.

Parameters:

  • row (int)
  • col (int)
  • typeName (string)

Returns:

bool

Note

Note that a cell could be accessible in different ways, e.g. a numeric cell may return true for wx.grid.GRID_VALUE_NUMBER but also for wx.grid.GRID_VALUE_STRING indicating that the value can be coerced to a string form.


CanHaveAttributes()

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.


Returns:

bool


CanSetValueAs(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)

Returns:

bool

See also

CanGetValueAs


Clear()

Clear the table contents.

Modifying the table structure.

Notice that none of these functions are pure virtual as they don’t have to be implemented if the table structure is never modified after creation, i.e. neither rows nor columns are never added or deleted but that you do need to implement them if they are called, i.e. if your code either calls them directly or uses the matching wx.grid.Grid methods, as by default they simply do nothing which is definitely inappropriate.

This method is used by wx.grid.Grid.ClearGrid.


DeleteCols(pos=0, numCols=1)

Exactly the same as DeleteRows but for columns.

Parameters:

  • pos (long): The first column to delete.
  • numCols (long): The number of columns to delete.

Returns:

bool


DeleteRows(pos=0, numRows=1)

Delete rows from the table.

Parameters:

  • pos (long): The first row to delete.
  • numRows (long): The number of rows to delete.

Returns:

bool


GetAttr(row, col)

Return the attribute for the given cell.

By default forwarded to wx.grid.GridCellAttrProvider if any. May be overridden to handle attributes directly in the table.

Parameters:

  • row (int)
  • col (int)

Returns:

wx.grid.GridCellAttr


GetAttrProvider()

Get the currently used attr provider (may be None).

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.


Returns:

wx.grid.GridCellAttrProvider


GetColLabelValue(col)

Return the label of the specified column.

Parameters:

  • col (int)

Returns:

string


GetNumberCols()

Must be overridden to return the number of columns in the table.


Returns:

int


GetNumberRows()

Must be overridden to return the number of rows in the table.


Returns:

int


GetRowLabelValue(row)

Return the label of the specified row.

By default the numbers are used for labeling rows and Latin letters for labeling columns. If the table has more than 26 columns, the pairs of letters are used starting from the 27-th one and so on, i.e. the sequence of labels is A, B, ..., Z, AA, AB, ..., AZ, BA, ..., ZZ, AAA, ...

Parameters:

  • row (int)

Returns:

string


GetTypeName(row, col)

Returns the type of the value in the given cell.

By default all cells are strings and this method returns wx.grid.GRID_VALUE_STRING.

Parameters:

  • row (int)
  • col (int)

Returns:

string


GetValue(row, col)

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

Parameters:

  • row (int)
  • col (int)

Returns:

string


GetValueAsBool(row, col)

Returns the value of the given cell as a boolean.

This should only be called if CanGetValueAs returns True when called with wx.grid.GRID_VALUE_BOOL argument.

Default implementation always return False.

Parameters:

  • row (int)
  • col (int)

Returns:

bool


GetValueAsDouble(row, col)

Returns the value of the given cell as a double.

This should only be called if CanGetValueAs returns True when called with wx.grid.GRID_VALUE_FLOAT argument.

Default implementation always return 0.0.

Parameters:

  • row (int)
  • col (int)

Returns:

double


GetValueAsLong(row, col)

Returns the value of the given cell as a long integer.

This should only be called if CanGetValueAs returns True when called with wx.grid.GRID_VALUE_NUMBER argument.

Default implementation always return 0.

Parameters:

  • row (int)
  • col (int)

Returns:

long


GetView()

Returns the last grid passed to SetView.


Returns:

wx.grid.Grid


InsertCols(pos=0, numCols=1)

Exactly the same as InsertRows but for columns.

Parameters:

  • pos (long): The position of the first new column.
  • numCols (long) : The number of columns to insert.

Returns:

bool


InsertRows(pos=0, numRows=1)

Insert additional rows at the end of the table.

Parameters:

  • pos (long): The position of the first new row.
  • numRows (long) : The number of rows to insert.

Returns:

bool


IsEmptyCell(row, col)

Must be overridden to implement testing for empty cells.

Parameters:

  • row (int)
  • col (int)

Returns:

bool


SetAttr(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(attrProvider)

Attributes management.

By default the attributes management is delegated to wx.grid.GridCellAttrProvider class. You may override the methods in this section to handle the attributes directly if, for example, they can be computed from the cell values. 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(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(col, label)

Exactly the same as SetRowLabelValue but for columns.

Parameters:

  • col (int)
  • label (string)

SetRowAttr(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(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(row, col, value)

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

Parameters:

  • row (int)
  • col (int)
  • value (string)

SetValueAsBool(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 wx.grid.GRID_VALUE_BOOL argument.

Default implementation doesn’t do anything.

Parameters:

  • row (int)
  • col (int)
  • value (bool)

SetValueAsDouble(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 wx.grid.GRID_VALUE_FLOAT argument.

Default implementation doesn’t do anything.

Parameters:

  • row (int)
  • col (int)
  • value (double)

SetValueAsLong(row, col, value)

Sets the value of the given cell as a long integer.

This should only be called if CanSetValueAs returns True when called with wx.grid.GRID_VALUE_NUMBER argument.

Default implementation doesn’t do anything.

Parameters:

  • row (int)
  • col (int)
  • value (long)

SetView(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.

Overriding this method is optional.

Parameters:


Properties

AttrProvider
See GetAttrProvider and SetAttrProvider
NumberCols
See GetNumberCols
NumberRows
See GetNumberRows
View
See GetView and SetView