Skip to content

Commit

Permalink
Better warning messages (w/o dialog pop-ups!)
Browse files Browse the repository at this point in the history
  • Loading branch information
roomrys committed Dec 6, 2023
1 parent 7cc7a5a commit a2326d3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
35 changes: 15 additions & 20 deletions sleap/gui/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -3546,18 +3546,11 @@ def get_and_verify_enough_instances(
require_multiple_views=True,
)
return instances
except ValueError:
# If not enough views or instances, then return
message = (
"One or less instances found for frame "
f"{frame_idx} in {session.camera_cluster}. "
"Multiple instances accross multiple views needed to triangulate. "
"Skipping triangulation and reprojection."
)
if show_dialog and context is not None:
QtWidgets.QMessageBox.warning(context.app, "Triangulation", message)
else:
logger.warning(message)
except Exception as e:
# If not enough views, instances or some other error, then return
message = str(e)
message += "\n\tSkipping triangulation and reprojection."
logger.warning(message)
return False

@staticmethod
Expand Down Expand Up @@ -3622,6 +3615,14 @@ def get_instances_across_views(
instances are found.
"""

def _message(views: bool):
views_or_instances = "views" if views else "instances"
return (
f"One or less {views_or_instances} found for frame "
f"{frame_idx} in {session.camera_cluster}. "
"Multiple instances accross multiple views needed to triangulate."
)

# Get all views at this frame index
views: Dict[
Camcorder, "LabeledFrame"
Expand All @@ -3633,10 +3634,7 @@ def get_instances_across_views(

# If not enough views, then raise error
if len(views) <= 1 and require_multiple_views:
raise ValueError(
"One or less views found for frame "
f"{frame_idx} in {session.camera_cluster}."
)
raise ValueError(_message(views=True))

# Find all instance accross all views
instances: Dict[Camcorder, "Instance"] = {}
Expand All @@ -3647,10 +3645,7 @@ def get_instances_across_views(

# If not enough instances for multiple views, then raise error
if len(instances) <= 1 and require_multiple_views:
raise ValueError(
"One or less instances found for frame "
f"{frame_idx} in {session.camera_cluster}."
)
raise ValueError(_message(views=False))

return instances

Expand Down
2 changes: 1 addition & 1 deletion tests/gui/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,7 @@ def test_triangulate_session_do_action(multiview_min_session_labels: Labels):


def test_triangulate_session(multiview_min_session_labels: Labels):
"""Test `TriangulateSession`, if"""
"""Test `TriangulateSession`."""

labels = multiview_min_session_labels
session = labels.sessions[0]
Expand Down

0 comments on commit a2326d3

Please sign in to comment.