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

Conversation

ramizhajj1
Copy link
Collaborator

@ramizhajj1 ramizhajj1 commented Jun 21, 2024

Description

When the user clicks Shift + 0 keyboard shortcut, it should both create a new instance group and assign the selected instance if any.

Types of changes

  • Bugfix
  • [x ] New feature
  • Refactor / Code style update (no logical changes)
  • Build / CI changes
  • Documentation Update
  • Other (explain)

Does this address any currently open issues?

[list open issues here]

Outside contributors checklist

  • Review the guidelines for contributing to this repository
  • Read and sign the CLA and add yourself to the authors list
  • Make sure you are making a pull request against the develop branch (not main). Also you should start your branch off develop
  • Add tests that prove your fix is effective or that your feature works
  • Add necessary documentation (if appropriate)

Thank you for contributing to SLEAP!

❤️

@ramizhajj1 ramizhajj1 requested a review from roomrys June 21, 2024 17:28
Copy link

coderabbitai bot commented Jun 21, 2024

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@ramizhajj1 ramizhajj1 changed the base branch from develop to liezl/add-gui-elements-for-sessions June 21, 2024 17:29
@roomrys roomrys added the MultiView Stack This PR is part of the MultView stacked PRs. label Jul 1, 2024
@roomrys roomrys changed the title Add feature Shift + 0 creates a new instance group and assign the selected instance Add feature Shift + num in (n_instance_groups, 9] creates a new instance group and assign the selected instance Jul 1, 2024
@roomrys roomrys changed the title Add feature Shift + num in (n_instance_groups, 9] creates a new instance group and assign the selected instance Create and assign instance group with Shift + num in (n_instance_groups, 9] Jul 1, 2024
Copy link
Collaborator

@roomrys roomrys left a comment

Choose a reason for hiding this comment

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

Change of task seeing as what we originally set out to do is already handled with:

sleap/sleap/gui/commands.py

Lines 2783 to 2784 in 5d120c6

# Now add the selected instance to the `InstanceGroup`
context.execute(SetSelectedInstanceGroup, instance_group=instance_group)

We want to make edits to this section of code ONLY:

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,
)

to link the remaining single digit numbers (that are not already being used to set an Instance to an existing InstanceGroup) to link to the single "New Instance Group" menu-item.

This is an untested replacement for above code:

from qtpy.QtGui import QKeySequence

action = QAction("New Instance Group", self)
action.setShortcuts([QKeySequence(Qt.SHIFT + Qt.Key_0)])
action.triggered.connect(self.commands.addInstanceGroup)

self.inst_groups_menu.addAction(action)

You may need to checkout the Qt documentation if that bit of code is non-functional.

Comment on lines +192 to +200
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)

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)

Comment on lines +848 to +853
self.inst_groups_menu.addAction(
"New Instance Group and Assign (Shift + 0)",
self.create_and_assign_instance_group,
Qt.SHIFT + Qt.Key_0
)

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
)

@roomrys
Copy link
Collaborator

roomrys commented Sep 5, 2024

The more I think about it, this feature actually does not seem like a good idea anymore. For e.g., if a user has 4 animals and starts to assign instance groups, but maybe accidentally skips from Ctrl + 2 to Ctrl + 4. Now... this was obviously a mistake, why else would the user go out of numerical order? Do we enforce the user's mistake and have hotkeys for Ctrl + 1, 2, and 4?

I think this is just going to propagate errors. Ctrl + 0 for a new track and then automatically following numerical order for assigning hotkeys is a pretty good approach (that is already imlemented).

@roomrys roomrys closed this Sep 5, 2024
@roomrys roomrys deleted the ramiz/add-feature-create-and-assign-instance branch September 5, 2024 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
MultiView Stack This PR is part of the MultView stacked PRs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants