class Table: (source)
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 |
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 |
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 |
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 |
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 |
Sets the separator below the current line. |
Instance Variable | colwidth |
Undocumented |
Instance Variable | current |
Undocumented |
Instance Variable | current |
Undocumented |
Instance Variable | lines |
Undocumented |
Instance Variable | measured |
Undocumented |
Instance Variable | separator |
Undocumented |
Property | cells |
Undocumented |
Method | _ensure |
Undocumented |
Method | _ensure |
Undocumented |
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:Cell | Undocumented |
Add a row to the table, to use with ``add_cell()``. It is not needed to call ``add_row()`` before the first ``add_cell()``.