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

Create and assign instance group with Shift + num in (n_instance_groups, 9] #1823

Closed
Changes from all commits
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
15 changes: 15 additions & 0 deletions sleap/gui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,15 @@ def __init__(
else:
self.state["project_loaded"] = False

def create_and_assign_instance_group(self):
"""Creates a new instance group and assigns the selected instance."""
instance = self.state["instance"]
self.commands.addInstanceGroup() # Create a new instance group
if instance is not None:
new_group = self.state["session"].frame_groups
[self.state["frame_idx"]].instance_groups[-1]
self.commands.setInstanceGroup(instance_group=new_group)

Comment on lines +192 to +200
Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. This should not be a method of MainWindow, it should be a command class in commands.py.
  2. We already have a command class for this that we just need to modify - although looking at the function, it looks like this is already handled by the last line here:

    sleap/sleap/gui/commands.py

    Lines 2763 to 2784 in 5d120c6

    class AddInstanceGroup(EditCommand):
    topics = [UpdateTopic.sessions]
    @staticmethod
    def do_action(context, params):
    # Get session and frame index
    frame_idx = context.state["frame_idx"]
    session: RecordingSession = context.state["session"]
    if session is None:
    raise ValueError("Cannot add instance group without session.")
    # Get or create frame group
    frame_group = session.frame_groups.get(frame_idx, None)
    if frame_group is None:
    frame_group = session.new_frame_group(frame_idx=frame_idx)
    # Create and add instance group
    instance_group = frame_group.add_instance_group(instance_group=None)
    # Now add the selected instance to the `InstanceGroup`
    context.execute(SetSelectedInstanceGroup, instance_group=instance_group)
Suggested change
def create_and_assign_instance_group(self):
"""Creates a new instance group and assigns the selected instance."""
instance = self.state["instance"]
self.commands.addInstanceGroup() # Create a new instance group
if instance is not None:
new_group = self.state["session"].frame_groups
[self.state["frame_idx"]].instance_groups[-1]
self.commands.setInstanceGroup(instance_group=new_group)

def setWindowTitle(self, value):
"""Sets window title (if value is not None)."""
if value is not None:
Expand Down Expand Up @@ -836,6 +845,12 @@ def new_instance_menu_action():
self.inst_groups_delete_menu = sessionsMenu.addMenu("Delete Instance Group")
self.state.connect("frame_idx", self._update_sessions_menu)

self.inst_groups_menu.addAction(
"New Instance Group and Assign (Shift + 0)",
self.create_and_assign_instance_group,
Qt.SHIFT + Qt.Key_0
)

Comment on lines +848 to +853
Copy link
Collaborator

Choose a reason for hiding this comment

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

We already link an action to the Shirt + 0 hotkey.

sleap/sleap/gui/app.py

Lines 1506 to 1510 in 5d120c6

self.inst_groups_menu.addAction(
"New Instance Group",
self.commands.addInstanceGroup,
Qt.SHIFT + Qt.Key_0,
)

Suggested change
self.inst_groups_menu.addAction(
"New Instance Group and Assign (Shift + 0)",
self.create_and_assign_instance_group,
Qt.SHIFT + Qt.Key_0
)

### Tracks Menu ###

tracksMenu = self.menuBar().addMenu("Tracks")
Expand Down