Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
9 changes: 5 additions & 4 deletions sleap/gui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1365,14 +1365,15 @@ 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)
# TODO: revisit with LabeledFrame.unused_predictions() & instances_to_show()
n_instances = 0 if lf is None else len(lf.instances_to_show)
message += f"{spacer}Current frame: {n_instances} instances"
if not self.state["show instances"]:
if (n_instances > 0) and 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")
self.statusBar().setStyleSheet("color: red")
else:
self.statusBar().setStyleSheet("color: black; font-weight: normal")
self.statusBar().setStyleSheet("color: black")

self.statusBar().showMessage(message)

Expand Down
2 changes: 2 additions & 0 deletions sleap/gui/widgets/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,8 @@ def showInstances(self, show):
"""
for inst in self.instances:
inst.showInstances(show)
for inst in self.predicted_instances:
inst.showInstances(show)

def showLabels(self, show):
"""Show/hide node labels for all instances in viewer.
Expand Down
66 changes: 66 additions & 0 deletions tests/gui/test_app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest
from PySide2.QtWidgets import QApplication

from sleap.gui.app import MainWindow
Expand Down Expand Up @@ -264,3 +265,68 @@ def test_app_new_window(qtbot):
assert wins == (start_wins + 3)

app.closeAllWindows()


@pytest.mark.skipif(
sys.platform.startswith("li"), reason="qtbot.waitActive times out on ubuntu"
)
def test_menu_actions(qtbot, centered_pair_predictions: Labels):
def verify_visibility(expected_visibility: bool = True):
"""Verify the visibility status of all instances in video player.

Args:
expected_visibility: Expected visibility of instance. Defaults to True.
"""
for inst in vp.instances:
assert inst.isVisible() == expected_visibility
for inst in vp.predicted_instances:
assert inst.isVisible() == expected_visibility

def toggle_and_verify_visibility(expected_visibility: bool = True):
"""Toggle the visibility of all instances within video player, then verify
expected visibility of all instances.

Args:
expected_visibility: Expected visibility of instances. Defaults to True.
"""
qtbot.keyClick(window.menuBar(), window.shortcuts["show instances"].toString())
verify_visibility(expected_visibility)

# Test hide instances menu action (and its effect on instance color)

# Instantiate the window and load labels
window: MainWindow = MainWindow()
window.loadLabelsObject(centered_pair_predictions)
# TODO: window does not seem to show as expected on ubuntu
with qtbot.waitActive(window, timeout=2000):
window.showNormal()
vp = window.player

# Enable distinct colors
window.state["color predicted"] = True

# Read colors for each instance in view
# TODO: revisit with LabeledFrame.unused_predictions() & instances_to_show()
visible_instances = window.state["labeled_frame"].instances_to_show
color_of_instances = {}
for inst in visible_instances:
item_color = window.color_manager.get_item_color(inst)
color_of_instances[inst] = item_color

# Turn predicted instance into user labeled instance
predicted_instance = vp.view.predicted_instances[0].instance
window.commands.newInstance(copy_instance=predicted_instance, mark_complete=False)

# Ensure colors of instances do not change
for inst in visible_instances:
item_color = window.color_manager.get_item_color(inst)
assert item_color == color_of_instances[inst]

# Ensure instances are visible - should be the visible by default
verify_visibility(True)

# Toggle instance visibility with shortcut, hiding instances
toggle_and_verify_visibility(False)

# Toggle instance visibility with shortcut, showing instances
toggle_and_verify_visibility(True)