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.
-
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.
-
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
-
process_events_then
(action: Callable)[source]¶ Decorates a function with a call to first process events.
-
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.
-
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.
-
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.
-
property
predicted_instances
¶ Returns a list of predicted instances.
Order should match the order in which instances were added to scene.
-
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.
-
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
parent – QGraphicsObject 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.
-
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.
-
getPointsBoundingRect
() → PySide2.QtCore.QRectF[source]¶ Returns a rect which contains all the nodes in the skeleton.
-
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.
-
mouseDoubleClickEvent
(event: PySide2.QtGui.QMouseEvent)[source]¶ Custom event handler to emit signal on event.
-
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.
-
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.
-
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) –
-
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 displayplot – 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.
-
property
predicted_instances
¶ Returns list of predicted QtInstance objects in view.
-
property
scene
¶ Returns QGraphicsScene for viewer.
-
property
selectable_instances
¶ Returns list of selectable QtInstance objects in view.
-
showEdges
(show)[source]¶ Show/hide node edges for all instances in viewer.
- Parameters
show – Show if True, hide otherwise.
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.
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.
-
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.
-
get_data
() → dict[source]¶ Get all data (fixed and user-selected) for imported video.
- Returns
Dict with data for this video.
-
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.
-
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.
-
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.
-
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.
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_base – LabeledFrame objects from base that conflicted.
extra_new – LabeledFrame 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
.-
data
(index: PySide2.QtCore.QModelIndex, role=PySide2.QtCore.Qt.ItemDataRole.DisplayRole)[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).
-
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
.-
data
(index: PySide2.QtCore.QModelIndex, role=PySide2.QtCore.Qt.ItemDataRole.DisplayRole)[source]¶ Required by Qt.
-
sleap.gui.shortcuts¶
Gui for keyboard shortcuts.
-
class
sleap.gui.shortcuts.
ShortcutDialog
(*args, **kwargs)[source]¶ Dialog window for reviewing and modifying the keyboard shortcuts.
Makes the form buttons.
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
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).
-
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
-
class
sleap.gui.formbuilder.
ResizingStackedWidget
(*args, **kwargs)[source]¶ QStackedWidget that updates its sizeHint and minimumSizeHint as needed.
-
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()
.
-
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”
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.
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.
-
decrementContiguousMarkedVal
(val)[source]¶ Decrements value within contiguously marked range if possible.
-
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 –
-
incrementContiguousMarkedVal
(val)[source]¶ Increments value within contiguously marked range if possible.
-
mouseDoubleClickEvent
(event)[source]¶ Override method to move handle for mouse double-click.
- Parameters
event –
-
mousePressEvent
(event)[source]¶ Override method to move handle for mouse press/drag.
- Parameters
event –
-
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.
-
releaseSelectionAnchor
(x, y)[source]¶ Finishes selection in response to mouse release.
- Parameters
x – x position of mouse
y – y position of mouse
- Returns
None.
-
resizeEvent
(event=None)[source]¶ Override method to update visual size when necessary.
- Parameters
event –
-
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.
-
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
-
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
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.
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.
-
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.
-
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.
-
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.
-
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.
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.
-
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.
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).
-
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).
-
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]¶
-
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
-
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.
-
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]¶