From dd5621fe8665587ee1ed2dc5d0eefcfc90fc8c66 Mon Sep 17 00:00:00 2001 From: roomrys <38435167+roomrys@users.noreply.github.com> Date: Wed, 30 Mar 2022 10:47:05 -0700 Subject: [PATCH 1/3] add hide instance menu item and hotkey * single press of hotkey (H) toggles instance visibility --- sleap/config/shortcuts.yaml | 1 + sleap/gui/app.py | 2 ++ sleap/gui/overlays/instance.py | 1 + sleap/gui/shortcuts.py | 1 + sleap/gui/widgets/video.py | 19 +++++++++++++++++++ 5 files changed, 24 insertions(+) diff --git a/sleap/config/shortcuts.yaml b/sleap/config/shortcuts.yaml index 8761db995..53dc96814 100644 --- a/sleap/config/shortcuts.yaml +++ b/sleap/config/shortcuts.yaml @@ -28,6 +28,7 @@ save as: Ctrl+Shift+S save: Ctrl+S select next: '`' select to frame: Ctrl+Shift+J +show instances: H show edges: Ctrl+Shift+Tab show labels: Ctrl+Tab show trails: diff --git a/sleap/gui/app.py b/sleap/gui/app.py index b88e070e3..31eeccbd9 100644 --- a/sleap/gui/app.py +++ b/sleap/gui/app.py @@ -140,6 +140,7 @@ def __init__( self.state["last_interacted_frame"] = None self.state["filename"] = None self.state["show non-visible nodes"] = prefs["show non-visible nodes"] + self.state["show instances"] = True self.state["show labels"] = True self.state["show edges"] = True self.state["edge style"] = prefs["edge style"] @@ -549,6 +550,7 @@ def prev_vid(): viewMenu.addSeparator() + add_menu_check_item(viewMenu, "show instances", "Show Instances") add_menu_check_item( viewMenu, "show non-visible nodes", "Show Non-Visible Nodes" ) diff --git a/sleap/gui/overlays/instance.py b/sleap/gui/overlays/instance.py index e1dfb51a6..10da79cfe 100644 --- a/sleap/gui/overlays/instance.py +++ b/sleap/gui/overlays/instance.py @@ -50,6 +50,7 @@ def add_to_scene(self, video, frame_idx): show_non_visible=self.state.get("show non-visible nodes", default=True), ) + self.player.showInstances(self.state.get("show instances", default=True)) self.player.showLabels(self.state.get("show labels", default=True)) self.player.showEdges(self.state.get("show edges", default=True)) diff --git a/sleap/gui/shortcuts.py b/sleap/gui/shortcuts.py index 76a3053bf..7b45a1e11 100644 --- a/sleap/gui/shortcuts.py +++ b/sleap/gui/shortcuts.py @@ -41,6 +41,7 @@ class Shortcuts(object): "goto next suggestion", "goto prev suggestion", "goto next track spawn", + "show instances", "show labels", "show edges", "show trails", diff --git a/sleap/gui/widgets/video.py b/sleap/gui/widgets/video.py index 7e83cb8b0..e7c52772e 100644 --- a/sleap/gui/widgets/video.py +++ b/sleap/gui/widgets/video.py @@ -263,6 +263,7 @@ def update_selection_state(a, b): self.state.connect("frame_idx", lambda idx: self.seekbar.setValue(idx)) self.state.connect("instance", self.view.selectInstance) + self.state.connect("show instances", self.plot) self.state.connect("show labels", self.plot) self.state.connect("show edges", self.plot) self.state.connect("video", self.load_video) @@ -476,6 +477,15 @@ def plot(self, *args): self._video_image_loader.video = self.video self._video_image_loader.request(idx) + def showInstances(self, show): + """Show/hide all instances in viewer. + + Args: + show: Show if True, hide otherwise. + """ + for inst in self.instances: + inst.showInstances(show) + def showLabels(self, show): """Show/hide node labels for all instances in viewer. @@ -1963,6 +1973,15 @@ def selected(self, selected: bool): # Update the selection box for this skeleton instance self.updateBox() + def showInstances(self, show: bool): + """ + Shows/hides skeleton instance. + + Args: + show: Show skeleton if True, hide otherwise. + """ + self.setVisible(show) + def showLabels(self, show: bool): """ Draws/hides the labels for this skeleton instance. From c270c41dd946e1a6750ddf8034d076deebca4e4e Mon Sep 17 00:00:00 2001 From: roomrys <38435167+roomrys@users.noreply.github.com> Date: Wed, 30 Mar 2022 15:48:19 -0700 Subject: [PATCH 2/3] Add instance visibility message to status bar --- sleap/gui/app.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/sleap/gui/app.py b/sleap/gui/app.py index 31eeccbd9..bfeda1213 100644 --- a/sleap/gui/app.py +++ b/sleap/gui/app.py @@ -127,6 +127,8 @@ def __init__( state=self.state, app=self, update_callback=self.on_data_update ) + self.shortcuts = Shortcuts() + self._menu_actions = dict() self._buttons = dict() self._child_windows = dict() @@ -318,11 +320,11 @@ def _create_color_manager(self): def _create_menus(self): """Creates main application menus.""" - shortcuts = Shortcuts() + # shortcuts = Shortcuts() # add basic menu item def add_menu_item(menu, key: str, name: str, action: Callable): - menu_item = menu.addAction(name, action, shortcuts[key]) + menu_item = menu.addAction(name, action, self.shortcuts[key]) self._menu_actions[key] = menu_item return menu_item @@ -1362,6 +1364,16 @@ def updateStatusMessage(self, message: Optional[str] = None): ) message += " in video" + lf = self.state["labeled_frame"] + n_instances = 0 if lf is None else len(lf) + message += f"{spacer}Current frame: {n_instances} instances" + if not self.state["show instances"]: + hide_key = self.shortcuts["show instances"].toString() + message += f" [Hidden] Press '{hide_key}' to toggle." + self.statusBar().setStyleSheet("color: red; font-weight: bold") + else: + self.statusBar().setStyleSheet("color: black; font-weight: normal") + self.statusBar().showMessage(message) def resetPrefs(self): From b2fff04e07539470104896443dd7597404701269 Mon Sep 17 00:00:00 2001 From: roomrys <38435167+roomrys@users.noreply.github.com> Date: Wed, 30 Mar 2022 16:13:38 -0700 Subject: [PATCH 3/3] Resize keyboard shortcuts dialog box * Make shortcuts pop-up slightly narrower and taller --- sleap/gui/dialogs/shortcuts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sleap/gui/dialogs/shortcuts.py b/sleap/gui/dialogs/shortcuts.py index 89f700019..0b9c9be64 100644 --- a/sleap/gui/dialogs/shortcuts.py +++ b/sleap/gui/dialogs/shortcuts.py @@ -14,7 +14,7 @@ class ShortcutDialog(QtWidgets.QDialog): Dialog window for reviewing and modifying the keyboard shortcuts. """ - _column_len = 13 + _column_len = 14 def __init__(self, *args, **kwargs): super(ShortcutDialog, self).__init__(*args, **kwargs)