8000 Add hide instance menu item and hotkey by roomrys · Pull Request #692 · talmolab/sleap · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add hide instance menu item and hotkey #692

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sleap/config/shortcuts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 16 additions & 2 deletions sleap/gui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -140,6 +142,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"]
Expand Down Expand Up @@ -317,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

Expand Down Expand Up @@ -549,6 +552,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"
)
Expand Down Expand Up @@ -1360,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):
Expand Down
2 changes: 1 addition & 1 deletion sleap/gui/dialogs/shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions sleap/gui/overlays/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
1 change: 1 addition & 0 deletions sleap/gui/shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
19 changes: 19 additions & 0 deletions sleap/gui/widgets/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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.
Expand Down
0