-
Notifications
You must be signed in to change notification settings - Fork 101
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
Add option to group cameras from sessions #2125
base: liezl/add-gui-elements-for-sessions
Are you sure you want to change the base?
Add option to group cameras from sessions #2125
Conversation
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 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 using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAttention: Patch coverage is
❌ Your patch check has failed because the patch coverage (50.00%) is below the target coverage (100.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## liezl/add-gui-elements-for-sessions #2125 +/- ##
=======================================================================
- Coverage 74.18% 73.84% -0.35%
=======================================================================
Files 135 135
Lines 25450 25688 +238
=======================================================================
+ Hits 18881 18969 +88
- Misses 6569 6719 +150 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…com/talmolab/sleap into justin/group-cameras-from-sessions
…dd a camera to a camera group
SetCameraGroupName, AddCameraToGroup, and RemoveCameraFromGroup for creating, deleting, and managing camera groups
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.
A few things:
- If a method does not exist, instead of calling the method that doesn't exist, raise a
NotImplementedError
and add aTODO(JS)
. - Also, can we see some screenshots of the GUI elements in the PR.
- I would also like to see tests that hits each one of the methods you've created.
sleap/gui/dataviews.py
Outdated
# Mark project as changed | ||
self.context.changestack_push("rename camera 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.
While we want to call a self.context
method here, this is not the one (we haven't created the method we want to call yet).
# Mark project as changed | |
self.context.changestack_push("rename camera group") | |
# TODO(JS): Add `CommandContext` method that updates the camera group name | |
raise NotImplementedError |
sleap/gui/dataviews.py
Outdated
# Register for updates | ||
if context and hasattr(context, 'state'): | ||
context.state.connect("camera_groups", self.update_items) | ||
|
||
def update_items(self, camera_groups): | ||
"""Update the model when camera groups change.""" | ||
self.items = camera_groups | ||
self.beginResetModel() | ||
self.endResetModel() |
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.
Oh man, yeah I do kinda like this better than what we currently do:
Lines 1216 to 1220 in 6531447
if _has_topic([UpdateTopic.project, UpdateTopic.on_frame]): | |
self.instances_dock.table.model().items = self.state["labeled_frame"] | |
if _has_topic([UpdateTopic.suggestions]): | |
self.suggestions_dock.table.model().items = self.labels.suggestions |
. Let's leave it for now (and possibly open a new PR to refactor all the other table updates).
sleap/gui/widgets/docks.py
Outdated
if not camera: | ||
QMessageBox.information( | ||
self.main_window, | ||
"No Camera Selected", | ||
"Please select a camera to add to a group." | ||
) | ||
return |
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.
Instead of raising an error message, maybe we can just disable the button so no one can click on it if there is no camera selected. See this example for the "Link Video" button:
Lines 1191 to 1195 in d898a84
self._buttons["link video"].setEnabled( | |
has_selected_unlinked_video | |
and has_selected_camcorder | |
and has_selected_session | |
) |
.
if not camera: | |
QMessageBox.information( | |
self.main_window, | |
"No Camera Selected", | |
"Please select a camera to add to a group." | |
) | |
return |
sleap/gui/dataviews.py
Outdated
def __init__(self, items=None, context=None): | ||
super().__init__(items=items, context=context) |
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.
Expose the property kwarg:
def __init__(self, items=None, context=None): | |
super().__init__(items=items, context=context) | |
def __init__(self, items=None, properties=None, context=None): | |
super().__init__(items=items, properties=properties, context=context) |
sleap/gui/widgets/docks.py
Outdated
self.main_window, "New Camera Group", "Enter name for camera group:" | ||
) | ||
if ok and name: | ||
self.main_window.commands.addCameraGroup(name) |
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.
self.main_window.commands.addCameraGroup(name) | |
# TODO(JS): self.main_window.commands.addCameraGroup(name) | |
raise NotImplementedError |
sleap/gui/widgets/docks.py
Outdated
return | ||
|
||
# Get available groups | ||
if not self.main_window.state.get("camera_groups") or len(self.main_window.state["camera_groups"]) == 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.
GuiState
has a __getitem__
method, so we at least won't run into an error if the key doesn't exist.
Lines 52 to 54 in 6531447
def __getitem__(self, key: GSVarType) -> Any: | |
"""Gets value for key, or None if no value.""" | |
return self.get(key, default=None) |
How about we use get
, but with a default of an empty list:
if not self.main_window.state.get("camera_groups") or len(self.main_window.state["camera_groups"]) == 0: | |
if len(self.main_window.state.get("camera_groups", []) == 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.
ex:
In [20]: from sleap.gui.state import GuiState
In [21]: state = GuiState()
In [22]: state[3]
In [23]: state.get(3, [])
Out[23]: []
sleap/gui/widgets/docks.py
Outdated
def _add_camera_to_group(self): | ||
"""Add the selected camera to a group.""" | ||
camera = self.main_window.state.get("camera") | ||
if not camera: | ||
QMessageBox.information( | ||
self.main_window, | ||
"No Camera Selected", | ||
"Please select a camera to add to a group." | ||
) | ||
return | ||
|
||
# Get available groups | ||
if not self.main_window.state.get("camera_groups") or len(self.main_window.state["camera_groups"]) == 0: | ||
reply = QMessageBox.question( | ||
self.main_window, | ||
"No Groups", | ||
"No camera groups exist. Would you like to create one?", | ||
QMessageBox.Yes | QMessageBox.No, | ||
QMessageBox.Yes | ||
) | ||
if reply == QMessageBox.Yes: | ||
self._create_camera_group() | ||
return | ||
|
||
# Show group selection dialog | ||
group_names = [group.name for group in self.main_window.state["camera_groups"]] | ||
selected_name, ok = QInputDialog.getItem( | ||
self.main_window, | ||
"Select Group", | ||
"Choose a group to add the camera to:", | ||
group_names, | ||
0, | ||
False | ||
) | ||
|
||
if ok and selected_name: | ||
selected_idx = group_names.index(selected_name) | ||
selected_group = self.main_window.state["camera_groups"][selected_idx] | ||
self.main_window.commands.addCameraToGroup(camera, selected_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 entire method is a duplicate
def _add_camera_to_group(self): | |
"""Add the selected camera to a group.""" | |
camera = self.main_window.state.get("camera") | |
if not camera: | |
QMessageBox.information( | |
self.main_window, | |
"No Camera Selected", | |
"Please select a camera to add to a group." | |
) | |
return | |
# Get available groups | |
if not self.main_window.state.get("camera_groups") or len(self.main_window.state["camera_groups"]) == 0: | |
reply = QMessageBox.question( | |
self.main_window, | |
"No Groups", | |
"No camera groups exist. Would you like to create one?", | |
QMessageBox.Yes | QMessageBox.No, | |
QMessageBox.Yes | |
) | |
if reply == QMessageBox.Yes: | |
self._create_camera_group() | |
return | |
# Show group selection dialog | |
group_names = [group.name for group in self.main_window.state["camera_groups"]] | |
selected_name, ok = QInputDialog.getItem( | |
self.main_window, | |
"Select Group", | |
"Choose a group to add the camera to:", | |
group_names, | |
0, | |
False | |
) | |
if ok and selected_name: | |
selected_idx = group_names.index(selected_name) | |
selected_group = self.main_window.state["camera_groups"][selected_idx] | |
self.main_window.commands.addCameraToGroup(camera, selected_group) |
Description
This new feature allows users to group different camera angles into distinct groups, where upon exporting a training set, the user cab export all frames from a specific group.
Types of changes
Does this address any currently open issues?
[list open issues here]
Outside contributors checklist
Thank you for contributing to SLEAP!
❤️