tardis.visualization.widgets.util module

Utility classes and functions for widgets.

class tardis.visualization.widgets.util.TableSummaryLabel(target_table, table_col_widths, label_key, label_value)[source]

Bases: object

Label like widget to show summary of a qgrid table widget.

Also handles aligning the label with the table columns exactly like a summary row.

Initialize a TableSummaryLabel for a table widget.

Parameters:
target_tableqgrid.QgridWidget

Table widget whose summary label it is

table_col_widthslist

A list containing width of each column of table in order (including the index as 1st column). The width values must be proportions of 100 i.e. they must sum to 100

label_keystr

Brief description of what label summarizes about table

label_valueint

Initial summary value of the table to be shown in label

Notes

TableSummaryLabel can only be created for a table with two columns (including index as 1st column) as of now

update_and_resize(value)[source]

Update the label value and resize it as per the size of target table.

Resizing is done in such a way so as to match the width of components of label with columns of target table, making it look like another row. This method should be called whenever there is any update in data or layout of target table.

Parameters:
valueint

Value to be shown in label

Notes

The width resizing operation is highly dependent on qgrid tables’ layout. So it may not remain precise if there happens any CSS change in upcoming versions of qgrid.

class tardis.visualization.widgets.util.Timer(timeout, callback)[source]

Bases: object

Timer to implement debouncing using an asynchronous loop.

Notes

This class is reproduced from ipywidgets documentation, for more information please see https://ipywidgets.readthedocs.io/en/latest/examples/Widget%20Events.html#debounce

Initialize the Timer with delay time and delayed function.

Parameters:
timeoutfloat
callbackfunction
cancel()[source]
start()[source]
tardis.visualization.widgets.util.create_table_widget(data, col_widths, table_options=None, changeable_col=None)[source]

Create table widget object which supports interaction and updating the data.

Parameters:
datapandas.DataFrame

Data you want to display in table widget

col_widthslist

A list containing width of each column of data in order (including the index as 1st column). The width values must be proportions of 100 i.e. they must sum to 100.

table_optionsdict, optional

A dictionary to specify options to use when creating interactive table widget (same as :grid_options: of qgrid, specified in Notes section of their API documentation <https://qgrid.readthedocs.io/en/latest/#qgrid.show_grid>_). Invalid keys will have no effect and valid keys will override or add to the options used by this function.

changeable_coldict, optional

A dictionary to specify the information about column which will change its name when data in generated table widget updates. It must have two keys - index to specify index of changeable column in dataframe data as an integer, and other_names to specify all possible names changeable column will get as a list of strings. Default value None indicates that there is no changable column.

Returns:
qgrid.QgridWidget

Table widget object

tardis.visualization.widgets.util.debounce(wait)[source]
Decorator that will postpone a function’s execution until after

wait seconds have elapsed since the last time it was invoked.

Parameters:
waitfloat
Returns:
function

Notes

This decorator is reproduced from ipywidgets documentation, for more information please see https://ipywidgets.readthedocs.io/en/latest/examples/Widget%20Events.html#debounce