Skip to content

Commit

Permalink
Add highlight for instance group dock (#1860)
Browse files Browse the repository at this point in the history
* Add connect callback to instance group

* Add QtInstance instead of InstanceGroup

* Add changes for review

* Handle case when select is neither Instance, int, nor InstanceGroup

---------

Co-authored-by: roomrys <38435167+roomrys@users.noreply.github.com>
  • Loading branch information
justinvshen and roomrys authored Jul 26, 2024
1 parent 0f9fe25 commit 69e00b1
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions sleap/gui/widgets/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
from sleap.prefs import prefs
from sleap.skeleton import Node
from sleap.io.cameras import Camcorder
from sleap.io.cameras import InstanceGroup


class LoadImageWorker(QtCore.QObject):
Expand Down Expand Up @@ -272,6 +273,7 @@ def update_selection_state(a, b):
self.state.connect("frame_idx", lambda idx: self.plot())
self.state.connect("frame_idx", lambda idx: self.seekbar.setValue(idx))
self.state.connect("instance", self.view.selectInstance)
self.state.connect("instance_group", self.view.selectInstance)

self.state.connect("show instances", self.plot)
self.state.connect("show labels", self.plot)
Expand Down Expand Up @@ -960,18 +962,42 @@ def all_instances(self) -> List["QtInstance"]:
scene_items = self.scene.items(Qt.SortOrder.AscendingOrder)
return list(filter(lambda x: isinstance(x, QtInstance), scene_items))

def selectInstance(self, select: Union[Instance, int]):
"""
Select a particular instance in view.
def selectInstance(self, select: Optional[Union[Instance, int, InstanceGroup]]):
"""Select a particular instance in view.
Args:
select: Either `Instance` or index of instance in view.
select: Either `None` or `Instance`, index, or `InstanceGroup` of instance
in view.
Returns:
None
"""

# Decide which function to use to determine if instance is selected
if isinstance(select, int):

def determine_selected(idx: int, instance: QtInstance):
return idx == select

elif isinstance(select, Instance):

def determine_selected(idx: int, instance: QtInstance):
return instance.instance == select

elif isinstance(select, InstanceGroup):

def determine_selected(idx: int, instance: QtInstance):
return instance.instance in select.instances

else:

def determine_selected(idx: int, instance: QtInstance):
return False

# Set selected state for each instance
for idx, instance in enumerate(self.all_instances):
instance.selected = select == idx or select == instance.instance
instance.selected = determine_selected(idx, instance)

self.updatedSelection.emit()

def getSelectionIndex(self) -> Optional[int]:
Expand Down

0 comments on commit 69e00b1

Please sign in to comment.