Skip to content

Commit

Permalink
Add color by instance group preference saving (#1999)
Browse files Browse the repository at this point in the history
* Add Color by Instance Group preference saving

* Replaced color_by_instance_group with distinctly_color to align with the existing View > Apply Distinct Colors To submenu

* Use updated preference for GUI state

* Rename GUI facing "instance_groups" to "instance groups"

---------

Co-authored-by: roomrys <[email protected]>
  • Loading branch information
justinvshen and roomrys authored Nov 1, 2024
1 parent b55d4ef commit c7185c7
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
7 changes: 5 additions & 2 deletions sleap/gui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ def closeEvent(self, event):
prefs["color predicted"] = self.state["color predicted"]
prefs["trail shade"] = self.state["trail_shade"]
prefs["share usage data"] = self.state["share usage data"]
prefs["distinctly_color"] = self.state["distinctly_color"]

# Save preferences.
prefs.save()
Expand Down Expand Up @@ -298,6 +299,8 @@ def labels(self, value):
def _initialize_gui(self):
"""Creates menus, dock windows, starts timers to update gui state."""

self.state["distinctly_color"] = prefs["distinctly_color"]

self._create_color_manager()
self._create_video_player()
self.statusBar()
Expand Down Expand Up @@ -655,7 +658,7 @@ def prev_vid():
key="palette",
)

distinctly_color_options = ("instance_groups", "instances", "nodes", "edges")
distinctly_color_options = ("instance groups", "instances", "nodes", "edges")

add_submenu_choices(
menu=viewMenu,
Expand All @@ -665,7 +668,7 @@ def prev_vid():
)

self.state["palette"] = prefs["palette"]
self.state["distinctly_color"] = "instances"
self.state["distinctly_color"] = prefs["distinctly_color"]

viewMenu.addSeparator()

Expand Down
2 changes: 1 addition & 1 deletion sleap/gui/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def get_item_color(

return (128, 128, 128)

if self.distinctly_color == "instance_groups" and parent_instance:
if self.distinctly_color == "instance groups" and parent_instance:

if parent_frame is None and parent_instance:
parent_frame = parent_instance.frame
Expand Down
2 changes: 1 addition & 1 deletion sleap/gui/dataviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ def item_to_data(self, obj, item: InstanceGroup):

def get_item_color(self, instance_group: InstanceGroup, key: str):
color_manager = self.context.app.color_manager
if color_manager.distinctly_color == "instance_groups" and key == "name":
if color_manager.distinctly_color == "instance groups" and key == "name":

# Get the RecordingSession
state = self.context.state
Expand Down
7 changes: 4 additions & 3 deletions sleap/io/visuals.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ def _plot_instance_cv(
)

if self.show_edges:
for (src, dst) in instance.skeleton.edge_inds:
for src, dst in instance.skeleton.edge_inds:
# Get points for the nodes connected by this edge
src_x, src_y = points_array[src]
dst_x, dst_y = points_array[dst]
Expand Down Expand Up @@ -542,8 +542,9 @@ def save_labeled_video(
for what instance/node/edge
palette: SLEAP color palette to use. Options include: "alphabet", "five+",
"solarized", or "standard". Only used if `color_manager` is None.
distinctly_color: Specify how to color instances. Options include: "instances",
"edges", and "nodes". Only used if `color_manager` is None.
distinctly_color: Specify how to color instances. Options include:
"instance groups", "instances", "edges", and "nodes". Only used if
`color_manager` is None.
gui_progress: Whether to show Qt GUI progress dialog.
Returns:
Expand Down
1 change: 1 addition & 0 deletions sleap/prefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Preferences(object):
"medium step size": 10,
"large step size": 100,
"color predicted": False,
"distinctly_color": "instances",
"propagate track labels": True,
"palette": "standard",
"bold lines": False,
Expand Down

0 comments on commit c7185c7

Please sign in to comment.