Skip to content

Commit

Permalink
Fix skeleton templates (#1404)
Browse files Browse the repository at this point in the history
  • Loading branch information
roomrys authored Jul 24, 2023
1 parent 0e7a372 commit d173303
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
19 changes: 16 additions & 3 deletions sleap/gui/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1946,15 +1946,28 @@ def delete_extra_skeletons(labels: Labels):

labels.skeletons = skeletons_used

@staticmethod
def get_template_skeleton_filename(context: CommandContext) -> str:
"""Helper function to get the template skeleton filename from dropdown.
Args:
context: The `CommandContext`.
Returns:
Path to the template skeleton shipped with SLEAP.
"""

template = context.app.skeleton_dock.skeleton_templates.currentText()
filename = get_package_file(f"sleap/skeletons/{template}.json")
return filename

@staticmethod
def ask(context: CommandContext, params: dict) -> bool:
filters = ["JSON skeleton (*.json)", "HDF5 skeleton (*.h5 *.hdf5)"]
# Check whether to load from file or preset
if params.get("template", False):
# Get selected template from dropdown
template = context.app.skeletonTemplates.currentText()
# Load from selected preset
filename = get_package_file(f"sleap/skeletons/{template}.json")
filename = OpenSkeleton.get_template_skeleton_filename(context)
else:
filename, selected_filter = FileDialog.open(
context.app,
Expand Down
15 changes: 10 additions & 5 deletions tests/gui/widgets/test_docks.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""Module for testing dock widgets for the `MainWindow`."""

import pytest
from pathlib import Path

from sleap import Labels, Video
from sleap.gui.app import MainWindow
from sleap.gui.commands import OpenSkeleton
from sleap.gui.widgets.docks import (
InstancesDock,
SuggestionsDock,
Expand Down Expand Up @@ -79,6 +81,13 @@ def test_skeleton_dock(qtbot):
assert dock.main_window is main_window
assert dock.wgt_layout is dock.widget().layout()

# This method should get called when we click the load button, but let's just call
# the non-gui parts directly
fn = Path(
OpenSkeleton.get_template_skeleton_filename(context=dock.main_window.commands)
)
assert fn.name == f"{dock.skeleton_templates.currentText()}.json"


def test_suggestions_dock(qtbot):
"""Test the `DockWidget` class."""
Expand All @@ -98,7 +107,3 @@ def test_instances_dock(qtbot):
assert dock.name == "Instances"
assert dock.main_window is main_window
assert dock.wgt_layout is dock.widget().layout()


if __name__ == "__main__":
pytest.main([f"{__file__}::test_instances_dock"])

0 comments on commit d173303

Please sign in to comment.