napari_track_edit.data_views.views.table.custom_table_widget

Classes

TrackTableModel

Lazy table model backing the tracks table.

NoSelectionHighlightDelegate

Prevents Qt from painting the default selection background,

CustomTableWidget

ColoredTableWidget

Customized table widget with colored rows based on label colors in a napari Labels layer

Module Contents

class napari_track_edit.data_views.views.table.custom_table_widget.TrackTableModel(parent=None, decimals: int = 3)

Bases: qtpy.QtCore.QAbstractTableModel

Lazy table model backing the tracks table.

Holds the data as columns of numpy arrays (one row per node) and serves values/colors on demand, so the view only ever realizes the handful of rows currently visible. This keeps memory and populate-time O(visible rows) regardless of the total node count (a QTableWidget would instead create one QTableWidgetItem per cell, which blows up memory and freezes the UI for large datasets).

_table: dict[str, numpy.ndarray]
_columns: list[str] = []
_nrows = 0
_decimals = 3
_bg: list[qtpy.QtGui.QColor] = []
_fg: list[qtpy.QtGui.QColor] = []
set_table(table: dict[str, numpy.ndarray], colormap: napari_track_edit.data_views.colormap.TrackColormap) → None

Replace the table contents and precompute per-row colors.

rowCount(parent=None) → int
columnCount(parent=None) → int
headerData(section, orientation, role=Qt.DisplayRole)
_format(value) → str
data(index: qtpy.QtCore.QModelIndex, role=Qt.DisplayRole)
flags(index)
class napari_track_edit.data_views.views.table.custom_table_widget.NoSelectionHighlightDelegate

Bases: qtpy.QtWidgets.QStyledItemDelegate

Prevents Qt from painting the default selection background, preserving each row’s custom background color, and draws a cyan border instead.

paint(painter, option, index)
class napari_track_edit.data_views.views.table.custom_table_widget.CustomTableWidget(*args, **kwargs)

Bases: qtpy.QtWidgets.QTableView

_drag_start_row = None
mousePressEvent(event: qtpy.QtGui.QMouseEvent)

Handle mouse click events and check modifiers for different behaviors: - Plain click: single selection, toggle if already selected - Shift: append to selection. - Ctrl/CMD: center node, should not affect selection. - Alt/Option: take over this node’s tracklet id, should not affect selection. - Side buttons (back/forward): navigate selection history.

mouseMoveEvent(event: qtpy.QtGui.QMouseEvent)

Record mouse drag events to select a range. In combination with shift, it is possible to select multiple ranges.

mouseReleaseEvent(event: qtpy.QtGui.QMouseEvent)
keyPressEvent(event: qtpy.QtGui.QKeyEvent) → None

Handle key press events for common tracksviewer actions.

class napari_track_edit.data_views.views.table.custom_table_widget.ColoredTableWidget(viewer: napari.Viewer)

Bases: qtpy.QtWidgets.QWidget

Customized table widget with colored rows based on label colors in a napari Labels layer

tracks_viewer
_table
_id_to_row: dict[int, int]
ascending = False
_syncing = False
_table_widget
_model
cleanup() → None

Stop following the TracksViewer.

Called by MenuManager when the dock is destroyed, so we can stop listening to TracksViewer update signals to rebuild the table.

update_data(**kwargs) → None

Update the displayed data based on the tracks_df on TracksViewer

_update_selected() → None

Select the rows belonging to the nodes that are in the selection list of the TracksViewer

_select_rows(rows: list[int]) → None

Replace current table selection with given rows.

Parameters:

rows (list[int]) – list of indices to be selected.

_on_selection_changed(*args) → None

Update the node selection list on TracksViewer based on the rows selected in the table.

center_node(index: int) → None

Call TracksViewer to center Viewer on the node of current index

Parameters:

index (int) – the index in the table corresponding to the to be centered node.

pick_track_id(index: int) → None

Call TracksViewer to adopt the tracklet id of the node of current index.

The node itself is not selected and the time point is not changed, so this is the table’s equivalent of ALT/OPTION + click in the tree view and the layers.

Parameters:

index (int) – the index in the table corresponding to the node whose tracklet id should become the current one.

scroll_to_node(node: int) → None

Identify the index of the node that was selected, and scroll to that index.

Parameters:

node (int) – the node to scroll to.

scroll_to_row(index: int) → None

Scroll to make sure the row is in view

Parameters:

index (int) – the index to scroll to

_find_row(**conditions) → int | None

Find the first row matching the given conditions (e.g. label=12, time_point=5) Returns: row index or None

set_data(df: pandas.DataFrame, columns_to_display: list[str] | None = None) → None

Set the content of the table from a dataframe.

Parameters:
  • df (pd.DataFrame) – dataframe holding the tree widget data, one row per node.

  • columns_to_display (list[str] | None) – optional list of column headers to filter on (should correspond to the tracks features). Column ‘node_id’ should always be included.

_sort_table(column_index: int) → None

Sorts the table in ascending or descending order

Parameters:

column_index (int) – The index of the clicked column header