-
Notifications
You must be signed in to change notification settings - Fork 96
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
Create and assign instance group with Shift + num
in (n_instance_groups
, 9
]
#1823
Conversation
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configration File (
|
num
in (n_instance_groups
, 9
] creates a new instance group and assign the selected instance
num
in (n_instance_groups
, 9
] creates a new instance group and assign the selected instancenum
in (n_instance_groups
, 9
]
There was a problem hiding this 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:
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:
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.
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) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- This should not be a method of
MainWindow
, it should be a command class in commands.py. - 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:
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)
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) |
self.inst_groups_menu.addAction( | ||
"New Instance Group and Assign (Shift + 0)", | ||
self.create_and_assign_instance_group, | ||
Qt.SHIFT + Qt.Key_0 | ||
) | ||
|
There was a problem hiding this comment.
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.
Lines 1506 to 1510 in 5d120c6
self.inst_groups_menu.addAction( | |
"New Instance Group", | |
self.commands.addInstanceGroup, | |
Qt.SHIFT + Qt.Key_0, | |
) |
self.inst_groups_menu.addAction( | |
"New Instance Group and Assign (Shift + 0)", | |
self.create_and_assign_instance_group, | |
Qt.SHIFT + Qt.Key_0 | |
) |
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 I think this is just going to propagate errors. |
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
Does this address any currently open issues?
[list open issues here]
Outside contributors checklist
Thank you for contributing to SLEAP!
❤️