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

Each open project is an instance of MainWindow.

The main window contains a QtVideoPlayer widget for showing video frames (the video player widget contains both a graphics view widget that shows the frame image and a seekbar widget for navigation). The main window also contains various “data views”–tables which can be docked in the window as well as a status bar.

When a new instance of MainWindow is created, it creates all of these widgets, sets up the menus, and also creates

  • single GuiState object

  • single CommandContext object

  • single ColorManager object

  • multiple overlay objects (subclasses of BaseOverlay)

A timer is started (runs via Qt event loop) which enables/disables various menu items and buttons based on current state (e.g., you can’t delete an instance if no instance is selected).

Shortcuts are loaded using Shortcuts class. Preferences are loaded by importing prefs, a singleton instance of Preferences.

GuiState is used for storing “global” state for the project (e.g., Labels object, the current frame, current instance, whether to show track trails, etc.). every menu command with state (e.g., check/uncheck) should be connected to a state variable.

CommandContext has methods which can be triggered by menu items/buttons/etc in the GUI to perform various actions. The command context enforces a pattern for implementing each command in its own class, it keeps track of whether there are unsaved changes (and in the future would make it easier to implement undo/redo), and it handles triggering the relevant updates in the GUI based on the effects of the command (these are passed using UpdateTopic enum and handed by :py:method:`MainWindow.on_data_update()`).

ColorManager loads color palettes, keeps track of current palette, and should always be queried for how to draw instances–this ensures consistency (e.g.) between color of instances drawn on video frame and instances listed in data view table.

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


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


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


Closes application window, prompting for saving as needed.

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

Custom event handler.

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


e – The event.


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

loadLabelsObject(labels:, filename: Optional[str] = None)[source]

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

  • labels – The Labels object to load.

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



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

Loads given labels file into GUI.


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


Return type


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.


Sets window title (if value is not None).

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

Updates status bar.[source]

Starts new instance of app.