class Table:
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:
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 | _ensure_has_column |
Undocumented |
Method | _ensure_has_line |
Undocumented |
Method | add_cell |
No summary |
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 |
Undocumented
Parameters | |
pos:Tuple[ | Undocumented |
Returns | |
Cell | Undocumented |
Undocumented
Parameters | |
pos:Tuple[ | Undocumented |
cell:Cell | Undocumented |
Parameters | |
cell:Cell | Undocumented |
Parameters | |
cell:Cell | Undocumented |
source:List[ | Undocumented |
Returns | |
int | Undocumented |
Parameters | |
line:List[ | Undocumented |
Returns | |
int | Undocumented |