class documentation

Represents a table, handling cells that can span multiple lines or rows, like:: +-----------+-----+ | AAA | BBB | +-----+-----+ | | | XXX | | | +-----+-----+ | DDD | CCC | +-----+-----------+ This class can be used in two ways, either: - With absolute positions: call ``table[line, col] = Cell(...)``, this overwrites any existing cell(s) at these positions. - With relative positions: call the ``add_row()`` and ``add_cell(Cell(...))`` as needed. Cells spanning multiple rows or multiple columns (having a colspan or rowspan greater than one) are automatically referenced by all the table cells they cover. This is a useful representation as we can simply check ``if self[x, y] is self[x, y+1]`` to recognize a rowspan. Colwidth is not automatically computed, it has to be given, either at construction time, or during the table construction. Example usage:: table = Table([6, 6]) table.add_cell(Cell("foo")) table.add_cell(Cell("bar")) table.set_separator() table.add_row() table.add_cell(Cell("FOO")) table.add_cell(Cell("BAR")) print(table) +--------+--------+ | foo | bar | |========|========| | FOO | BAR | +--------+--------+

Method __getitem__ Undocumented
Method __init__ Undocumented
Method __repr__ Undocumented
Method __setitem__ Undocumented
Method __str__ Undocumented
Method add_cell Add a cell to the current line, to use with ``add_row()``. To add a cell spanning multiple lines or rows, simply set the ``cell.colspan`` or ``cell.rowspan`` BEFORE inserting it into the table.
Method add_row Add a row to the table, to use with ``add_cell()``. It is not needed to call ``add_row()`` before the first ``add_cell()``.
Method cell_width Give the cell width, according to the given source (either ``self.colwidth`` or ``self.measured_widths``). This takes into account cells spanning multiple columns.
Method physical_lines_for_line For a given line, compute the number of physical lines it spans due to text wrapping.
Method rewrap Call ``cell.wrap()`` on all cells, and measure each column width after wrapping (result written in ``self.measured_widths``).
Method set_separator Sets the separator below the current line.
Instance Variable colwidth Undocumented
Instance Variable current_col Undocumented
Instance Variable current_line Undocumented
Instance Variable lines Undocumented
Instance Variable measured_widths Undocumented
Instance Variable separator Undocumented
Property cells Undocumented
Method _ensure_has_column Undocumented
Method _ensure_has_line Undocumented
def __getitem__(self, pos): (source)

Undocumented

Parameters
pos:tuple[int, int]Undocumented
Returns
CellUndocumented
def __init__(self, colwidth=None): (source)

Undocumented

Parameters
colwidth:list[int]Undocumented
def __repr__(self): (source)

Undocumented

Returns
strUndocumented
def __setitem__(self, pos, cell): (source)

Undocumented

Parameters
pos:tuple[int, int]Undocumented
cell:CellUndocumented
def __str__(self): (source)

Undocumented

Returns
strUndocumented
def add_cell(self, cell): (source)

Add a cell to the current line, to use with ``add_row()``. To add a cell spanning multiple lines or rows, simply set the ``cell.colspan`` or ``cell.rowspan`` BEFORE inserting it into the table.

Parameters
cell:CellUndocumented
def add_row(self): (source)

Add a row to the table, to use with ``add_cell()``. It is not needed to call ``add_row()`` before the first ``add_cell()``.

def cell_width(self, cell, source): (source)

Give the cell width, according to the given source (either ``self.colwidth`` or ``self.measured_widths``). This takes into account cells spanning multiple columns.

Parameters
cell:CellUndocumented
source:list[int]Undocumented
Returns
intUndocumented
def physical_lines_for_line(self, line): (source)

For a given line, compute the number of physical lines it spans due to text wrapping.

Parameters
line:list[Cell]Undocumented
Returns
intUndocumented
def rewrap(self): (source)

Call ``cell.wrap()`` on all cells, and measure each column width after wrapping (result written in ``self.measured_widths``).

def set_separator(self): (source)

Sets the separator below the current line.

colwidth: list[int] = (source)

Undocumented

current_col: int = (source)

Undocumented

current_line: int = (source)

Undocumented

Undocumented

measured_widths = (source)

Undocumented

separator = (source)

Undocumented

def _ensure_has_column(self, col): (source)

Undocumented

Parameters
col:intUndocumented
def _ensure_has_line(self, line): (source)

Undocumented

Parameters
line:intUndocumented