sleap.gui.dataviews¶
Data table widgets and view models used in GUI app.
Typically you’ll need to subclass GenericTableModel
for your data
(unless your data is already a list of dictionaries with keys matching
the columns of the table you want), but you can use GenericTableView
as is. For example:
videos_table = GenericTableView(
state=self.state,
row_name="video",
is_activatable=True,
model=VideosTableModel(items=self.labels.videos, context=self.commands),
)
-
class
sleap.gui.dataviews.
GenericTableModel
(items: Optional[list] = None, properties: Optional[List[str]] = None, context: Optional[sleap.gui.commands.CommandContext] = None)[source]¶ Generic Qt table model to show a list of properties for some items.
- Typically this will be used as base class. Subclasses can implement methods:
- object_to_items: allows conversion from a single object to a list of
items which correspond to rows of table. for example, a table which shows skeleton nodes could implement this method and return the list of nodes for skeleton.
- item_to_data: if each item isn’t already a dictionary with keys for
columns of table (i.e., properties attribute) and values to show in table, then use this method to convert each item to such a dict.
Note that if you need to convert a single object to a list of dictionaries, you can implement both steps in object_to_items (and use the default implementation of item_to_data which doesn’t do any conversion), or you can implement this in two steps using the two methods. It doesn’t make much difference which you do.
For editable table, you must implement can_set and set_item methods.
Usually it’s simplest to override properties in the subclass, rather than passing as an init arg.
- Parameters
properties – The list of property names (table columns).
items – The list of items with said properties (rows).
context – A command context (required for editable items).
-
data
(index: PySide2.QtCore.QModelIndex, role=PySide2.QtCore.Qt.ItemDataRole.DisplayRole)[source]¶ Overrides Qt method, returns data to show in table.
-
flags
(index: PySide2.QtCore.QModelIndex)[source]¶ Overrides Qt method, returns whether item is selectable etc.
-
headerData
(idx: int, orientation: <class 'PySide2.QtCore.Qt.Orientation'>, role=PySide2.QtCore.Qt.ItemDataRole.DisplayRole)[source]¶ Overrides Qt method, returns column (attribute) names.
-
property
items
¶ Gets or sets list of items to show in table.
-
object_to_items
(item_list)[source]¶ Virtual method, convert object to list of items to show in rows.
-
property
original_items
¶ Gets the original items (rather than the dictionary we build from it).
-
setData
(index: PySide2.QtCore.QModelIndex, value: str, role=PySide2.QtCore.Qt.ItemDataRole.EditRole)[source]¶ Overrides Qt method, dispatch for settable properties.
-
sort
(column_idx: int, order: <class 'PySide2.QtCore.Qt.SortOrder'> = PySide2.QtCore.Qt.SortOrder.AscendingOrder)[source]¶ Sorts table by given column and order.
Correctly sorts numeric string (i.e., “123.45”) numerically rather than alphabetically. Has logic for correctly sorting video frames by video then frame index.
-
class
sleap.gui.dataviews.
GenericTableView
(model: PySide2.QtCore.QAbstractTableModel, state: sleap.gui.state.GuiState = None, row_name: Optional[str] = None, name_prefix: Optional[str] = None, is_sortable: bool = False, is_activatable: bool = False)[source]¶ Qt table view for use with GenericTableModel (and subclasses).
Uses the
GuiState
object to keep track of which row/item is selected. If the row_name attribute is “foo”, then a “foo_selected” state will be item corresponding to the currently selected row in table (and the table will select the row if this state is updated by something else). When is_activatable is True, then a “foo” state will also be set to the item when a row is activated–typically by being double-clicked. This state can then be used to trigger something else outside the table.Note that by default “selected_” is used for the state key, e.g., “selected_foo”, but you can set the name_prefix attribute/init arg if for some reason you need this to be different. For instance, the table of instances in the GUI sets this to “” so that the row for an instance is automatically selected when state[“instance”] is set outside the table.
-
activateSelected
(*args)[source]¶ Activates item currently selected in table.
“Activate” means that the relevant
GuiState
state variable is set to the currently selected item.
-
getSelectedRowItem
() → Any[source]¶ Returns item corresponding to currently selected row.
Note that if the table model converts items to dictionaries (using item_to_data method), then returned item will be the original item, not the converted dict.
-
-
class
sleap.gui.dataviews.
LabeledFrameTableModel
(items: Optional[list] = None, properties: Optional[List[str]] = None, context: Optional[sleap.gui.commands.CommandContext] = None)[source]¶ Table model for listing instances in labeled frame.
Allows editing track names.
- Parameters
labeled_frame – LabeledFrame to show
labels – Labels datasource
-
object_to_items
(labeled_frame: sleap.instance.LabeledFrame)[source]¶ Virtual method, convert object to list of items to show in rows.
-
class
sleap.gui.dataviews.
SkeletonEdgesTableModel
(items: Optional[list] = None, properties: Optional[List[str]] = None, context: Optional[sleap.gui.commands.CommandContext] = None)[source]¶ Table model for skeleton edges.
-
object_to_items
(skeleton: sleap.skeleton.Skeleton)[source]¶ Virtual method, convert object to list of items to show in rows.
-
-
class
sleap.gui.dataviews.
SkeletonNodeModel
(skeleton: sleap.skeleton.Skeleton, src_node: Callable = None)[source]¶ String list model for source/destination nodes of edges.
- Parameters
skeleton – The skeleton for which to list nodes.
src_node – If given, then we assume that this model is being used for edge destination node. Otherwise, we assume that this model is being used for an edge source node. If given, then this should be function that will return the selected edge source node.
-
data
(index: PySide2.QtCore.QModelIndex, role=PySide2.QtCore.Qt.ItemDataRole.DisplayRole)[source]¶ Overrides Qt method, returns data for given row.
-
flags
(index: PySide2.QtCore.QModelIndex)[source]¶ Overrides Qt method, returns flags (editable etc).
-
property
skeleton
¶ Gets or sets current skeleton.
-
class
sleap.gui.dataviews.
SkeletonNodesTableModel
(items: Optional[list] = None, properties: Optional[List[str]] = None, context: Optional[sleap.gui.commands.CommandContext] = None)[source]¶ -
-
object_to_items
(skeleton: sleap.skeleton.Skeleton)[source]¶ Converts given skeleton to list of nodes to show in table.
-
-
class
sleap.gui.dataviews.
SuggestionsTableModel
(items: Optional[list] = None, properties: Optional[List[str]] = None, context: Optional[sleap.gui.commands.CommandContext] = None)[source]¶
-
class
sleap.gui.dataviews.
VideosTableModel
(items: Optional[list] = None, properties: Optional[List[str]] = None, context: Optional[sleap.gui.commands.CommandContext] = None)[source]¶