Skip to content
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

Handle case when no frame selection for trail overlay #1832

Merged
merged 2 commits into from
Jul 1, 2024
Merged
Changes from 1 commit
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
19 changes: 11 additions & 8 deletions sleap/gui/overlays/tracks.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
"""Track trail and track list overlays."""

from typing import Dict, Iterable, List, Optional, Tuple

import attr
from qtpy import QtCore, QtGui

from sleap.gui.overlays.base import BaseOverlay
from sleap.gui.widgets.video import QtTextWithBackground
from sleap.instance import Track
from sleap.io.dataset import Labels
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unused import.

The Labels class from sleap.io.dataset is imported but not used in this file.

- from sleap.io.dataset import Labels
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
from sleap.io.dataset import Labels
Tools
Ruff

11-11: sleap.io.dataset.Labels imported but unused

Remove unused import: sleap.io.dataset.Labels

(F401)

from sleap.io.video import Video
from sleap.prefs import prefs
from sleap.gui.widgets.video import QtTextWithBackground

import attr

from typing import Iterable, List, Optional, Dict

from qtpy import QtCore, QtGui


@attr.s(auto_attribs=True)
Expand Down Expand Up @@ -56,7 +55,9 @@ def get_shade_options(cls):

return {"Dark": 0.6, "Normal": 1.0, "Light": 1.25}

def get_track_trails(self, frame_selection: Iterable["LabeledFrame"]):
def get_track_trails(
self, frame_selection: Iterable["LabeledFrame"]
) -> Optional[Dict[Track, List[List[Tuple[float, float]]]]]:
Comment on lines +61 to +62
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add missing import for LabeledFrame.

The LabeledFrame class is referenced but not imported, which could cause a runtime error.

+ from sleap.io.dataset import LabeledFrame
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
self, frame_selection: Iterable["LabeledFrame"]
) -> Optional[Dict[Track, List[List[Tuple[float, float]]]]]:
from sleap.io.dataset import LabeledFrame
self, frame_selection: Iterable["LabeledFrame"]
) -> Optional[Dict[Track, List[List[Tuple[float, float]]]]]:
Tools
Ruff

61-61: Undefined name LabeledFrame

(F821)

"""Get data needed to draw track trail.

Args:
Expand Down Expand Up @@ -152,6 +153,8 @@ def add_to_scene(self, video: Video, frame_idx: int):
frame_selection = self.get_frame_selection(video, frame_idx)

all_track_trails = self.get_track_trails(frame_selection)
if all_track_trails is None:
return

for track, trails in all_track_trails.items():
trail_color = tuple(
Expand Down