TermTk.TTkWidgets.TTkModelView.tablemodelcsv

TTkTableModelCSV

class TTkTableModelCSV(*, filename: str = None, fd=None)[source]

TTkTableModelCSV extends TTkTableModelList with cvs loading helpers.

You can address the csv file through the Filename (filename) or the FileDescriptor (fd).

import TermTk as ttk

# TableModel from csv filename
tm1 = ttk.TTkTableModelCSV(filename='path/file.csv')

# TableModel from csv FileDescriptor
with open('path/file.csv') as fd:
    tm2 = ttk.TTkTableModelCSV(fd=fd)
Parameters
  • filename (str, optional) – the csv filename, if missing the file descriptor is used instead.

  • fd (io, optional) – the FileDescriptor

columnCount() int

Returns the number of columns of the current moodel.

Returns

int

data(row: int, col: int) None

Returns the data stored for the item referred to by the row/column.

Note: If you do not have a value to return, return None instead of returning 0.

Parameters
  • row (int) – the row position of the data

  • col (int) – the column position of the data

Returns

object

flags(row: int, col: int) ItemFlag

Returns the item flags for the given row,column.

The base class implementation returns a combination of flags that enables the item (ItemIsEnabled) and allows it to be selected (ItemIsSelectable).

Parameters
  • row (int) – the row position od the data

  • col (int) – the column position of the data

Returns

ItemFlag

headerData(num: int, orientation: int)

Returns the data for the given role and section in the header with the specified orientation.

For horizontal headers, the section number corresponds to the column number. Similarly, for vertical headers, the section number corresponds to the row number.

Parameters
  • pos (int) – the position (col or row) of the header

  • orientation (Direction) – the orienttin of the header to be retrieved

Returns

TTkString

index(row: int, col: int) TTkModelIndex

Returns the index of the item in the model specified by the given row, column.

Parameters
  • row (int) – the row position of the index

  • col (int) – the column position of the index

Returns

TTkModelIndex

rowCount() int

Returns the number of rows of the current model.

Returns

int

setData(row: int, col: int, data: object) None

Returns true if successful; otherwise returns false.

The dataChanged() signal should be emitted if the data was successfully set.

The base class implementation returns false. This function and data() must be reimplemented for editable models.

Parameters
  • row (int) – the row position of the data

  • col (int) – the column position of the data

  • data (object) – the data to be set in the (row,col) position of the table

Returns

bool

sort(column: int, order: SortOrder) None

Sorts the model by column in the given order.

Parameters
  • column (int) – The column index to be sorted, if -1 is provided the original unsorted order is used.

  • order (SortOrder) – the sorting order

ttkStringData(row: int, col: int) TTkString

Returns the TTkString reprsents the ddata stored in the row/column.

Parameters
  • row (int) – the row position of the data

  • col (int) – the column position of the data

Returns

TTkString