timApp.plugin.timtable package
Contents
timApp.plugin.timtable package#
Submodules#
timApp.plugin.timtable.row_owner_info module#
timApp.plugin.timtable.timTable module#
- class timApp.plugin.timtable.timTable.RelativeDataBlockValue(row: int, column: int, data: str | dict[str, Any])[source]#
Bases:
object
- timApp.plugin.timtable.timTable.add_row(plug: timApp.plugin.plugin.Plugin, row_id: int)[source]#
Generic function for adding a row.
- Parameters
plug – The plugin.
row_id – The place (index) where the row should be added. -1 can be used for appending rows to the end of the table.
- Returns
The unique ID of the row, or None if it has no ID.
- timApp.plugin.timtable.timTable.apply_datablock_from_entry_list(plug: timApp.plugin.plugin.Plugin, relative_data_block_values: list)[source]#
- timApp.plugin.timtable.timTable.colnum_to_letters(column_index: int) str [source]#
Transforms column index to letter
- Parameters
column_index – ex. 2
- Returns
column index as letter
- timApp.plugin.timtable.timTable.construct_datablock_entry_list_from_yaml(plug: timApp.plugin.plugin.Plugin) list[timApp.plugin.timtable.timTable.RelativeDataBlockValue] [source]#
Parses a relative datablock and returns its data as a list of RelativeDataBlockValue instances.
- Parameters
plug – The plugin instance.
- Returns
A list of RelativeDataBlockValues.
- timApp.plugin.timtable.timTable.convert_export_data()[source]#
Route for getting save JSON from exportdata
- Returns
JSON to save or {} if nothing to save
- timApp.plugin.timtable.timTable.create_datablock(table: dict[str, Any])[source]#
Creates tableDatablock
- Parameters
table –
- Returns
- timApp.plugin.timtable.timTable.create_datablock_from_entry_list(relative_data_block_values: list) dict[str, Any] [source]#
Creates the datablock from a list of RelativeDataBlockValues.
- Parameters
relative_data_block_values – The list of RelativeDataBlockValues.
- Returns
The datablock as a dict.
- timApp.plugin.timtable.timTable.datablock_key_to_indexes(datablock_key: str) tuple[int, int] [source]#
Gets the column and row indexes from a single relative datablock entry.
- Parameters
datablock_key – The entry in the relative datablock.
- Returns
Column and row indexes in a tuple.
- timApp.plugin.timtable.timTable.find_cell(rows: list, row: int, col: int) str [source]#
Gets cell from index place if it exists, otherwise returns an empty string
- Parameters
rows – List of cells
row – Row index
col – Column index
- Returns
Cell from specified index
- timApp.plugin.timtable.timTable.find_cell_from_datablock(cells: dict, row: int, col: int) str | None [source]#
Finds cell from datablock
- Parameters
cells – all cells
row – Row index
col – Column index
- Returns
cell if exists
- timApp.plugin.timtable.timTable.get_column_counts(plug: timApp.plugin.plugin.Plugin, row_len: int) tuple[dict[int, int], list[timApp.plugin.timtable.timTable.RelativeDataBlockValue]] [source]#
Returns the number of columns for each row. Takes both the regular table structure and the datablock into account. :return: A dict with row indexes as keys and respective column counts as values, and also a list of datablock entries.
- timApp.plugin.timtable.timTable.get_plugin_from_paragraph(doc_id, par_id) -> (<class 'timApp.document.docentry.DocEntry'>, <class 'timApp.plugin.plugin.Plugin'>)[source]#
Returns the DocEntry and the plugin instance from a document and paragraph ID.
- Parameters
doc_id – The document ID
par_id – The paragraph ID
- Returns
Tuple of a DocEntry and the plugin instance.
- timApp.plugin.timtable.timTable.is_datablock(yaml: dict[str, Any]) bool [source]#
Checks if tableDataBlock exists
- Parameters
yaml –
- Returns
Boolean indicating the existance of tabledatablock
- timApp.plugin.timtable.timTable.is_in_datainput_mode(plug: timApp.plugin.plugin.Plugin) bool [source]#
Checks whether the table is in data input mode.
- Parameters
plug – The plugin instance.
- Returns
True if the table is in data input mode, otherwise false.
- timApp.plugin.timtable.timTable.is_in_global_append_mode(plug: timApp.plugin.plugin.Plugin) bool [source]#
Checks whether global append mode is enabled. In global append mode even users without edit rights can add rows, but they can only edit the content of rows that they’ve added.
- Parameters
plug – The plugin instance.
- Returns
True if global append mode is enabled, otherwise false.
- timApp.plugin.timtable.timTable.is_review(request)[source]#
Check if request is review
- Parameters
request –
- Returns
- timApp.plugin.timtable.timTable.pop_unique_row_id(plug: timApp.plugin.plugin.Plugin) int [source]#
Returns an unique ID for a new row.
- Parameters
plug – The plugin instance.
- Returns
- timApp.plugin.timtable.timTable.prepare_for_and_call_dumbo(plug: timApp.plugin.plugin.Plugin)[source]#
Prepares the table’s markdown for Dumbo conversion and runs it through Dumbo.
- Parameters
plug – The plugin instance.
- Returns
The conversion result from Dumbo.
- timApp.plugin.timtable.timTable.prepare_for_dumbo(values)[source]#
Prepares the table’s markdown for Dumbo conversion when automd is enabled.
- Parameters
values – The plugin paragraph’s markdown.
- Returns
The table’s markdown, prepared for dumbo conversion.
- timApp.plugin.timtable.timTable.prepare_multi_for_dumbo(timtable_list)[source]#
Prepares multiple TimTables (given in a request) for Dumbo.
- Parameters
timtable_list –
- Returns
- timApp.plugin.timtable.timTable.row_key(s)[source]#
Make a sort key for table cell address. For example
AB3: cat => 0003 AB
E17: dog => 0017 E
A => A
23 => 23
- Parameters
s – string whre key is calculated
- Returns
key for sorting by row numbers
- timApp.plugin.timtable.timTable.save_cell(datablock: dict[str, Any], row: int, col: int, cell_content: str | dict[str, Any])[source]#
Updates datablock with the content and the coordinate of a cell.
- Parameters
datablock –
row – Row index
col – Column index
cell_content – Cell content
- Returns
- timApp.plugin.timtable.timTable.set_cell_style_attribute(doc_id, par_id, cells_to_save)[source]#
Sets a style attribute for a cell.
- Parameters
doc_id – Document ID
par_id – Paragraph ID
cells_to_save – list of cells to save
- Returns
The entire table’s data after the style attribute has been set.
- timApp.plugin.timtable.timTable.set_value_to_table(plug, row_id, col_id, value)[source]#
Set value in the description part of table
- Parameters
plug – plugin to use
row_id – row where to set
col_id – col where to set
value – value to be set
- Returns
nothing
- timApp.plugin.timtable.timTable.tim_table_add_column()[source]#
Adds a new cell into each row on the table. In other words, adds a column into the table. :return: The entire table’s data after the column has been added.
- timApp.plugin.timtable.timTable.tim_table_add_datablock_column()[source]#
Adds a column into the table’s datablock. Doesn’t affect the table’s regular YAML. :return: The entire table’s data after the column has been added.
- timApp.plugin.timtable.timTable.tim_table_add_datablock_row()[source]#
Adds a row into the table’s datablock. Doesn’t affect the table’s regular YAML. :return: The entire table’s data after the row has been added.
- timApp.plugin.timtable.timTable.tim_table_add_multi_cell_value(cells_to_save, d, plug, multi, must_call_dumbo=True)[source]#
- timApp.plugin.timtable.timTable.tim_table_add_row()[source]#
Adds a row into the table. :return: The entire table’s data after the row has been added.
- timApp.plugin.timtable.timTable.tim_table_add_user_specific_row()[source]#
Adds an user-specific row into the table. :return: The entire table’s data after the row has been added.
- timApp.plugin.timtable.timTable.tim_table_get_cell_data()[source]#
Route for getting the content of a cell. :return: The cell content in the specified index.
- timApp.plugin.timtable.timTable.tim_table_get_html(jso, review)[source]#
Returns the HTML of a single TimTable paragraph.
- Parameters
jso –
review –
- Returns
- timApp.plugin.timtable.timTable.tim_table_multihtml()[source]#
Route for getting the HTML of all TimTable plugins in a document. :return:
- timApp.plugin.timtable.timTable.tim_table_multihtml_direct(jsondata)[source]#
Directly callable method for getting the HTML of all TimTable plugins.
- Parameters
jsondata – The data of the plugins.
- Returns
The data of the plugins converted to HTML.
- timApp.plugin.timtable.timTable.tim_table_multimd()[source]#
Handles latex printing. :return: Table as latex.
- timApp.plugin.timtable.timTable.tim_table_remove_column()[source]#
Removes a column from the table. :return: The entire table’s data after the column has been removed.
- timApp.plugin.timtable.timTable.tim_table_remove_row()[source]#
Removes a row from the table. :return: The entire table’s data after the row has been removed.
- timApp.plugin.timtable.timTable.tim_table_save_cell_list()[source]#
Saves cell content :return: The cell content as html
- timApp.plugin.timtable.timTable.tim_table_save_cell_value(cell_content, docid, parid, row, col)[source]#
- timApp.plugin.timtable.timTable.tim_table_save_multi_cell_list()[source]#
Saves cell content :return: The cell content as html
timApp.plugin.timtable.timTableLatex module#
Converts timTable-json into LaTeX.
Visa Naukkarinen
- class timApp.plugin.timtable.timTableLatex.Cell(index: int = -1, content: str = '', colspan: int = 1, rowspan: int = 1, text_color: None | str = 'black', text_color_html: None | bool = False, bg_color: None | str = 'none', bg_color_html: None | bool = False, h_align='l', font_size: float = 12, cell_width='*', cell_height='0', line_space=0, pbox='10cm', font_family='qpl', borders: timApp.plugin.timtable.timTableLatex.CellBorders = <class 'timApp.plugin.timtable.timTableLatex.CellBorders'>: {'left': False, 'right': False, 'top': False, 'bottom': False, 'color_bottom': ('none', False), 'color_top': ('none', False), 'color_left': ('none', False), 'color_right': ('none', False)}, font_weight=None)[source]#
Bases:
object
LaTeX-table cell containing all its attributes.
- class timApp.plugin.timtable.timTableLatex.CellBorders(left=False, right=False, top=False, bottom=False, color_bottom=('none', False), color_top=('none', False), color_left=('none', False), color_right=('none', False))[source]#
Bases:
object
Contains the attributes of a cell’s borders.
- class timApp.plugin.timtable.timTableLatex.HorizontalBorder(row_above: Optional[timApp.plugin.timtable.timTableLatex.Row] = None, row_below: Optional[timApp.plugin.timtable.timTableLatex.Row] = None)[source]#
Bases:
object
Horizontal line between rows.
- exception timApp.plugin.timtable.timTableLatex.IndexConversionError[source]#
Bases:
timApp.plugin.timtable.timTableLatex.TimTableException
Error raised if attempt to convert Excel-type cell coordinate like A3 fails.
- class timApp.plugin.timtable.timTableLatex.Row(index: int, cells: list[timApp.plugin.timtable.timTableLatex.Cell], height: Optional[float] = None)[source]#
Bases:
object
LaTeX-table row.
- add_cell(i: int, cell: timApp.plugin.timtable.timTableLatex.Cell) None [source]#
Adds a cell to index in row and uses the first free index.
- Parameters
i – Row index of the cell to add.
cell – The Cell-object to add to the row.
- Returns
None.
- get_cell(index: int) timApp.plugin.timtable.timTableLatex.Cell | None [source]#
Gives cell with the index number (which may be different from list index).
- Parameters
index – Cell index number in the table.
- Returns
Cell or None, if not found.
- class timApp.plugin.timtable.timTableLatex.Table(rows: list[timApp.plugin.timtable.timTableLatex.Row], width='\\columnwidth', height='!', fit_to_page_width: bool = False)[source]#
Bases:
object
Table with rows, cells in rows, and horizontal borders between rows.
- auto_size_cells() None [source]#
Try to set row heights automatically based on cell content length.
- Returns
None.
- create_hborders() None [source]#
Once all rows have been created, create the borders between them.
- Returns
None.
- get_largest_col_count() int [source]#
Get largest total row colspan in the table. :return: Colspan of the widest row.
- get_largest_content_len() int [source]#
Get largest content length in the table. :return: Content length of the longest cell.
- get_or_create_row(i: int) timApp.plugin.timtable.timTableLatex.Row [source]#
Returns the row in index or creates a new one with said index.
- Parameters
i – Row index.
- Returns
The row with index i, whether it existed or not.
- exception timApp.plugin.timtable.timTableLatex.TableBorderException[source]#
Bases:
timApp.plugin.timtable.timTableLatex.TimTableException
If there’s something wrong with border-related things.
- exception timApp.plugin.timtable.timTableLatex.TimTableException[source]#
Bases:
Exception
Base exception class.
- timApp.plugin.timtable.timTableLatex.add_missing_elements(table_json, datablock)[source]#
Add cells and rows only present in datablock.
- Parameters
table_json – Table data.
datablock – Datablock data.
- Returns
table_json with datablock-only cells added.
- timApp.plugin.timtable.timTableLatex.convert_datablock_index(datablock_index) tuple[int, int] [source]#
A 1 -> 0, 0 ZZ13 -> 51, 12
- Parameters
datablock_index – Index in format “A1”.
- Returns
Integer tuple (cell_index, row_index).
- timApp.plugin.timtable.timTableLatex.convert_table(table_json, draw_html_borders: bool = False) timApp.plugin.timtable.timTableLatex.Table [source]#
Converts TimTable-json into LaTeX-compatible object. Note: for correct functioning all the other modules should use this.
- Parameters
table_json – Table data as json dictionary with ‘rows’, ‘tabledatablock’, etc. at the first level.
:param draw_html_borders Add light gray default borders around cells similarly to HTML-table. :return: Table-object containing the rows and cells in LaTex.
- timApp.plugin.timtable.timTableLatex.copy_cell(cell: timApp.plugin.timtable.timTableLatex.Cell) timApp.plugin.timtable.timTableLatex.Cell [source]#
Properly copies Cell-object and the objects within.
- Parameters
cell – Cell object to copy.
- Returns
Copy with new CellBorders-object pointers.
- timApp.plugin.timtable.timTableLatex.custom_repr(obj) str [source]#
Extended repr that displays all contents of the object.
- Parameters
obj – The object to repr.
- Returns
Full contents of the object and the objects it references.
- timApp.plugin.timtable.timTableLatex.decide_colspan_rowspan(cell_colspan, cell_rowspan, datablock_colspan, datablock_rowspan)[source]#
- timApp.plugin.timtable.timTableLatex.decide_format(format_levels)[source]#
Decides which format to use by taking the latest non-empty one.
- Parameters
format_levels – Table, column, row, cell, datablock.
- Returns
Last non-empty value or None if all are empty.
- timApp.plugin.timtable.timTableLatex.decide_format_size(format_levels)[source]#
Decides which size (column, row, cell, datablock) to use by taking the longest one.
- Parameters
format_levels – Table, column, row, cell, datablock.
- Returns
Largest size.
- timApp.plugin.timtable.timTableLatex.decide_format_tuple(format_levels)[source]#
Goes through a list of formats and returns the last non-empty one. The idea is to stack table, column, row and cell formats and take the topmost format.
- Parameters
format_levels – Table, column, row, cell, datablock.
- Returns
Last non-empty format.
- timApp.plugin.timtable.timTableLatex.estimate_cell_height(cell, width_constraint)[source]#
Gives estimation of cell height with width as constraint.
- Parameters
cell – Cell to estimate.
width_constraint – The width is locked before estimating height.
- Returns
Height of cell.
- timApp.plugin.timtable.timTableLatex.estimate_cell_width(cell)[source]#
Give estimation of cell width based on content and font size.
- Parameters
cell – Cell to estimate.
- Returns
Width of cell.
- timApp.plugin.timtable.timTableLatex.estimate_col_widths(rows)[source]#
Takes the most large set width of the column’s cells, or estimation of their needed content size, if all are automatic.
- Parameters
rows – Table rows.
- Returns
Estimation of column widths.
- timApp.plugin.timtable.timTableLatex.estimate_table_width(self) tuple[float, bool] [source]#
Get total width of the table (i.e. width of longest row). :return: Width.
- timApp.plugin.timtable.timTableLatex.format_color(color: str, html_color: bool) str [source]#
Converts color to LaTeX-format depending on whether it’s html or normal color.
- Parameters
color – Color name or hex-code.
html_color – Whether the color is in hex or not.
- Returns
Just the color name, or HTML-option and hex code.
- timApp.plugin.timtable.timTableLatex.get_border_color(border_data) tuple[str, bool] [source]#
Parses border color from HTML border format.
- Parameters
border_data – HTML border format with line thickness, style, color.
- Returns
Border color as tuple containing color name/code and whether its a hex.
- timApp.plugin.timtable.timTableLatex.get_borders(item, default_borders=<class 'timApp.plugin.timtable.timTableLatex.CellBorders'>: {'left': False, 'right': False, 'top': False, 'bottom': False, 'color_bottom': ('none', False), 'color_top': ('none', False), 'color_left': ('none', False), 'color_right': ('none', False)}) timApp.plugin.timtable.timTableLatex.CellBorders [source]#
Creates a CellBorder object with corresponding border-data.
- Parameters
item – Cell or row data.
default_borders – Borders to be used in case none found.
- Returns
CellBorders object for the item.
- timApp.plugin.timtable.timTableLatex.get_color(item, key: str, default_color=None, default_color_html=None) -> (<class 'str'>, <class 'bool'>)[source]#
Parses color-data into LaTeX-format.
- Parameters
item –
key – Key for color element (color, backgroundColor, etc.).
default_color – Color to use if key not found.
default_color_html – Whether color is in hex or not.
- Returns
Tuple with the color-code / name and whether its in hex or not.
- timApp.plugin.timtable.timTableLatex.get_column_color_list(key, table_data)[source]#
Reads all the columns of the table and makes a list of their color formattings.
- Parameters
key – Key for color type.
table_data – Table JSON.
- Returns
List of column colors.
- timApp.plugin.timtable.timTableLatex.get_column_format_list(table_data, f: Callable[[dict, Any], Any])[source]#
Forms a list of font families from the columns data.
- Parameters
table_data –
f – Function to get the format values from the column data.
- Returns
List of column formats.
- timApp.plugin.timtable.timTableLatex.get_column_span(item)[source]#
Get column span value.
- Parameters
item – Column data.
- Returns
Span.
- timApp.plugin.timtable.timTableLatex.get_column_style_list(table_data, key)[source]#
Forms a list of styles corresponding to the key from the columns data.
- Parameters
table_data – Table JSON.
key – Style key.
- Returns
List of column styles.
- timApp.plugin.timtable.timTableLatex.get_column_width_list(table_data)[source]#
Forms a list of column widths from the columns data.
- Parameters
table_data – Table JSON.
- Returns
List of column widths.
- timApp.plugin.timtable.timTableLatex.get_content(cell_data) str [source]#
Gets content from a cell.
- Parameters
cell_data – Cell JSON.
- Returns
Cell content.
- timApp.plugin.timtable.timTableLatex.get_datablock(table_json)[source]#
Looks for and returns datablock or None, if table has no tabledatablock element.
- Parameters
table_json – Table data as json string.
- Returns
Datablock or None.
- timApp.plugin.timtable.timTableLatex.get_datablock_cell_data(datablock, row: int, cell: int)[source]#
Returns data from datablock index.
- Parameters
datablock – Datablock JSON.
row – Row index.
cell – Cell index.
- Returns
Datablock data for a cell, if it exists.
- timApp.plugin.timtable.timTableLatex.get_font_family(item, default: str | None = 'qpl') str | None [source]#
- Parameters
item – Cell or row data.
default – Font family to use in case none set.
- Returns
Set font family or default.
- timApp.plugin.timtable.timTableLatex.get_font_size(item, default_size)[source]#
Gets text size if set, and uses default otherwise.
- Parameters
item – Cell data item.
default_size – Size to be used if no set font size.
- Returns
Font size or default font size.
- timApp.plugin.timtable.timTableLatex.get_key_value(item, key, default=None)[source]#
Returns a value from dictionary or default if key doesn’t exist.
- Parameters
item – Dictionary (JSON).
default – Value that’s used in case key cannot be found.
key – Key.
- Returns
Value or default.
- timApp.plugin.timtable.timTableLatex.get_size(item, key: str, default=None) str | None [source]#
Parse width or height into LaTeX-supported format.
- Parameters
item – Cell data.
key – Width or heigth.
default – Value to be used if key wasn’t found.
- Returns
Cell width or height.
- timApp.plugin.timtable.timTableLatex.get_span(item, default=None) -> (<class 'int'>, <class 'int'>)[source]#
Parses row and column span of the cell. If not specified, assume it’s 1.
- Parameters
item – Cell data.
default – Default used when not found.
- Returns
Colspan and rowspan in a tuple.
- timApp.plugin.timtable.timTableLatex.get_table_resize(table_data, table_width_estimation, col_count) bool [source]#
Whether table should be resized to fit the page width. If the attribute isn’t set, automatically decide whether to resize.
- Parameters
table_data – Table JSON.
table_width_estimation – Table width and whether it’s an estimation as tuple.
:param col_count Max number of columns (including colspans) in the table. :return: Table scaling true or false.
- timApp.plugin.timtable.timTableLatex.get_table_size(table_data)[source]#
Sets table size attributes and uses default values if not found.
- Parameters
table_data – Table data dictionary.
- Returns
Table width and height as a tuple.
- timApp.plugin.timtable.timTableLatex.get_text_horizontal_align(item, default)[source]#
Parses text horizontal alignment.
- Parameters
item – Table, row or cell data.
default – Value to be used if no set align.
- Returns
Set align or default.
- timApp.plugin.timtable.timTableLatex.int_to_datablock_index(i: int) str [source]#
Converts an index integer to corresponding capital letter(s). For example: 0 -> A, 25 -> Z, 26 -> AA, 27 -> BB.
- Parameters
i – Index starting from 0.
- Returns
The index in capital letter format.
- timApp.plugin.timtable.timTableLatex.is_close(a, b, rel_tol=1e-09, abs_tol=0.0) bool [source]#
Compares floats and returns true if they are almost same. Source: https://stackoverflow.com/questions/5595425/what-is-the-best-way-to-compare-floats-for-almost-equality-in-python
- Parameters
a – Number a.
b – Number b.
rel_tol – Relative tolerance.
abs_tol – Absolute tolerance.
- Returns
True if floats are very close to each other.
- timApp.plugin.timtable.timTableLatex.parse_hex_color(color, default_color=None) str | None [source]#
Removes non-hex characters and checks if result is valid.
- Parameters
color – Color string.
default_color – Color returned in case valid hex can’t be parsed.
- Returns
A hex color code of six characters.