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.
-
classmethod
-
class
sleap.gui.commands.
AddMissingInstanceNodes
[source]¶ -
classmethod
do_action
(context: sleap.gui.commands.CommandContext, params: dict)[source]¶ Method for performing action.
-
classmethod
-
class
sleap.gui.commands.
AddTrack
[source]¶ -
static
do_action
(context: sleap.gui.commands.CommandContext, params: dict)[source]¶ Method for performing action.
-
static
-
class
sleap.gui.commands.
AddUserInstancesFromPredictions
[source]¶ -
classmethod
do_action
(context: sleap.gui.commands.CommandContext, params: dict)[source]¶ Method for performing action.
-
classmethod
-
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.
-
static
-
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.
-
static
-
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.
-
completeInstanceNodes
(instance: sleap.instance.Instance)[source]¶ Adds missing nodes to given 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.
-
exportTrainingPackage
()[source]¶ Gui for exporting the dataset with user-labeled images and suggestions.
-
classmethod
from_labels
(labels: sleap.io.dataset.Labels) → sleap.gui.commands.CommandContext[source]¶ Creates a command context for use independently of GUI app.
-
gotoVideoAndFrame
(video: sleap.io.video.Video, frame_idx: int)[source]¶ Activates video and goes to frame.
-
property
labels
¶ Alias to app.labels.
-
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
(orPredictedInstance
) 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).
-
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.
-
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.
-
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.
-
-
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.
-
static
-
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.
-
classmethod
-
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.
-
classmethod
-
class
sleap.gui.commands.
DeleteNode
[source]¶ -
static
do_action
(context: sleap.gui.commands.CommandContext, params: dict)[source]¶ Method for performing action.
-
static
-
class
sleap.gui.commands.
DeleteSelectedInstance
[source]¶ -
static
do_action
(context: sleap.gui.commands.CommandContext, params: dict)[source]¶ Method for performing action.
-
static
-
class
sleap.gui.commands.
DeleteSelectedInstanceTrack
[source]¶ -
static
do_action
(context: sleap.gui.commands.CommandContext, params: dict)[source]¶ Method for performing action.
-
static
-
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.
-
static
-
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.
-
static
-
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.
-
static
-
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.
-
classmethod
-
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.
-
classmethod
-
class
sleap.gui.commands.
GoIteratorCommand
[source]¶ -
classmethod
do_action
(context: sleap.gui.commands.CommandContext, params: dict)[source]¶ Method for performing action.
-
classmethod
-
class
sleap.gui.commands.
GoNextSuggestedFrame
[source]¶ -
classmethod
do_action
(context: sleap.gui.commands.CommandContext, params: dict)[source]¶ Method for performing action.
-
classmethod
-
class
sleap.gui.commands.
GoNextTrackFrame
[source]¶ -
classmethod
do_action
(context: sleap.gui.commands.CommandContext, params: dict)[source]¶ Method for performing action.
-
classmethod
-
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.
-
static
-
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.
-
static
-
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.
-
static
-
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.
-
static
-
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.
-
static
-
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.
-
classmethod
-
class
sleap.gui.commands.
NewEdge
[source]¶ -
static
do_action
(context: sleap.gui.commands.CommandContext, params: dict)[source]¶ Method for performing action.
-
static
-
class
sleap.gui.commands.
NewNode
[source]¶ -
static
do_action
(context: sleap.gui.commands.CommandContext, params: dict)[source]¶ Method for performing action.
-
static
-
class
sleap.gui.commands.
NewProject
[source]¶ -
static
do_action
(context: sleap.gui.commands.CommandContext, params: dict)[source]¶ Method for performing action.
-
static
-
class
sleap.gui.commands.
OpenPrereleaseVersion
[source]¶ -
static
do_action
(context: sleap.gui.commands.CommandContext, params: dict)[source]¶ Method for performing action.
-
static
-
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.
-
static
-
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.
-
static
-
class
sleap.gui.commands.
OpenStableVersion
[source]¶ -
static
do_action
(context: sleap.gui.commands.CommandContext, params: dict)[source]¶ Method for performing action.
-
static
-
class
sleap.gui.commands.
OpenWebsite
[source]¶ -
static
do_action
(context: sleap.gui.commands.CommandContext, params: dict)[source]¶ Method for performing action.
-
static
-
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.
-
static
-
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.
-
static
-
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.
-
classmethod
-
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.
-
static
-
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.
-
static
-
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.
-
classmethod
-
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.
-
static
-
class
sleap.gui.commands.
SetNodeSymmetry
[source]¶ -
static
do_action
(context: sleap.gui.commands.CommandContext, params: dict)[source]¶ Method for performing action.
-
static
-
class
sleap.gui.commands.
SetSelectedInstanceTrack
[source]¶ -
static
do_action
(context: sleap.gui.commands.CommandContext, params: dict)[source]¶ Method for performing action.
-
static
-
class
sleap.gui.commands.
SetTrackName
[source]¶ -
static
do_action
(context: sleap.gui.commands.CommandContext, params: dict)[source]¶ Method for performing action.
-
static
-
class
sleap.gui.commands.
TransposeInstances
[source]¶ -
classmethod
do_action
(context: sleap.gui.commands.CommandContext, params: dict)[source]¶ Method for performing action.
-
classmethod