class table_view.TableView(Widget)
A TableView
provides a tabular view of data having a fixed number of columns and a
variable number of rows. There may be a header providing titles for the
columns. There is provision for scrolling and for allowing the user to
select rows.
An auxiliary class TableColumn is used to configure the formatting of the headers and data.
By default, all headers and data are displayed textually, but this can be changed by overriding methods of the TableView.
Constructor
- TableView(nrows = None, height = None, header_height = None, row_height = None, scrolling = True)
The TableView is initialized with a width and height determined as follows:
- The initial width is calculated from the information in the columns attribute.
- The initial height, excluding the header, is determined either directly by the height parameter or by the row height and number of rows nrows. If no row_height is specified, it is calculated from the size of the font.
- The height of the header is determined by header_height, or the size of the header font.
If scrolling is true, the table will display scrolling arrows.
Attributes
- columns
- A list of TableColumn instances describing the columns of the table.
header_font- Font in which to display the column headers.
header_fg_color- Foreground colour of the column headers.
header_bg_color- Background colour of the column headers, or None.
header_spacing- Space to leave between the header and the rows.
column_margin- Space to leave either side of the contents of a column.
Abstract Methods
- num_rows()
- Should return the number of rows in the table. Must be implemented.
row_data(n)- Should return a sequence of data items for row number n. The data items may be of any type, provided they can be formatted as specified by the corresponding TableColumn. Must be implemented.
row_is_selected(n)- Should return true if row number n is to be considered selected. The default implementation always returns false.
click_row(n, event)- Called when row number n is clicked. The default implementation does nothing.
Default Methods
- draw_header_cell(surface, colnum, rect, coldesc)
- Draws the header of column number colnum. The rect is the rectangle corresponding to the header area, and coldesc is the TableColumn instance describing the column. By default, the column's title is displayed using the header_font and the alignment specified by coldesc.
draw_table_cell(surface, colnum, data, rect, coldesc)- Draws a cell of the table. The colnum is the column number, data is the data item to be displayed, rect is the rectangle corresponding to the cell, and coldesc is the TableColumn instance describing the column. By default, the data is formatted as specified by coldesc and rendered using the widget's font.
---