spinetoolbox.widgets.custom_qtableview

Custom QTableView classes that support copy-paste and the like.

Module Contents

Classes

CopyPasteTableView

Custom QTableView class with copy and paste methods.

AutoFilterCopyPasteTableView

Custom QTableView class with autofilter functionality.

IndexedParameterValueTableViewBase

Custom QTableView base class with copy and paste methods for indexed parameter values.

TimeSeriesFixedResolutionTableView

A QTableView for fixed resolution time series table.

IndexedValueTableView

A QTableView class with for variable resolution time series and time patterns.

ArrayTableView

Custom QTableView with copy and paste methods for single column tables.

MapTableView

Custom QTableView with copy and paste methods for map tables.

Functions

_range(selection)

Returns the top left and bottom right corners of selection.

_could_be_time_stamp(s)

Evaluates if given string could be a time stamp.

system_lc_numeric()

Attributes

_

_NOT_TIME_STAMP

spinetoolbox.widgets.custom_qtableview._[source]
class spinetoolbox.widgets.custom_qtableview.CopyPasteTableView(parent=None)[source]

Bases: PySide6.QtWidgets.QTableView

Custom QTableView class with copy and paste methods.

property copy_action[source]
property paste_action[source]
init_copy_and_paste_actions()[source]

Initializes copy and paste actions and connects relevant signals.

set_external_copy_and_paste_actions(copy_action, paste_action)[source]

Sets the view to use external copy and paste actions.

Note that this doesn’t connect the actions’ trigger signals; the owner of the actions is responsible for handling them.

Parameters
  • copy_action (QAction) – copy action

  • paste_action (QAction) – paste action

delete_content(_=False)[source]

Deletes content from editable indexes in current selection.

can_copy()[source]
copy(_=False)[source]

Copies current selection to clipboard in excel format.

can_paste()[source]
paste(_=False)[source]

Paste data from clipboard.

static _read_pasted_text(text)[source]

Parses a tab separated CSV text table.

Parameters

text (str) – a CSV formatted table

Returns

a list of rows

Return type

list

paste_on_selection()[source]

Pastes clipboard data on selection, but not beyond. If data is smaller than selection, repeat data to fit selection.

paste_normal()[source]

Pastes clipboard data, overwriting cells if needed.

set_column_converter_for_pasting(header, converter)[source]
_converters()[source]
class spinetoolbox.widgets.custom_qtableview.AutoFilterCopyPasteTableView(parent)[source]

Bases: CopyPasteTableView

Custom QTableView class with autofilter functionality.

Parameters

parent (QObject) –

setModel(model)[source]

Disconnects the sectionPressed signal which seems to be connected by the super method. Otherwise pressing the header just selects the column.

Parameters

model (QAbstractItemModel) –

_trigger_filter_menu(_)[source]

Shows current column’s auto filter menu.

show_auto_filter_menu(logical_index)[source]

Called when user clicks on a horizontal section header. Shows/hides the auto filter widget.

Parameters

logical_index (int) – header section index

class spinetoolbox.widgets.custom_qtableview.IndexedParameterValueTableViewBase(parent=None)[source]

Bases: CopyPasteTableView

Custom QTableView base class with copy and paste methods for indexed parameter values.

copy(_=False)[source]

Copies current selection to clipboard in CSV format.

Returns

True if data was copied on the clipboard, False otherwise

Return type

bool

abstract static _read_pasted_text(text)[source]

Reads CSV formatted table.

abstract paste(_=False)[source]

Pastes data from clipboard to selection.

class spinetoolbox.widgets.custom_qtableview.TimeSeriesFixedResolutionTableView(parent=None)[source]

Bases: IndexedParameterValueTableViewBase

A QTableView for fixed resolution time series table.

paste(_=True)[source]

Pastes data from clipboard.

static _read_pasted_text(text)[source]

Parses the given CSV table. Parsing is locale aware.

Parameters

text (str) – a CSV table containing numbers

Returns

A list of floats

Return type

list of float

_paste_to_values_column(values, first_row, paste_length)[source]

Pastes data to the Values column.

Parameters
  • values (list) – a list of float values to paste

  • first_row (int) – index of the first row where to paste

  • paste_length (int) – length of the paste selection (can be different from len(values))

Returns

A tuple (list(pasted indexes), list(pasted values))

Return type

tuple

class spinetoolbox.widgets.custom_qtableview.IndexedValueTableView(parent=None)[source]

Bases: IndexedParameterValueTableViewBase

A QTableView class with for variable resolution time series and time patterns.

paste(_=False)[source]

Pastes data from clipboard.

_paste_two_columns(data_indexes, data_values, first_row, paste_length)[source]

Pastes data indexes and values.

Parameters
  • data_indexes (list) – a list of data indexes (time stamps/durations)

  • data_values (list) – a list of data values

  • first_row (int) – first row index

  • paste_length (int) – selection length for pasting

Returns

a tuple (modified model indexes, modified model values)

Return type

tuple

_paste_single_column(values, first_row, first_column, paste_length)[source]

Pastes a single column of data.

Parameters
  • values (list) – a list of data to paste (data indexes or values)

  • first_row (int) – first row index

  • paste_length (int) – selection length for pasting

Returns

a tuple (modified model indexes, modified model values)

Return type

tuple

static _read_pasted_text(text)[source]

Parses a given CSV table.

Parameters

text (str) – a CSV table

Returns

a tuple (data indexes, data values)

Return type

tuple

class spinetoolbox.widgets.custom_qtableview.ArrayTableView(parent=None)[source]

Bases: IndexedParameterValueTableViewBase

Custom QTableView with copy and paste methods for single column tables.

copy(_=False)[source]

Copies current selection to clipboard in CSV format.

Returns

True if data was copied on the clipboard, False otherwise

Return type

bool

paste(_=False)[source]

Pastes data from clipboard.

static _read_pasted_text(text)[source]

Reads the first column of given CSV table.

Parameters

text (str) – a CSV table

Returns

data column

Return type

list of str

class spinetoolbox.widgets.custom_qtableview.MapTableView(parent=None)[source]

Bases: CopyPasteTableView

Custom QTableView with copy and paste methods for map tables.

copy(_=False)[source]

Copies current selection to clipboard in Excel compatible CSV format.

Returns

True if data was copied on the clipboard, False otherwise

Return type

bool

delete_content(_=False)[source]

Deletes content in current selection.

paste(_=False)[source]

Pastes data from clipboard.

Returns

True if data was pasted successfully, False otherwise

Return type

bool

static _read_pasted_text(text)[source]

Parses a given CSV table.

Parameters

text (str) – a CSV table

Returns

a list of table rows

Return type

list of list

spinetoolbox.widgets.custom_qtableview._range(selection)[source]

Returns the top left and bottom right corners of selection.

Parameters

selection (QItemSelection) – a list of selected QItemSelection objects

Returns

a tuple (top row, bottom row, left column, right column)

Return type

tuple of ints

spinetoolbox.widgets.custom_qtableview._NOT_TIME_STAMP[source]
spinetoolbox.widgets.custom_qtableview._could_be_time_stamp(s)[source]

Evaluates if given string could be a time stamp.

This is to deal with special cases that are not intended as time stamps but could end up as one by the very greedy DateTime constructor.

Parameters

s (str) – string to evaluate

Returns

True if s could be a time stamp, False otherwise

Return type

bool

spinetoolbox.widgets.custom_qtableview.system_lc_numeric()[source]