GUI

sleap.gui.app

Main GUI application for labeling, training/inference, and proofreading.

class sleap.gui.app.MainWindow(labels_path: Optional[str] = None, *args, **kwargs)[source]

The SLEAP GUI application.

Each project (Labels dataset) that you have loaded in the GUI will have its own MainWindow object.

labels

The Labels dataset. If None, a new, empty project (i.e., Labels object) will be created.

state

Object that holds GUI state, e.g., current video, frame, whether to show node labels, etc.

closeEvent(event)[source]

Closes application window, prompting for saving as needed.

doubleClickInstance(instance: sleap.instance.Instance, event: PySide2.QtGui.QMouseEvent = None)[source]

Handles when the user has double-clicked an instance.

If prediction, then copy to new user-instance. If already user instance, then add any missing nodes (in case skeleton has been changed after instance was created).

Parameters

instance – The Instance that was double-clicked.

event(e: PySide2.QtCore.QEvent) → bool[source]

Custom event handler.

We use this to ignore events that would clear status bar.

Parameters

e – The event.

Returns

True if we ignore event, otherwise returns whatever the usual event handler would return.

learningFinished(new_count: int)[source]

Called when inference finishes.

loadLabelsObject(labels: sleap.io.dataset.Labels, filename: Optional[str] = None)[source]

Loads a Labels object into the GUI, replacing any currently loaded.

Parameters
  • labels – The Labels object to load.

  • filename – The filename where this file is saved, if any.

Returns

None.

loadProjectFile(filename: Optional[str] = None)[source]

Loads given labels file into GUI.

Parameters

filename – The path to the saved labels dataset. If None, then don’t do anything.

Returns

Return type

None

load_overlays()[source]

Load all standard video overlays.

openKeyRef()[source]

Shows gui for viewing/modifying keyboard shortucts.

plotFrame(*args, **kwargs)[source]

Plots (or replots) current frame.

process_events_then(action: Callable)[source]

Decorates a function with a call to first process events.

setSeekbarHeader(graph_name)[source]

Updates graph shown in seekbar header.

setWindowTitle(value)[source]

Sets window title (if value is not None).

showLearningDialog(mode: str)[source]

Helper function to show learning dialog in given mode.

Parameters
  • mode – A string representing mode for dialog, which could be:

  • "active" (*) –

  • "inference" (*) –

  • "expert" (*) –

Returns

None.

updateSeekbarMarks()[source]

Updates marks on seekbar.

updateStatusMessage(message: Optional[str] = None)[source]

Updates status bar.

updateTrackMenu()[source]

Updates track menu options.

visualizeOutputs()[source]

Gui for adding overlay with live visualization of predictions.

sleap.gui.app.main()[source]

Starts new instance of app.

sleap.gui.video

Module for showing and manipulating skeleton instances within a video.

All interactions should go through QtVideoPlayer.

Example usage:
>>> my_video = Video(...)
>>> my_instance = Instance(...)
>>> vp = QtVideoPlayer(video=my_video)
>>> vp.addInstance(instance=my_instance, color=(r, g, b))
class sleap.gui.video.GraphicsView(state=None, player=None, *args, **kwargs)[source]

Custom QGraphicsView used by QtVideoPlayer.

This contains elements for display of video and event handlers for zoom and selection of instances in view.

Signals:
  • updatedViewer: Emitted after update to view (e.g., zoom).

    Used internally so we know when to update points for each instance.

  • updatedSelection: Emitted after the user has (un)selected an instance.

  • instanceDoubleClicked: Emitted after an instance is double-clicked.

    Passes the Instance that was double-clicked.

  • areaSelected: Emitted after user selects an area when in “area”

    click mode. Passes x0, y0, x1, y1 for selected box coordinates.

  • pointSelected: Emitted after user clicks a point (in “point” click

    mode.) Passes x, y coordinates of point.

  • leftMouseButtonPressed: Emitted by event handler.

  • rightMouseButtonPressed: Emitted by event handler.

  • leftMouseButtonReleased: Emitted by event handler.

  • rightMouseButtonReleased: Emitted by event handler.

  • leftMouseButtonDoubleClicked: Emitted by event handler.

  • rightMouseButtonDoubleClicked: Emitted by event handler.

property all_instances

Returns a list of all QtInstance objects in scene.

Order should match the order in which instances were added to scene.

clear()[source]

Clears the displayed frame from the scene.

clearZoom()[source]

Clear zoom stack. Doesn’t update display.

getSelectionIndex() → Optional[int][source]

Returns the index of the currently selected instance. If no instance selected, returns None.

getSelectionInstance() → Optional[sleap.instance.Instance][source]

Returns the currently selected instance. If no instance selected, returns None.

getTopInstanceAt(scenePos) → Optional[sleap.instance.Instance][source]

Returns topmost instance at position in scene.

hasImage() → bool[source]

Returns whether or not the scene contains an image pixmap.

property instances

Returns a list of instances.

Order should match the order in which instances were added to scene.

instancesBoundingRect(margin: float = 0) → PySide2.QtCore.QRectF[source]

Returns a rect which contains all displayed skeleton instances.

Parameters

margin – Margin for padding the rect.

Returns

The QRectF which contains the skeleton instances.

keyPressEvent(event)[source]

Custom event hander, disables default QGraphicsView behavior.

keyReleaseEvent(event)[source]

Custom event hander, disables default QGraphicsView behavior.

mouseDoubleClickEvent(event: PySide2.QtGui.QMouseEvent)[source]

Custom event handler, clears zoom.

mouseMoveEvent(self, event:PySide2.QtGui.QMouseEvent)[source]
mousePressEvent(event)[source]

Start mouse pan or zoom mode.

mouseReleaseEvent(event)[source]

Stop mouse pan or zoom mode (apply zoom if valid).

property predicted_instances

Returns a list of predicted instances.

Order should match the order in which instances were added to scene.

resizeEvent(event)[source]

Maintain current zoom on resize.

selectInstance(select: Union[sleap.instance.Instance, int])[source]

Select a particular instance in view.

Parameters

select – Either Instance or index of instance in view.

Returns

None

property selectable_instances

Returns a list of instances which user can select.

Order should match the order in which instances were added to scene.

setImage(image: Union[PySide2.QtGui.QImage, PySide2.QtGui.QPixmap])[source]

Set the scene’s current image pixmap to the input QImage or QPixmap.

Parameters

image – The QPixmap or QImage to display.

Raises

RuntimeError – If the input image is not QImage or QPixmap

Returns

None.

updateViewer()[source]

Apply current zoom.

wheelEvent(event)[source]

Custom event handler. Zoom in/out based on scroll wheel change.

zoomToRect(zoom_rect: PySide2.QtCore.QRectF)[source]

Method to zoom scene to a given rectangle.

The rect can either be given relative to the current zoom (this is useful if it’s the rect drawn by user) or it can be given in absolute coordinates for displayed frame.

Parameters

zoom_rect – The QRectF to which we want to zoom.

class sleap.gui.video.LoadImageWorker(*args, **kwargs)[source]

Object to load video frames in background thread.

Requests to load a frame image are sent by calling the request method with the frame idx; the video attribute should already be set to the correct video.

These requests are added to a FILO queue polled by the doProcessing method, called whenever there’s time during the Qt event loop. (It’s also added to the event queue if it hasn’t been called for a while and we get a request, since the timer doesn’t seem to emit events if the user has been holding down the mouse for a while.)

The actual frame loading is wrapped with a mutex lock so that we only load a single frame at a time; this helps us not get a bunch of older frame requests running concurrently.

Once the frame loads, the QImage is sent via the result signal. (Qt handles the cross-thread communication if we use signals.)

class sleap.gui.video.QtEdge(parent: PySide2.QtWidgets.QGraphicsObject, player: sleap.gui.video.QtVideoPlayer, src: sleap.gui.video.QtNode, dst: sleap.gui.video.QtNode, show_non_visible: bool = True, *args, **kwargs)[source]

QGraphicsLineItem to handle display of edge between skeleton instance nodes.

Parameters
  • parentQGraphicsObject which will contain this item.

  • src – The QtNode source node for the edge.

  • dst – The QtNode destination node for the edge.

  • show_non_visible – Whether to show “non-visible” nodes/edges.

angle_to(node: sleap.gui.video.QtNode) → float[source]

Returns the angle from one edge node to the other.

Parameters

node – The node from which we’re measuring the angle.

Returns

Angle (in radians) to the other node.

connected_to(node: sleap.gui.video.QtNode)[source]

Return the other node along the edge.

Parameters

node – One of the edge’s nodes.

Returns

The other node (or None if edge doesn’t have node).

updateEdge(node: sleap.gui.video.QtNode)[source]

Updates the visual display of node.

Parameters

node – The node to update.

Returns

None.

class sleap.gui.video.QtInstance(instance: sleap.instance.Instance = None, player: Optional[sleap.gui.video.QtVideoPlayer] = None, markerRadius=4, show_non_visible=True, *args, **kwargs)[source]

QGraphicsObject for skeleton instances.

This object stores the data for one skeleton instance and handles the events to manipulate the skeleton within a video frame (i.e., moving, rotating, marking nodes).

It should be instantiated with an Instance and added to the relevant QGraphicsScene.

When instantiated, it creates QtNode, QtEdge, and QtNodeLabel items as children of itself.

Parameters
  • instance – The Instance to show.

  • markerRadius – Radius of nodes.

  • show_non_visible – Whether to show “non-visible” nodes/edges.

boundingRect()[source]

Method required Qt to determine bounding rect for item.

getPointsBoundingRect() → PySide2.QtCore.QRectF[source]

Returns a rect which contains all the nodes in the skeleton.

paint(painter, option, widget=None)[source]

Method required by Qt.

property selected

Whether instance is selected.

showEdges(show: bool)[source]

Draws/hides the edges for this skeleton instance.

Parameters

show – Show edges if True, hide them otherwise.

showLabels(show: bool)[source]

Draws/hides the labels for this skeleton instance.

Parameters

show – Show labels if True, hide them otherwise.

updateBox(*args, **kwargs)[source]

Updates the box drawn around a selected skeleton.

This updates both the box attribute stored and the visual box. The box attribute is used to determine whether a click should select this instance.

updatePoints(complete: bool = False, user_change: bool = False)[source]

Updates data and display for all points in skeleton.

This is called any time the skeleton is manipulated as a whole.

Parameters
  • complete – Whether to update all nodes by setting “completed” attribute.

  • user_change – Whether method is called because of change made by user.

Returns

None.

class sleap.gui.video.QtNode(parent: PySide2.QtWidgets.QGraphicsObject, player: sleap.gui.video.QtVideoPlayer, node: sleap.skeleton.Node, point: sleap.instance.Point, radius: float, predicted=False, show_non_visible=True, callbacks=None, *args, **kwargs)[source]

QGraphicsEllipseItem to handle display of skeleton instance node.

Parameters
  • parent – The QtInstance which will contain this item.

  • node – The Node corresponding to this visual node.

  • point – The Point where this node is located. Note that this is a mutable object so we’re able to directly access the very same Point object that’s defined outside our class.

  • radius – Radius of the visual node item.

  • predicted – Whether this point is predicted.

  • show_non_visible – Whether to show points where visible is False.

  • callbacks – List of functions to call after we update to the Point.

calls()[source]

Method to call all callbacks.

mouseDoubleClickEvent(event: PySide2.QtGui.QMouseEvent)[source]

Custom event handler to emit signal on event.

mouseMoveEvent(event)[source]

Custom event handler for mouse move.

mousePressEvent(event)[source]

Custom event handler for mouse press.

mouseReleaseEvent(event)[source]

Custom event handler for mouse release.

updatePoint(user_change: bool = False)[source]

Method to update data for node/edge when node position is manipulated.

Parameters

user_change – Whether this being called because of change by user.

wheelEvent(event)[source]

Custom event handler for mouse scroll wheel.

class sleap.gui.video.QtNodeLabel(node: sleap.skeleton.Node, parent: PySide2.QtWidgets.QGraphicsObject, predicted: bool = False, *args, **kwargs)[source]

QGraphicsTextItem to handle display of node text label.

Parameters
  • node – The QtNode to which this label is attached.

  • parent – The QtInstance which will contain this item.

  • predicted – Whether this is for a predicted point.

adjustPos(*args, **kwargs)[source]

Update the position of the label based on the position of the node.

Parameters

arbitrary arguments so we can connect to various signals. (Accepts) –

adjustStyle()[source]

Update visual display of the label and its node.

boundingRect()[source]

Method required by Qt.

mouseMoveEvent(event)[source]

Pass events along so that clicking label is like clicking node.

mousePressEvent(event)[source]

Pass events along so that clicking label is like clicking node.

mouseReleaseEvent(event)[source]

Pass events along so that clicking label is like clicking node.

paint(*args, **kwargs)[source]

Method required by Qt.

wheelEvent(event)[source]

Pass events along so that clicking label is like clicking node.

class sleap.gui.video.QtTextWithBackground(*args, **kwargs)[source]

Inherits methods/behavior of QGraphicsTextItem, but with background box.

Color of background box is light or dark depending on the text color.

boundingRect()[source]

Method required by Qt.

paint(painter, option, *args, **kwargs)[source]

Method required by Qt.

class sleap.gui.video.QtVideoPlayer(video: sleap.io.video.Video = None, color_manager=None, state=None, context=None, *args, **kwargs)[source]

Main QWidget for displaying video with skeleton instances.

Signals:
  • changedPlot: Emitted whenever the plot is redrawn

video

The Video to display

color_manager

A ColorManager object which determines which color to show the instances.

addInstance(instance, **kwargs)[source]

Add a skeleton instance to the video.

Parameters
  • instance – this can be either a QtInstance or an Instance

  • other named args are passed along if/when creating QtInstance. (Any) –

getVisibleRect()[source]

Returns QRectF with currently visible portion of frame image.

property instances

Returns list of all QtInstance objects in view.

keyPressEvent(event: PySide2.QtGui.QKeyEvent)[source]

Custom event handler, allows navigation and selection within view.

keyReleaseEvent(event: PySide2.QtGui.QKeyEvent)[source]

Custom event handler, tracks when user releases modifier (shift) key.

load_video(video: sleap.io.video.Video, plot=True)[source]

Load video into viewer.

Parameters
  • video – the Video to display

  • plot – If True, plot the video frame. Otherwise, just load the data.

onAreaSelection(callback: Callable)[source]

Starts mode for user to select area, callback called when finished.

Parameters

callback – The function called after user clicks point, should take x0, y0, x1, y1 as arguments.

Returns

None.

onPointSelection(callback: Callable)[source]

Starts mode for user to click point, callback called when finished.

Parameters

callback – The function called after user clicks point, should take x and y as arguments.

Returns

None.

onSequenceSelect(seq_len: int, on_success: Callable, on_each: Optional[Callable] = None, on_failure: Optional[Callable] = None)[source]

Collect a sequence of instances (through user selection).

When the sequence is complete, the on_success callback is called. After each selection in sequence, the on_each callback is called (if given). If the user cancels (by unselecting without new selection), the on_failure callback is called (if given).

Note

If successful, we call >>> on_success(list_of_instances)

Parameters
  • seq_len – Number of instances we want to collect in sequence.

  • on_success – Callback for when user has selected desired number of instances.

  • on_each – Callback after user selects each instance.

  • on_failure – Callback if user cancels process before selecting enough instances.

plot(*args)[source]

Do the actual plotting of the video frame.

property predicted_instances

Returns list of predicted QtInstance objects in view.

reset()[source]

Reset viewer by removing all video data.

property scene

Returns QGraphicsScene for viewer.

property selectable_instances

Returns list of selectable QtInstance objects in view.

setFitZoom(value)[source]

Zooms or unzooms current view to fit all instances.

showEdges(show)[source]

Show/hide node edges for all instances in viewer.

Parameters

show – Show if True, hide otherwise.

showLabels(show)[source]

Show/hide node labels for all instances in viewer.

Parameters

show – Show if True, hide otherwise.

zoomToFit()[source]

Zoom view to fit all instances.

sleap.gui.video.plot_instances(scene, frame_idx, labels, video=None, fixed=True)[source]

Demo function for plotting instances.

sleap.gui.video.video_demo(video=None, labels=None, standalone=False)[source]

Demo function for showing video.

Dialogs

sleap.gui.inference

Module for running training and inference from the main gui application.

class sleap.gui.inference.InferenceDialog(labels_filename: str, labels: sleap.io.dataset.Labels, mode: str = 'expert', *args, **kwargs)[source]

Training/inference dialog.

The dialog can be used in different modes: * simplified training + inference (fewer controls) * expert training + inference (full controls) * inference only

Parameters
  • labels_filename – Path to the dataset where we’ll get training data.

  • labels – The dataset where we’ll get training data and add predictions.

  • mode – String which specified mode (“learning”, “expert”, or “inference”).

property frame_selection

Returns dictionary with frames that user has selected for inference.

on_job_menu_selection(menu_name: str, selected_idx: int, field)[source]

Handles when user selects an item from model/job menu.

If selection is a valid job, then update form fields from job. If selection is “add”, then show the appropriate gui for selecting job.

run()[source]

Run training (or inference) with current dialog settings.

show()[source]

Shows dialog (we hide rather than close to maintain settings).

update_gui()[source]

Updates gui state after user changes to options.

view_datagen()[source]

Shows windows with sample visual data that will be used training.

sleap.gui.inference.has_jobs_to_train(training_jobs: Dict[ModelOutputType, TrainingJob])[source]

Returns whether any of the jobs need to be trained.

sleap.gui.inference.run_gui_inference(labels: sleap.io.dataset.Labels, trained_job_paths: List[str], frames_to_predict: Dict[sleap.io.video.Video, List[int]], inference_params: Dict[str, str], labels_filename: str, gui: bool = True) → int[source]

Run inference on specified frames using models from training_jobs.

Parameters
  • labels – The current labels object; results will be added to this.

  • trained_job_paths – List of paths to TrainingJobs with trained models.

  • frames_to_predict – Dict that gives list of frame indices for each video.

  • inference_params – Parameters to pass to inference.

  • gui – Whether to show gui windows and process gui events.

Returns

Number of new frames added to labels.

sleap.gui.inference.run_gui_training(labels_filename: str, training_jobs: Dict[ModelOutputType, TrainingJob], gui: bool = True, save_viz: bool = False) → Dict[sleap.nn.model.ModelOutputType, str][source]

Run training for each training job.

Parameters
  • labels – Labels object from which we’ll get training data.

  • training_jobs – Dict of the jobs to train.

  • gui – Whether to show gui windows and process gui events.

  • save_viz – Whether to save visualizations from training.

Returns

Dict of paths to trained jobs corresponding with input training jobs.

sleap.gui.inference.run_learning_pipeline(labels_filename: str, labels: sleap.io.dataset.Labels, training_jobs: Dict[ModelOutputType, TrainingJob], inference_params: Dict[str, str], frames_to_predict: Dict[sleap.io.video.Video, List[int]] = None) → int[source]

Run training (as needed) and inference.

Parameters
  • labels_filename – Path to already saved current labels object.

  • labels – The current labels object; results will be added to this.

  • training_jobs – The TrainingJobs with params/hyperparams for training.

  • inference_params – Parameters to pass to inference.

  • frames_to_predict – Dict that gives list of frame indices for each video.

Returns

Number of new frames added to labels.

sleap.gui.importvideos

Interface to handle the UI for importing videos.

Usage:

>>> import_list = ImportVideos().go()

This will show the user a file-selection dialog, and then a second dialog to select the import parameters for each file.

It returns a list with data about each file selected by the user. In particular, we’ll have the name of the file and all of the parameters relevant for that specific type of file. It also includes a reference to the relevant method of Video.

For each item in import_list, we can load the video by calling this method while passing the user-selected params as the named parameters:

>>> vid = item["video_class"](**item["params"])
class sleap.gui.importvideos.ImportItemWidget(file_path: str, import_type: dict, *args, **kwargs)[source]

Widget for selecting parameters with preview when importing video.

Parameters
  • file_path (str) – Full path to selected video file.

  • import_type (dict) – Data about user-selectable import parameters.

boundingRect() → PySide2.QtCore.QRectF[source]

Method required by Qt.

get_data() → dict[source]

Get all data (fixed and user-selected) for imported video.

Returns

Dict with data for this video.

is_enabled()[source]

Am I enabled?

Our UI provides a way to enable/disable this item (file). We only want to import enabled items.

Returns

Am I enabled?

Return type

Boolean

paint(painter, option, widget=None)[source]

Method required by Qt.

update_video(initial: bool = False)[source]

Update preview video using current param values.

Parameters

initial – if True, then get video settings that are used by the Video object when they aren’t specified as params

Returns

None.

class sleap.gui.importvideos.ImportParamDialog(filenames: list, *args, **kwargs)[source]

Dialog for selecting parameters with preview when importing video.

Parameters

filenames (list) – List of files we want to import.

boundingRect() → PySide2.QtCore.QRectF[source]

Method required by Qt.

get_data(import_result=None)[source]

Method to get results from import.

Parameters

import_result (optional) – If specified, we’ll insert data into this.

Returns

List of dicts with data for each (enabled) imported file.

paint(painter, option, widget=None)[source]

Method required by Qt.

class sleap.gui.importvideos.ImportParamWidget(file_path: str, import_type: dict, *args, **kwargs)[source]

Widget for allowing user to select video parameters.

Parameters
  • file_path – file path/name

  • import_type – data about the parameters for this type of video

Note

Object is a widget with the UI for params specific to this video type.

boundingRect() → PySide2.QtCore.QRectF[source]

Method required by Qt.

get_values(only_required=False)[source]

Method to get current user-selected values for import parameters.

Parameters

only_required – Only return the parameters that are required for instantiating Video object

Returns

Dict of param keys/values.

Note

It’s easiest if the return dict matches the arguments we need for the Video object, so we’ll add the file name to the dict even though it’s not a user-selectable param.

make_layout() → PySide2.QtWidgets.QLayout[source]

Builds the layout of widgets for user-selected import parameters.

paint(painter, option, widget=None)[source]

Method required by Qt.

set_values_from_video(video)[source]

Set the form fields using attributes on video.

class sleap.gui.importvideos.ImportVideos[source]

Class to handle video importing UI.

go()[source]

Runs the import UI.

  1. Show file selection dialog.

  2. Show import parameter dialog with widget for each file.

Parameters

None.

Returns

List with dict of the parameters for each file to import.

class sleap.gui.importvideos.VideoPreviewWidget(video: sleap.io.video.Video = None, *args, **kwargs)[source]

Widget to show video preview. Based on Video class.

Parameters

video – the video to show

Returns

None.

Note

This widget is used by ImportItemWidget.

boundingRect() → PySide2.QtCore.QRectF[source]

Method required by Qt.

clear_video()[source]

Clear the video preview.

load_video(video: sleap.io.video.Video, initial_frame=0, plot=True)[source]

Load the video preview and display label text.

paint(painter, option, widget=None)[source]

Method required by Qt.

plot(idx=0)[source]

Show the video preview.

sleap.gui.merge

Gui for merging two labels files with options to resolve conflicts.

class sleap.gui.merge.ConflictTable(base_labels: sleap.io.dataset.Labels, extra_base: List[sleap.instance.LabeledFrame], extra_new: List[sleap.instance.LabeledFrame])[source]

Qt table view for summarizing merge conflicts.

Arguments are passed through to the table view object.

The two lists of LabeledFrame objects should be correlated (idx in one will match idx of the conflicting frame in other).

Parameters
  • base_labels – The base dataset.

  • extra_baseLabeledFrame objects from base that conflicted.

  • extra_newLabeledFrame objects from new dataset that conflicts.

class sleap.gui.merge.ConflictTableModel(base_labels: sleap.io.dataset.Labels, extra_base: List[sleap.instance.LabeledFrame], extra_new: List[sleap.instance.LabeledFrame])[source]

Qt table model for summarizing merge conflicts.

See ConflictTable.

columnCount(*args)[source]

Required by Qt.

data(index: PySide2.QtCore.QModelIndex, role=PySide2.QtCore.Qt.ItemDataRole.DisplayRole)[source]

Required by Qt.

headerData(section, orientation: <class 'PySide2.QtCore.Qt.Orientation'>, role=PySide2.QtCore.Qt.ItemDataRole.DisplayRole)[source]

Required by Qt.

rowCount(*args)[source]

Required by Qt.

class sleap.gui.merge.MergeDialog(base_labels: sleap.io.dataset.Labels, new_labels: sleap.io.dataset.Labels, *args, **kwargs)[source]

Dialog window for complex merging of two SLEAP datasets.

This will immediately merge any labeled frames that can be cleanly merged, show summary of merge and prompt user about how to handle merge conflict, and then finish merge (resolving conflicts as the user requested).

finishMerge()[source]

Finishes merge process, possibly resolving conflicts.

This is connected to accepted signal.

Parameters

None.

Raises

ValueError – If no valid merge method was selected in dialog.

Returns

None.

class sleap.gui.merge.MergeTable(merged, *args, **kwargs)[source]

Qt table view for summarizing cleanly merged frames.

Arguments are passed through to the table view object.

Parameters

merged – The frames that were cleanly merged. See Labels.complex_merge_between() for details.

class sleap.gui.merge.MergeTableModel(merged: Dict[Video, Dict[int, List[Instance]]])[source]

Qt table model for summarizing merge conflicts.

See MergeTable.

columnCount(*args)[source]

Required by Qt.

data(index: PySide2.QtCore.QModelIndex, role=PySide2.QtCore.Qt.ItemDataRole.DisplayRole)[source]

Required by Qt.

headerData(section, orientation: <class 'PySide2.QtCore.Qt.Orientation'>, role=PySide2.QtCore.Qt.ItemDataRole.DisplayRole)[source]

Required by Qt.

rowCount(*args)[source]

Required by Qt.

sleap.gui.merge.show_instance_type_counts(instance_list: List[Instance]) → str[source]

Returns string of instance counts to show in table.

Parameters

instance_list – The list of instances to count.

Returns

String with numbers of user/predicted instances.

sleap.gui.shortcuts

Gui for keyboard shortcuts.

class sleap.gui.shortcuts.ShortcutDialog(*args, **kwargs)[source]

Dialog window for reviewing and modifying the keyboard shortcuts.

accept()[source]

Triggered when form is accepted; saves the shortcuts.

load_shortcuts()[source]

Loads shortcuts object.

make_buttons_widget() → PySide2.QtWidgets.QDialogButtonBox[source]

Makes the form buttons.

make_column_widget(shortcuts: List) → PySide2.QtWidgets.QWidget[source]

Makes a single column of shortcut fields.

Parameters

shortcuts – The list of shortcuts to include in this column.

Returns

The widget.

make_form()[source]

Creates the form with fields for all shortcuts.

make_shortcuts_widget() → PySide2.QtWidgets.QWidget[source]

Makes the widget will fields for all shortcuts.

class sleap.gui.shortcuts.Shortcuts[source]

Class for accessing keyboard shortcuts.

Shortcuts are saved in sleap/config/shortcuts.yaml

When instantiated, this reads in the shortcuts from the file.

save()[source]

Saves all shortcuts to shortcut file.

sleap.gui.suggestions

Module for generating lists of suggested frames (for labeling or reviewing).

class sleap.gui.suggestions.SuggestionFrame(video: sleap.io.video.Video, frame_idx: int, group: Optional[int] = None)[source]

Object for storing a single suggested frame item.

class sleap.gui.suggestions.VideoFrameSuggestions[source]

Class for generating lists of suggested frames.

Implements various algorithms as methods: * sample (either random or evenly spaced sample frames from each video) * image features (raw images/brisk -> pca -> k-means) * prediction_score (frames with number of instances below specified score)

Each of algorithm method should accept labels; other parameters will be passed from the params dict given to suggest().

classmethod basic_sample_suggestion_method(labels, per_video: int = 20, sampling_method: str = 'random', **kwargs)[source]

Method to generate suggestions by taking strides through video.

classmethod image_feature_based_method(labels, per_video, sample_method, scale, merge_video_features, feature_type, pca_components, n_clusters, per_cluster, **kwargs)[source]

Method to generate suggestions based on image features.

This is a wrapper for feature_suggestion_pipeline implemented in sleap.info.feature_suggestions.

classmethod prediction_score(labels: Labels, score_limit, instance_limit, **kwargs)[source]

Method to generate suggestions for proofreading frames with low score.

classmethod suggest(params: dict, labels: Labels = None) → List[sleap.gui.suggestions.SuggestionFrame][source]

This is the main entry point for generating lists of suggested frames.

Parameters
  • params – A dictionary with all params to control how we generate suggestions, minimally this will have a “method” key with the name of one of the class methods.

  • labels – A Labels object for which we are generating suggestions.

Returns

List of SuggestionFrame objects.

classmethod velocity(labels: Labels, node: Union[int, str], threshold: float, **kwargs)[source]

Finds frames for proofreading with high node velocity.

sleap.gui.training_editor

Module for viewing and modifying training profiles.

class sleap.gui.training_editor.TrainingEditor(profile_filename: Optional[str] = None, saved_files: list = [], skeleton: Optional[Skeleton] = None, *args, **kwargs)[source]

Dialog for viewing and modifying training profiles.

Parameters
  • profile_filename – Path to saved training profile to view.

  • saved_files – When user saved profile, it’s path is added to this list (which will be updated in code that created TrainingEditor).

property profile_filename

Returns path to currently loaded training profile.

Other Widgets

sleap.gui.formbuilder

Module for creating a form from a yaml file.

Example:

>>> widget = YamlFormWidget(yaml_file="example.yaml")
>>> widget.mainAction.connect(my_function)

my_function will get called with form data when user clicks the main button (main button has type “button” and default “main action”)

class sleap.gui.formbuilder.FieldComboWidget(result_as_idx: bool = False, add_blank_option: bool = False, *args, **kwargs)[source]

A custom ComboBox widget with method to easily add set of options.

Parameters
  • result_as_idx – If True, then set/get for value will use idx of option rather than string.

  • add_blank_option – If True, then blank (“”) option will be added at beginning of list (which will return “” as val instead of idx if result_as_idx is True).

set_options(options_list: List[str], select_item: Optional[str] = None)[source]

Sets list of menu options.

Parameters
  • options_list – List of items (strings) to show in menu.

  • select_item – Item to select initially.

Returns

None.

class sleap.gui.formbuilder.FormBuilderLayout(items_to_create, field_options_lists=None, *args, **kwargs)[source]

Custom QFormLayout which populates itself from list of form fields.

Parameters

items_to_create – list which gets passed to get_form_data() (see there for details about format)

build_form(items_to_create: List[Dict[str, Any]])[source]

Adds widgets to form layout for each item in items_to_create.

Parameters

items_to_create

list of dictionaries with keys

  • name: used as key when we return form data as dict

  • label: string to show in form

  • type: supports double, int, bool, list, button, stack

  • default: default value for form field

  • [options]: comma separated list of options, used for list or stack field-types

  • for stack, array of dicts w/ form data for each stack page

A “stack” has a dropdown menu that determines which stack page to show.

Returns

None.

find_field(field_name: str)[source]

Finds form fields by name.

Parameters

field_name – Name of field to find.

Returns

List of field widgets, including any in active stacked widget.

get_form_data() → dict[source]

Gets all user-editable data from the widgets in the form layout.

Returns

value for each user-editable widget in layout

Return type

Dict with key

static get_widget_value(widget: PySide2.QtWidgets.QWidget) → Any[source]

Returns value of form field.

This determines the method appropriate for the type of widget.

Parameters

widget – The widget for which to return value.

Returns

value (can be bool, numeric, string, or None)

set_field_options(field_name: str, options_list: List[str])[source]

Sets custom list of options for specified field.

set_form_data(data: dict)[source]

Set specified user-editable data.

Parameters

data – dictionary of datay, key should match field name

static set_widget_value(widget: PySide2.QtWidgets.QWidget, val)[source]

Set value for specific widget.

update_field_options()[source]

Updates options list for every field with custom list.

class sleap.gui.formbuilder.ResizingStackedWidget(*args, **kwargs)[source]

QStackedWidget that updates its sizeHint and minimumSizeHint as needed.

minimumSizeHint()[source]

Qt method.

sizeHint()[source]

Qt method.

class sleap.gui.formbuilder.StackBuilderWidget(stack_data, field_options_lists=None, *args, **kwargs)[source]

A custom widget that shows different subforms depending on menu selection.

Parameters

stack_data – Dictionary for field from items_to_create. The “options” key will give the list of options to show in menu. Each of the “options” will also be the key of a dictionary within stack_data that has the same structure as the dictionary passed to FormBuilderLayout.build_form().

find_field(*args, **kwargs)[source]

Returns result of find_field method on currently shown subform.

get_data()[source]

Returns value from currently shown subform.

setValue(value)[source]

Sets value of menu.

set_field_options(*args, **kwargs)[source]

Calls set_field_options for every subform.

switch_to_idx(idx)[source]

Switch currently shown widget from stack.

value()[source]

Returns value of menu.

class sleap.gui.formbuilder.YamlFormWidget(yaml_file, which_form: str = 'main', field_options_lists: Optional[Dict[str, list]] = None, *args, **kwargs)[source]

Custom QWidget which creates form based on yaml file.

Parameters
  • yaml_file – filename

  • which_form (optional) – key to form in yaml file, default “main”

property buttons

Returns a list of buttons in form (so we can connect to handlers).

property fields

widget} fields in form.

Type

Return a dict of {name

classmethod from_name(form_name: str, *args, **kwargs) → sleap.gui.formbuilder.YamlFormWidget[source]

Instantiate class from the short name of form (e.g., “suggestions”).

Short name is converted to path to yaml file, and then class is instantiated using this path.

Parameters
  • form_name – Short name of form, corresponds to name of yaml file.

  • args – Positional args passed to class initializer.

  • kwargs – Named args passed to class initializer.

Returns

Instance of YamlFormWidget class.

get_form_data()[source]

Returns dict of form data.

set_field_options(field_name: str, options_list: List[str], **kwargs)[source]

Sets option list for specified field.

set_form_data(data)[source]

Set data for form from dict.

trigger_main_action()[source]

Emit mainAction signal with form data.

sleap.gui.slider

Drop-in replacement for QSlider with additional features.

class sleap.gui.slider.SliderMark(type: str, val: float, end_val: float = None, row: int = None, track: Track = None, color: Union[tuple, str] = 'black')[source]

Class to hold data for an individual mark on the slider.

type

Type of the mark, options are: * “simple” (single value) * “filled” (single value) * “open” (single value) * “predicted” (single value) * “track” (range of values) * “tick” (single value) * “tick_column” (single value)

val

Beginning of mark range

end_val

End of mark range (for “track” marks)

row

The row that the mark goes in; used for tracks.

color

Color of mark, can be string or (r, g, b) tuple.

filled

Whether the mark is shown filled (solid color).

property QColor

Returns color of mark as QColor.

property color

Returns color of mark.

property filled

Returns whether mark is filled or open.

class sleap.gui.slider.VideoSlider(orientation=-1, min=0, max=1, val=0, marks=None, color_manager: Optional[sleap.gui.color.ColorManager] = None, *args, **kwargs)[source]

Drop-in replacement for QSlider with additional features.

Parameters
  • orientation – ignored (here for compatibility with QSlider)

  • min – initial minimum value

  • max – initial maximum value

  • val – initial value

  • marks – initial set of values to mark on slider this can be either * list of values to mark * list of (track, value)-tuples to mark

  • color_manager – A ColorManager which determines the color to use for “track”-type marks

Signals:

mousePressed: triggered on Qt event mouseMoved: triggered on Qt event mouseReleased: triggered on Qt event keyPress: triggered on Qt event keyReleased: triggered on Qt event valueChanged: triggered when value of slider changes selectionChanged: triggered when slider range selection changes heightUpdated: triggered when the height of slider changes

addMark(new_mark: sleap.gui.slider.SliderMark, update: bool = True)[source]

Adds a marked value to the slider.

Parameters
  • new_mark – value to mark

  • update – Whether to redraw slider with new mark.

Returns

None.

boundingRect() → PySide2.QtCore.QRectF[source]

Method required by Qt.

clearHeader()[source]

Remove header graph from slider.

clearMarks()[source]

Clears all marked values for slider.

clearSelection()[source]

Clears selection endpoints.

contiguousSelectionMarksAroundVal(val)[source]

Selects contiguously marked frames around value.

decrementContiguousMarkedVal(val)[source]

Decrements value within contiguously marked range if possible.

drawHeader()[source]

Draw the header graph.

enabled()[source]

Returns whether slider is enabled.

endSelection(val, update: bool = False)[source]

Add final selection endpoint.

Called during or after the user is dragging to select range.

Parameters
  • val – value of endpoint

  • update

getMarks(type: str = '')[source]

Returns list of marks.

getSelection()[source]

Returns start and end value of current selection endpoints.

hasSelection() → bool[source]

Returns True if a clip is selected, False otherwise.

incrementContiguousMarkedVal(val)[source]

Increments value within contiguously marked range if possible.

isMarkedVal(val)[source]

Returns whether value has mark.

keyPressEvent(event)[source]

Catch event and emit signal so something else can handle event.

keyReleaseEvent(event)[source]

Catch event and emit signal so something else can handle event.

mouseDoubleClickEvent(event)[source]

Override method to move handle for mouse double-click.

Parameters

event

mouseMoveEvent(event)[source]

Override method to emid mouseMoved signal on drag.

mousePressEvent(event)[source]

Override method to move handle for mouse press/drag.

Parameters

event

mouseReleaseEvent(event)[source]

Override method to emit mouseReleased signal on release.

moveHandle(x, y)[source]

Move handle in response to mouse position.

Emits valueChanged signal if value of slider changed.

Parameters
  • x – x position of mouse

  • y – y position of mouse

moveSelectionAnchor(x: float, y: float)[source]

Moves selection anchor in response to mouse position.

Parameters
  • x – x position of mouse

  • y – y position of mouse

Returns

None.

paint(*args, **kwargs)[source]

Method required by Qt.

releaseSelectionAnchor(x, y)[source]

Finishes selection in response to mouse release.

Parameters
  • x – x position of mouse

  • y – y position of mouse

Returns

None.

removeMark(mark: sleap.gui.slider.SliderMark)[source]

Removes an individual mark.

resizeEvent(event=None)[source]

Override method to update visual size when necessary.

Parameters

event

setEnabled(val: float) → float[source]

Set whether the slider is enabled.

setHeaderSeries(series: Optional[Dict[int, float]] = None)[source]

Show header graph with specified series.

Parameters

series – {frame number: series value} dict.

Returns

None.

setMarks(marks: Iterable[Union[sleap.gui.slider.SliderMark, int]])[source]

Sets all marked values for the slider.

Parameters

marks – iterable with all values to mark

Returns

None.

setMaximum(max: float) → float[source]

Sets maximum value for slider.

setMinimum(min: float) → float[source]

Sets minimum value for slider.

setSelection(start_val, end_val)[source]

Selects clip from start_val to end_val.

setTickMarks()[source]

Resets which tick marks to show.

setTracks(track_rows)[source]

Set the number of tracks to show in slider.

Parameters

track_rows – the number of tracks to show

setTracksFromLabels(labels: Labels, video: Video)[source]

Set slider marks using track information from Labels object.

Note that this is the only method coupled to a SLEAP object.

Parameters
  • labels – the dataset with tracks and labeled frames

  • video – the video for which to show marks

Returns

None

setValue(val: float) → float[source]

Sets value of slider.

property slider_visible_value_range

Value range that’s visible given current size and zoom.

startSelection(val)[source]

Adds initial selection endpoint.

Called when user starts dragging to select range in slider.

Parameters

val – value of endpoint

updateHeight()[source]

Update the height of the slider.

updatePos()[source]

Update the visual x position of handle and slider annotations.

updateSelectionBoxPositions(box_object, a: float, b: float)[source]

Update box item on slider.

Parameters
  • box_object – The box to update

  • a – one endpoint value

  • b – other endpoint value

Returns

None.

value() → float[source]

Returns value of slider.

sleap.gui.multicheck

Module for Qt Widget to show multiple checkboxes for selecting.

Example

>>> mc = MultiCheckWidget(count=5, selected=[0,1],title="My Items")
>>> mc.selectionChanged.connect(window.plot)
>>> window.layout.addWidget(mc)
class sleap.gui.multicheck.MultiCheckWidget(*args, count: int, title: Optional[str] = '', selected: Optional[List] = None, default: Optional[bool] = False, **kwargs)[source]

Qt Widget to show multiple checkboxes for a sequence of numbers.

Parameters
  • count – The number of checkboxes to show.

  • title – Display title for group of checkboxes.

  • selected – List of checkbox numbers to initially check.

  • default – Whether to default boxes as checked.

boundingRect() → PySide2.QtCore.QRectF[source]

Method required by Qt.

getSelected() → list[source]

Method to get list of the checked checkboxes.

Returns

list of checked checkboxes

paint(painter, option, widget=None)[source]

Method required by Qt.

setSelected(selected: list)[source]

Method to set some checkboxes as checked.

Parameters

selected – List of checkboxes to check.

Returns

None

sleap.gui.overlays

sleap.gui.overlays.instance

Module with overlay for showing instances.

class sleap.gui.overlays.instance.InstanceOverlay(labels: sleap.io.dataset.Labels = None, player: sleap.gui.video.QtVideoPlayer = None, state: sleap.gui.state.GuiState = None)[source]

Class for adding instances as overlays on video frames.

labels

The Labels dataset from which to get overlay data.

player

The video player in which to show overlay.

state

Object used to communicate with application.

add_to_scene(video, frame_idx)[source]

Adds overlay for frame to player scene.

sleap.gui.overlays.tracks

Module that handles track-related overlays (including track color).

class sleap.gui.overlays.tracks.TrackListOverlay(labels: sleap.io.dataset.Labels = None, player: QtVideoPlayer = None)[source]

Class to show track number and names in overlay.

add_to_scene(video: sleap.io.video.Video, frame_idx: int)[source]

Adds track list as overlay on video.

property visible

Gets or set whether overlay is visible.

class sleap.gui.overlays.tracks.TrackTrailOverlay(labels: sleap.io.dataset.Labels = None, player: QtVideoPlayer = None, trail_length: int = 0, show: bool = True)[source]

Class to show track trails as overlay on video frame.

Initialize this object with both its data source and its visual output scene, and it handles both extracting the relevant data for a given frame and plotting it in the output.

labels

The Labels dataset from which to get overlay data.

player

The video player in which to show overlay.

trail_length

The maximum number of frames to include in trail.

Usage:

After class is instantiated, call add_to_scene(frame_idx)() to plot the trails in scene.

add_to_scene(video: sleap.io.video.Video, frame_idx: int)[source]

Plot the trail on a given frame.

Parameters
  • video – current video

  • frame_idx – index of the frame to which the trail is attached

get_frame_selection(video: sleap.io.video.Video, frame_idx: int)[source]

Return LabeledFrame objects to include in trail for specified frame.

get_track_trails(frame_selection: Iterable[LabeledFrame])[source]

Get data needed to draw track trail.

Parameters

frame_selection – an iterable with the LabeledFrame objects to include in trail.

Returns

Dictionary keyed by track, value is list of lists of (x, y) tuples

i.e., for every node in instance, we get a list of positions

get_tracks_in_frame(video: sleap.io.video.Video, frame_idx: int, include_trails: bool = False) → List[sleap.instance.Track][source]

Returns list of tracks that have instance in specified frame.

Parameters
  • video – Video for which we want tracks.

  • frame_idx – Frame index for which we want tracks.

  • include_trails – Whether to include tracks which aren’t in current frame but would be included in trail (i.e., previous frames within trail_length).

Returns

List of tracks.

static map_to_qt_path(point_list)[source]

Converts a list of (x, y)-tuples to a QPainterPath.

sleap.gui.overlays.anchors

sleap.gui.overlays.base

Base class for overlays.

sleap.gui.overlays.confmaps

Module for showing confidence maps as an overlay within a QtVideoPlayer.

Example

>>> cm = ConfMapsPlot(conf_data.get_frame(0))
>>> window.view.scene.addItem(cm)
class sleap.gui.overlays.confmaps.ConfMapPlot(confmap: numpy.array = None, color=[255, 255, 255], *args, **kwargs)[source]

QGraphicsPixmapItem object for drawing single channel of confidence map.

Parameters
  • confmap (numpy.array) – (h, w) array of one confidence map channel.

  • color (list) – optional (r, g, b) array for channel color.

Returns

None.

Note

In most cases this should only be called by ConfMapsPlot.

get_conf_image() → PySide2.QtGui.QImage[source]

Converts array data stored in object to QImage.

Returns

QImage.

class sleap.gui.overlays.confmaps.ConfMapsPlot(frame: numpy.array = None, show=None, show_box=True, *args, **kwargs)[source]

QGraphicsObject to display multiple confidence maps in a QGraphicsView.

Parameters
  • frame (numpy.array) – Data for one frame of confidence map data. Shape of array should be (channels, height, width).

  • show (list, optional) – List of channels to show. If None, show all channels.

  • show_box (bool, optional) – Draw bounding box around confidence maps.

Returns

None.

When initialized, creates one child ConfMapPlot item for each channel.

boundingRect() → PySide2.QtCore.QRectF[source]

Method required by Qt.

paint(painter, option, widget=None)[source]

Method required by Qt.

class sleap.gui.overlays.confmaps.ConfmapOverlay(data: Sequence = None, player: sleap.gui.video.QtVideoPlayer = None, overlay_class: PySide2.QtWidgets.QGraphicsObject = None)[source]

Overlay to show confidence maps.

classmethod from_model(filename, video, **kwargs)[source]

Create object with live predictions from model as datasource.

sleap.gui.overlays.confmaps.demo_confmaps(confmaps, video, standalone=False, callback=None)[source]

Demo function.

sleap.gui.overlays.confmaps.show_confmaps_from_h5(filename, input_format='channels_last', standalone=False)[source]

Demo function.

sleap.gui.overlays.pafs

class sleap.gui.overlays.pafs.MultiQuiverPlot(frame: numpy.array = None, show: list = None, decimation: int = 2, scale: float = 1.0, *args, **kwargs)[source]

QtWidgets.QGraphicsObject to display multiple quiver plots in a QtWidgets.QGraphicsView.

Parameters
  • frame (numpy.array) – Data for one frame of quiver plot data. Shape of array should be (channels, height, width).

  • show (list, optional) – List of channels to show. If None, show all channels.

  • decimation (int, optional) – Decimation factor. If 1, show every arrow.

Returns

None.

Note

Each channel corresponds to two (h, w) arrays: x and y for the vector.

When initialized, creates one child QuiverPlot item for each channel.

boundingRect() → PySide2.QtCore.QRectF[source]

Method required by Qt.

paint(painter, option, widget=None)[source]

Method required by Qt.

class sleap.gui.overlays.pafs.QuiverPlot(field_x: numpy.array = None, field_y: numpy.array = None, color=[255, 255, 255], decimation=1, scale=1, *args, **kwargs)[source]

QtWidgets.QGraphicsObject for drawing single quiver plot.

Parameters
  • field_x (numpy.array) – (h, w) array of x component of vectors.

  • field_y (numpy.array) – (h, w) array of y component of vectors.

  • color (list, optional) – Arrow color. Format as (r, g, b) array.

  • decimation (int, optional) – Decimation factor. If 1, show every arrow.

Returns

None.

boundingRect() → PySide2.QtCore.QRectF[source]

Method called by Qt in order to determine whether object is in visible frame.

paint(painter, option, widget=None)[source]

Method called by Qt to draw object.

sleap.gui.dataviews

Data table widgets and view models used in GUI app.

class sleap.gui.dataviews.GenericTableModel(items: Optional[list] = None, properties: Optional[List[str]] = None, context: Optional[sleap.gui.commands.CommandContext] = None)[source]

Generic table model to show a list of properties for some items.

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).

can_set(item, key)[source]

Virtual method, returns whether table cell is editable.

columnCount(parent=None)[source]

Overrides Qt method, returns number of columns (attributes).

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.

get_from_idx(index: PySide2.QtCore.QModelIndex)[source]

Gets item from QModelIndex.

get_item_color(item: Any, key: str)[source]

Virtual method, returns color for given item.

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).

rowCount(parent=None)[source]

Overrides Qt method, returns number of rows (items).

setData(index: PySide2.QtCore.QModelIndex, value: str, role=PySide2.QtCore.Qt.ItemDataRole.EditRole)[source]

Overrides Qt method, dispatch for settable properties.

set_item(item, key, value)[source]

Virtual method, used to set value for item in table cell.

sort(column_idx: int, order: <class 'PySide2.QtCore.Qt.SortOrder'> = PySide2.QtCore.Qt.SortOrder.AscendingOrder)[source]

Sorts table by given column and order.

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]
activateSelected(*args)[source]

Activates item selected in table.

selectionChanged(new, old)[source]

Custom event handler.

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_frameLabeledFrame to show

  • labelsLabels datasource

can_set(item, key)[source]

Virtual method, returns whether table cell is editable.

get_item_color(item: Any, key: str)[source]

Virtual method, returns color for given item.

object_to_items(labeled_frame: sleap.instance.LabeledFrame)[source]

Virtual method, convert object to list of items to show in rows.

set_item(item, key, value)[source]

Virtual method, used to set value for item in table cell.

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.

get_item_color(item: Any, key: str)[source]

Virtual method, returns color for given item.

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.

columnCount(parent)[source]

Overrides Qt method, returns number of columns (1).

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).

rowCount(parent)[source]

Overrides Qt method, returns number of rows.

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]
can_set(item, key)[source]

Virtual method, returns whether table cell is editable.

get_item_color(item: Any, key: str)[source]

Virtual method, returns color for given item.

object_to_items(skeleton: sleap.skeleton.Skeleton)[source]

Converts given skeleton to list of nodes to show in table.

set_item(item, key, value)[source]

Virtual method, used to set value for item in table cell.

class sleap.gui.dataviews.SuggestionsTableModel(items: Optional[list] = None, properties: Optional[List[str]] = None, context: Optional[sleap.gui.commands.CommandContext] = None)[source]
sort(column_idx: int, order: <class 'PySide2.QtCore.Qt.SortOrder'>)[source]

Sorts table by given column and order.

class sleap.gui.dataviews.VideosTableModel(items: Optional[list] = None, properties: Optional[List[str]] = None, context: Optional[sleap.gui.commands.CommandContext] = None)[source]