sleap.gui.commands

Module for gui command context and commands objects.

Each open project (i.e., MainWindow) will have its own CommandContext. The context enables commands to access and modify the GuiState and Labels, as well as potentially maintaining a command history (so we can add support for undo!). See sleap.gui.app for how the context is created and used.

Every command will have both a method in CommandContext (this is what should be used to trigger the command, e.g., connected to the menu action) and a class which inherits from AppCommand (or a more specialized class such as NavCommand, GoIteratorCommand, or EditCommand). Note that this code relies on inheritance, so some care and attention is required.

A typical command will override the ask and do_action methods. If the command updates something which affects the GUI, it should override the topic attribute (this then gets passed back to the update_callback from the context. If a command doesn’t require any input from the user, then it doesn’t need to override the ask method.

If it’s not possible to separate the GUI “ask” and the non-GUI “do” code, then instead of ask and do_action you should add an ask_and_do method (for instance, DeleteDialogCommand and MergeProject show dialogues which handle both the GUI and the action). Ideally we’d endorse separation of “ask” and “do” for all commands (this is important if we’re going to implement undo)– for now it’s at least easy to see where this separation is violated.

class sleap.gui.commands.AddInstance[source]
classmethod do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

class sleap.gui.commands.AddMissingInstanceNodes[source]
classmethod do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

static get_rect_center_xy(rect: PySide2.QtCore.QRectF)[source]

Returns x, y at center of rect.

static get_xy_in_rect(rect: PySide2.QtCore.QRectF)[source]

Returns random x, y coordinates within given rect.

class sleap.gui.commands.AddTrack[source]
static do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

class sleap.gui.commands.AddUserInstancesFromPredictions[source]
classmethod do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

class sleap.gui.commands.AddVideo[source]
static ask(context: sleap.gui.commands.CommandContext, params: dict) → bool[source]

Shows gui for adding video to project.

static do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

class sleap.gui.commands.AppCommand[source]

Base class for specific commands.

Note that this is not an abstract base class. For specific commands, you should override ask and/or do_action methods, or add an ask_and_do method. In many cases you’ll want to override the topics and does_edits attributes. That said, these are not virtual methods/attributes and have are implemented in the base class with default behaviors (i.e., doing nothing).

You should not override execute or do_with_signal.

topics

List of UpdateTopic items. Override this to indicate what should be updated after command is executed.

does_edits

Whether command will modify data that could be saved.

static ask(context: sleap.gui.commands.CommandContext, params: dict) → bool[source]

Method for information gathering.

Returns

Whether to perform action. By default returns True, but this is where we should return False if we prompt user for confirmation and they abort.

static do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

classmethod do_with_signal(context: sleap.gui.commands.CommandContext, params: dict)[source]

Wrapper to perform action and notify/track changes.

Don’t override this method!

execute(context: sleap.gui.commands.CommandContext, params: dict = None)[source]

Entry point for running command.

This calls internal methods to gather information required for execution, perform the action, and notify about changes.

Ideally, any information gathering should be performed in the ask method, and be added to the params dictionary which then gets passed to do_action. The ask method should not modify state.

(This will make it easier to add support for undo, using an undo_action which will be given the same params dictionary.)

If it’s not possible to easily separate information gathering from performing the action, the child class should implement ask_and_do, which it turn should call do_with_signal to notify about changes.

Parameters
  • context – This is the CommandContext in which the command will execute. Commands will use this to access MainWindow, GuiState, and Labels.

  • params – Dictionary of any params for command.

class sleap.gui.commands.CheckForUpdates[source]
static do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

class sleap.gui.commands.CommandContext(state: sleap.gui.state.GuiState, app: MainWindow, update_callback: Optional[Callable] = None, change_stack: List = NOTHING)[source]

Context within in which commands are executed.

When you create a new command, you should both create a class for the command (which inherits from CommandClass) and add a distinct method for the command in the CommandContext class. This method is what should be connected/called from other code to invoke the command.

state

The GuiState object used to store state and pass messages.

app

The MainWindow, available for commands that modify the app.

update_callback

A callback to receive update notifications. This function should accept a list of UpdateTopic items.

addTrack()[source]

Creates new track and moves selected instance into this track.

addVideo()[source]

Shows gui for adding videos to project.

changestack_clear()[source]

Clears stack of changes.

changestack_push(change: str = '')[source]

Adds to stack of changes made by user.

changestack_savepoint()[source]

Marks that project was just saved.

checkForUpdates()[source]

Check for updates online.

completeInstanceNodes(instance: sleap.instance.Instance)[source]

Adds missing nodes to given instance.

deleteAreaPredictions()[source]

Gui for deleting instances within some rect on frame images.

deleteClipPredictions()[source]

Deletes all predictions within selected range of video frames.

deleteDialog()[source]

Deletes using options selected in a dialog.

deleteEdge()[source]

Removes (currently selected) edge from skeleton.

deleteFrameLimitPredictions()[source]

Gui for deleting instances beyond some number in each frame.

deleteFramePredictions()[source]

Deletes all predictions on current frame.

deleteLowScorePredictions()[source]

Gui for deleting instances below some score threshold.

deleteNode()[source]

Removes (currently selected) node from skeleton.

deletePredictions()[source]

Deletes all predicted instances in project.

deleteSelectedInstance()[source]

Deletes currently selected instance.

deleteSelectedInstanceTrack()[source]

Deletes all instances from track of currently selected instance.

execute(command: Type[sleap.gui.commands.AppCommand], **kwargs)[source]

Execute command in this context, passing named arguments.

exportAnalysisFile()[source]

Shows gui for exporting analysis h5 file.

exportFullPackage()[source]

Gui for exporting the dataset with any labeled frames and suggestions.

exportLabeledClip()[source]

Shows gui for exporting clip with visual annotations.

exportTrainingPackage()[source]

Gui for exporting the dataset with user-labeled images and suggestions.

exportUserLabelsPackage()[source]

Gui for exporting the dataset with user-labeled images.

classmethod from_labels(labels: sleap.io.dataset.Labels)sleap.gui.commands.CommandContext[source]

Creates a command context for use independently of GUI app.

generateSuggestions(params: Dict)[source]

Generates suggestions using given params dictionary.

gotoFrame()[source]

Shows gui to go to frame by number.

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

Activates video and goes to frame.

importAnalysisFile()[source]

Imports SLEAP analysis hdf5 files.

importCoco()[source]

Imports COCO datasets.

importDLC()[source]

Imports DeepLabCut datasets.

importDPK()[source]

Imports DeepPoseKit datasets.

importLEAP()[source]

Imports LEAP matlab datasets.

importPredictions()[source]

Starts gui for importing another dataset into currently one.

property labels

Alias to app.labels.

newEdge(src_node, dst_node)[source]

Adds new edge to skeleton.

newInstance(copy_instance: Optional[sleap.instance.Instance] = None, init_method: str = 'best', location: Optional[PySide2.QtCore.QPoint] = None, mark_complete: bool = False)[source]

Creates a new instance, copying node coordinates as appropriate.

Parameters
  • copy_instance – The Instance (or PredictedInstance) which we want to copy.

  • init_method – Method to use for positioning nodes.

  • location – The location where instance should be added (if node init method supports custom location).

newNode()[source]

Adds new node to skeleton.

newProject()[source]

Create a new project in a new window.

nextLabeledFrame()[source]

Goes to labeled frame after current frame.

nextSuggestedFrame()[source]

Goes to next suggested frame.

nextTrackFrame()[source]

Goes to next frame on which a track starts.

nextUserLabeledFrame()[source]

Goes to next labeled frame with user instances.

openPrereleaseVersion()[source]

Open the current prerelease version.

openProject(first_open: bool = False)[source]

Allows use to select and then open a saved project.

Parameters

first_open – Whether this is the first window opened. If True, then the new project is loaded into the current window rather than a new application window.

Returns

None.

openSkeleton()[source]

Shows gui for loading saved skeleton into project.

openStableVersion()[source]

Open the current stable version.

openWebsite(url)[source]

Open a website from URL using the native system browser.

prevSuggestedFrame()[source]

Goes to previous suggested frame.

previousLabeledFrame()[source]

Goes to labeled frame prior to current frame.

removeVideo()[source]

Removes selected video from project.

replaceVideo()[source]

Shows gui for replacing videos to project.

saveProject()[source]

Show gui to save project (or save as if not yet saved).

saveProjectAs()[source]

Show gui to save project as a new file.

saveSkeleton()[source]

Shows gui for saving skeleton from project.

selectToFrame()[source]

Shows gui to go to frame by number.

setInstancePointVisibility(instance: sleap.instance.Instance, node: Node, visible: bool)[source]

Toggles visibility set for a node for an instance.

setInstanceTrack(new_track: sleap.instance.Track)[source]

Sets track for selected instance.

setNodeName(skeleton, node, name)[source]

Changes name of node in skeleton.

setNodeSymmetry(skeleton, node, symmetry: str)[source]

Sets node symmetry in skeleton.

setPointLocations(instance: sleap.instance.Instance, nodes_locations: Dict[Node, Tuple[int, int]])[source]

Sets locations for node(s) for an instance.

setTrackName(track: sleap.instance.Track, name: str)[source]

Sets name for track.

signal_update(what: List[sleap.gui.commands.UpdateTopic])[source]

Calls the update callback after data has been changed.

transposeInstance()[source]

Transposes tracks for two instances.

If there are only two instances, then this swaps tracks. Otherwise, it allows user to select the instances for which we want to swap tracks.

updateEdges()[source]

Called when edges in skeleton have been changed.

class sleap.gui.commands.DeleteAllPredictions[source]
class sleap.gui.commands.DeleteAreaPredictions[source]
class sleap.gui.commands.DeleteClipPredictions[source]
class sleap.gui.commands.DeleteDialogCommand[source]
class sleap.gui.commands.DeleteEdge[source]
static ask(context: sleap.gui.commands.CommandContext, params: dict) → bool[source]

Method for information gathering.

Returns

Whether to perform action. By default returns True, but this is where we should return False if we prompt user for confirmation and they abort.

static do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

class sleap.gui.commands.DeleteFrameLimitPredictions[source]
classmethod ask(context: sleap.gui.commands.CommandContext, params: dict) → bool[source]

Method for information gathering.

Returns

Whether to perform action. By default returns True, but this is where we should return False if we prompt user for confirmation and they abort.

class sleap.gui.commands.DeleteFramePredictions[source]
class sleap.gui.commands.DeleteLowScorePredictions[source]
classmethod ask(context: sleap.gui.commands.CommandContext, params: dict) → bool[source]

Method for information gathering.

Returns

Whether to perform action. By default returns True, but this is where we should return False if we prompt user for confirmation and they abort.

class sleap.gui.commands.DeleteNode[source]
static do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

class sleap.gui.commands.DeleteSelectedInstance[source]
static do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

class sleap.gui.commands.DeleteSelectedInstanceTrack[source]
static do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

class sleap.gui.commands.EditCommand[source]

Class for commands which change data in project.

class sleap.gui.commands.ExportAnalysisFile[source]
static ask(context: sleap.gui.commands.CommandContext, params: dict) → bool[source]

Method for information gathering.

Returns

Whether to perform action. By default returns True, but this is where we should return False if we prompt user for confirmation and they abort.

classmethod do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

class sleap.gui.commands.ExportDatasetWithImages[source]
static ask(context: sleap.gui.commands.CommandContext, params: dict) → bool[source]

Method for information gathering.

Returns

Whether to perform action. By default returns True, but this is where we should return False if we prompt user for confirmation and they abort.

classmethod do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

class sleap.gui.commands.ExportFullPackage[source]
class sleap.gui.commands.ExportLabeledClip[source]
static ask(context: sleap.gui.commands.CommandContext, params: dict) → bool[source]

Method for information gathering.

Returns

Whether to perform action. By default returns True, but this is where we should return False if we prompt user for confirmation and they abort.

static do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

class sleap.gui.commands.ExportTrainingPackage[source]
class sleap.gui.commands.ExportUserLabelsPackage[source]
class sleap.gui.commands.FakeApp(labels: sleap.io.dataset.Labels)[source]

Use if you want to execute commands independently of the GUI app.

class sleap.gui.commands.GenerateSuggestions[source]
classmethod do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

class sleap.gui.commands.GoFrameGui[source]
classmethod ask(context: sleap.gui.commands.CommandContext, params: dict) → bool[source]

Method for information gathering.

Returns

Whether to perform action. By default returns True, but this is where we should return False if we prompt user for confirmation and they abort.

classmethod do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

class sleap.gui.commands.GoIteratorCommand[source]
classmethod do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

class sleap.gui.commands.GoNextLabeledFrame[source]
class sleap.gui.commands.GoNextSuggestedFrame[source]
classmethod do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

class sleap.gui.commands.GoNextTrackFrame[source]
classmethod do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

class sleap.gui.commands.GoNextUserLabeledFrame[source]
class sleap.gui.commands.GoPrevSuggestedFrame[source]
class sleap.gui.commands.GoPreviousLabeledFrame[source]
class sleap.gui.commands.ImportAnalysisFile[source]
static ask(context: sleap.gui.commands.CommandContext, params: dict) → bool[source]

Method for information gathering.

Returns

Whether to perform action. By default returns True, but this is where we should return False if we prompt user for confirmation and they abort.

static do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

class sleap.gui.commands.ImportCoco[source]
static ask(context: sleap.gui.commands.CommandContext, params: dict) → bool[source]

Method for information gathering.

Returns

Whether to perform action. By default returns True, but this is where we should return False if we prompt user for confirmation and they abort.

static do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

class sleap.gui.commands.ImportDeepLabCut[source]
static ask(context: sleap.gui.commands.CommandContext, params: dict) → bool[source]

Method for information gathering.

Returns

Whether to perform action. By default returns True, but this is where we should return False if we prompt user for confirmation and they abort.

static do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

class sleap.gui.commands.ImportDeepPoseKit[source]
static ask(context: sleap.gui.commands.CommandContext, params: dict) → bool[source]

Method for information gathering.

Returns

Whether to perform action. By default returns True, but this is where we should return False if we prompt user for confirmation and they abort.

static do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

class sleap.gui.commands.ImportLEAP[source]
static ask(context: sleap.gui.commands.CommandContext, params: dict) → bool[source]

Method for information gathering.

Returns

Whether to perform action. By default returns True, but this is where we should return False if we prompt user for confirmation and they abort.

static do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

class sleap.gui.commands.InstanceDeleteCommand[source]
classmethod ask(context: sleap.gui.commands.CommandContext, params: dict) → bool[source]

Method for information gathering.

Returns

Whether to perform action. By default returns True, but this is where we should return False if we prompt user for confirmation and they abort.

classmethod do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

class sleap.gui.commands.MergeProject[source]
class sleap.gui.commands.NavCommand[source]
class sleap.gui.commands.NewEdge[source]
static do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

class sleap.gui.commands.NewNode[source]
static do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

class sleap.gui.commands.NewProject[source]
static do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

class sleap.gui.commands.OpenPrereleaseVersion[source]
static do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

class sleap.gui.commands.OpenProject[source]
static ask(context: sleap.gui.commands.CommandContext, params: dict) → bool[source]

Method for information gathering.

Returns

Whether to perform action. By default returns True, but this is where we should return False if we prompt user for confirmation and they abort.

static do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

class sleap.gui.commands.OpenSkeleton[source]
static ask(context: sleap.gui.commands.CommandContext, params: dict) → bool[source]

Method for information gathering.

Returns

Whether to perform action. By default returns True, but this is where we should return False if we prompt user for confirmation and they abort.

static do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

class sleap.gui.commands.OpenStableVersion[source]
static do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

class sleap.gui.commands.OpenWebsite[source]
static do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

class sleap.gui.commands.RemoveVideo[source]
static ask(context: sleap.gui.commands.CommandContext, params: dict) → bool[source]

Method for information gathering.

Returns

Whether to perform action. By default returns True, but this is where we should return False if we prompt user for confirmation and they abort.

static do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

class sleap.gui.commands.ReplaceVideo[source]
static ask(context: sleap.gui.commands.CommandContext, params: dict) → bool[source]

Shows gui for replacing videos in project.

static do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

class sleap.gui.commands.SaveProject[source]
classmethod ask(context: sleap.gui.commands.CommandContext, params: dict) → bool[source]

Method for information gathering.

Returns

Whether to perform action. By default returns True, but this is where we should return False if we prompt user for confirmation and they abort.

class sleap.gui.commands.SaveProjectAs[source]
static ask(context: sleap.gui.commands.CommandContext, params: dict) → bool[source]

Method for information gathering.

Returns

Whether to perform action. By default returns True, but this is where we should return False if we prompt user for confirmation and they abort.

classmethod do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

class sleap.gui.commands.SaveSkeleton[source]
static ask(context: sleap.gui.commands.CommandContext, params: dict) → bool[source]

Method for information gathering.

Returns

Whether to perform action. By default returns True, but this is where we should return False if we prompt user for confirmation and they abort.

static do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

class sleap.gui.commands.SelectToFrameGui[source]
classmethod ask(context: sleap.gui.commands.CommandContext, params: dict) → bool[source]

Method for information gathering.

Returns

Whether to perform action. By default returns True, but this is where we should return False if we prompt user for confirmation and they abort.

classmethod do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

class sleap.gui.commands.SetInstancePointLocations[source]

Sets locations for node(s) for an instance.

Note: It’s important that this command does not update the visual scene, since this would redraw the frame and create new visual objects. The calling code is responsible for updating the visual scene.

Params:

instance: The instance nodes_locations: A dictionary of data to set * keys are nodes (or node names) * values are (x, y) coordinate tuples.

classmethod do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

class sleap.gui.commands.SetInstancePointVisibility[source]

Toggles visibility set for a node for an instance.

Note: It’s important that this command does not update the visual scene, since this would redraw the frame and create new visual objects. The calling code is responsible for updating the visual scene.

Params:

instance: The instance node: The Node (or name string) visible: Whether to set or clear visibility for node

classmethod do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

class sleap.gui.commands.SetNodeName[source]
static do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

class sleap.gui.commands.SetNodeSymmetry[source]
static do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

class sleap.gui.commands.SetSelectedInstanceTrack[source]
static do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

class sleap.gui.commands.SetTrackName[source]
static do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

class sleap.gui.commands.TransposeInstances[source]
classmethod do_action(context: sleap.gui.commands.CommandContext, params: dict)[source]

Method for performing action.

class sleap.gui.commands.UpdateTopic(value)[source]

Topics so context can tell callback what was updated by the command.