tablate.Grid#
- class tablate.Grid(columns, name=None, frame_divider=None, background=None, background_padding=None, multiline=None, max_lines=None, column_divider=None, column_padding=None, text_style=None, text_align=None, text_color=None, html_px_multiplier=None, html_styles=None, html_default_colors=None, container_border=None, container_padding=None, container_width=None, html_container_styles=None)[source]#
Create a TablateItem grid frame (single row of multiple columns) to Tablate instance.
- Parameters:
columns (
List[Union[str,GridColumnInput]]) – Either a list of contents (str, int, float) for columns or a list of column dicts containing contents and styles for columns. [required]name (
Optional[str]) – Frame name (to prevent duplicate entries). [default: None]frame_divider (
Optional[Literal['none','blank','thin','thick','double']]) – Dividing line at the bottom of the frame. [default: ‘thick’]background (
Optional[Literal['white','grey','red','green','yellow','blue','magenta','cyan','dark_red','dark_green','dark_yellow','dark_blue','dark_magenta','dark_cyan','dark_grey','black']]) – Background color for the grig frame. [default: None]background_padding (
Optional[int]) – Additional padding applied to text if background color set (ASCII only). [default: 1]multiline (
Optional[bool]) – Whether the text may wrap to multiple lines. [default: True]max_lines (
Optional[int]) – Maximum number of lines to which the text may wrap. [default: None]column_divider (
Optional[Literal['blank','thin','thick','double']]) – Dividing line between columns. [default: ‘thin’]column_padding (
Optional[int]) – Text padding within each column. [default: 1]text_style (
Optional[Literal['normal','bold','underlined','bold_underlined']]) – Text style for grid frame. [default: ‘normal’]text_align (
Optional[Literal['left','center','right']]) – Text alignment for grid frame. [default: ‘left’]text_color (
Optional[Literal['white','grey','red','green','yellow','blue','magenta','cyan','dark_red','dark_green','dark_yellow','dark_blue','dark_magenta','dark_cyan','dark_grey','black']]) – Text color for grid frame. [default: ‘None’]html_px_multiplier (
Optional[int]) – Multiplier applied to HTML px properties. [default: 1]html_styles (
Optional[HtmlStylesInput]) – HTML specific styles for grid frame. [default: { “html_frame_styles”: {“html_frame_divider_style”: “thick”, “html_frame_divider_weight: 1, “html_frame_divider_color”: ‘black’, “html_multiline”: True (False for Table frames), “html_max_lines”: None, “html_background”: None }, “html_column_styles”: {“html_column_divider_style”: “thin”, “html_column_divider_weight”: 1, “html_column_divider_color”: “black”, “html_padding”: “6px”} “html_text_styles”: {“html_text_style”: ‘normal’, “html_text_align”: ‘left’, “html_text_color”: None, “html_text_size”: 16 } }]container_border (
Optional[Literal['blank','thin','thick','double']]) – outer border style for the Tablate container instance. [default: ‘thick’]container_padding (
Optional[int]) – outer padding (in Unicode character width) for the Tablate container instance. [default: 1]container_width (
Optional[int]) – outer width (in Unicode character width) for the Tablate container instance. [default: 120 or terminal width]html_container_styles (
Optional[HtmlContainerStylesInput]) – style dictionary for HTML specific styles for Tablate container instance. [default: None]
- apply(function, raise_merge_error=True)#
Iterates over frame items and calls the passed function for on each iteration. Optionally, if the functions returns a valid frame options dict or global options dicts, these will be set to the internal store. If there is an error, trying to set the return objects, the .apply() method will break and reset the internal stores.
Note
As a rule of thumb, the return objects should have the same form as the third (frame options) and forth (global options) arguments passed to the .apply() method.
- Parameters:
function (
Callable[[str,Literal['text','grid','table'],dict,dict],Tuple[dict,dict]]) – A function called for each frame element. The function accepts four arguments: the frame type, the frame name, the frame options and the global options. The function may return a tuple containing the frame options and the global options. Tablate will attempt to apply the return values, if set, to its internal frame store and the global options store.raise_merge_error (
bool) – If set to True, the apply function will raise an
- apply_style(selector, css, sub_selector=None)#
Applies custom CSS styling to the Tablate container instance. CSS stylings are scoped to the specific Tablate container instance.
- Parameters:
selector (
str) – The HTML classnames within the Tablate container instance.css (
str) – The CSS style to be set (for instance: background-color: #FFFFFF).sub_selector (
Optional[str]) – An additional selector appended immediately after the main selector block.
- property name#
The name of the frame.
- Type:
Returns
- print()#
Prints an ASCII rendering of the Tablate container instance.
- Return type:
None
- rename(new_name)#
Renames the frame. :type new_name:
str:param new_name: The new name set on the frame.
- to_dict()#
Returns: A Pandas compatible dict.
- to_html()#
Generates an HTML rendering of the Tablate container instance.
Returns: An HTML rendering of the Tablate container instance.
- Return type:
str
- to_string()#
Generates an ASCII rendering of the Tablate container instance.
Returns: An ASCII rendering of the Tablate container instance.
- Return type:
str