-
Notifications
You must be signed in to change notification settings - Fork 103
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?
Changes from 9 commits
ffe5582
3023b10
23c9dd6
16c7d88
0b963be
7182b07
e646a92
fca9e8f
baa283b
5ce4bc4
3844141
d61ea3c
4233131
8bb6b99
b508503
1292cdc
c0c28a4
ca06614
d6bf553
695500d
0cc94e6
83e2dff
b16c1af
1032c83
6836608
07de332
271ddf1
74c7160
b9ce559
8de15b0
9e6a698
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -683,6 +683,40 @@ def item_to_data(self, obj: RecordingSession, item: Camcorder): | |||||||||||
video = obj.get_video(item) | ||||||||||||
return {"camera": item.name, "video": video.filename if video else ""} | ||||||||||||
|
||||||||||||
class CameraGroupsTableModel(GenericTableModel): | ||||||||||||
"""Table model for camera groups.""" | ||||||||||||
|
||||||||||||
properties = ("name", "cameras") | ||||||||||||
|
||||||||||||
def __init__(self, items=None, context=None): | ||||||||||||
super().__init__(items=items, context=context) | ||||||||||||
# 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 commentThe 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
. Let's leave it for now (and possibly open a new PR to refactor all the other table updates). |
||||||||||||
|
||||||||||||
def object_to_items(self, obj): | ||||||||||||
return obj | ||||||||||||
|
||||||||||||
def item_to_data(self, obj, item): | ||||||||||||
return { | ||||||||||||
"name": item.name, | ||||||||||||
"cameras": len(item.cameras) | ||||||||||||
} | ||||||||||||
|
||||||||||||
def can_set(self, item, key): | ||||||||||||
return key == "name" | ||||||||||||
|
||||||||||||
def set_item(self, item, key, value): | ||||||||||||
if key == "name" and value: | ||||||||||||
item.name = value | ||||||||||||
# Mark project as changed | ||||||||||||
self.context.changestack_push("rename camera group") | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While we want to call a
Suggested change
|
||||||||||||
|
||||||||||||
class InstanceGroupTableModel(GenericTableModel): | ||||||||||||
"""Table model for displaying all instance groups in a given frame. | ||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -20,6 +20,8 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
QTabWidget, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
QVBoxLayout, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
QWidget, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
QInputDialog, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
QMessageBox, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
from sleap.gui.dataviews import ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -34,6 +36,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
CamerasTableModel, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
SessionsTableModel, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
InstanceGroupTableModel, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
CameraGroupsTableModel, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
from sleap.io.cameras import RecordingSession, FrameGroup, InstanceGroup | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
from sleap.gui.dialogs.formbuilder import YamlFormWidget | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -584,13 +587,15 @@ def __init__( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.sessions_model_type = SessionsTableModel | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.camera_model_type = CamerasTableModel | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.unlinked_videos_model_type = VideosTableModel | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.camera_groups_model_type = CameraGroupsTableModel | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
super().__init__( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
name="Sessions", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
main_window=main_window, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
model_type=[ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.sessions_model_type, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.camera_model_type, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.unlinked_videos_model_type, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.camera_groups_model_type, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
tab_with=tab_with, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -625,10 +630,52 @@ def create_video_unlink_button(self) -> QWidget: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
hb, "Unlink Video", main_window.commands.unlink_video_from_camera | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.add_button(hb, "Add to Group", self._add_camera_to_group) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
hbw = QWidget() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
hbw.setLayout(hb) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return hbw | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# 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 commentThe reason will be displayed to describe this comment to others. Learn more.
Lines 52 to 54 in 6531447
How about we use
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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]: [] |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def create_video_link_button(self) -> QWidget: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
main_window = self.main_window | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -650,11 +697,15 @@ def create_models(self) -> Union[GenericTableModel, Dict[str, GenericTableModel] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.unlinked_videos_model = self.unlinked_videos_model_type( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
items=main_window.state["selected_session"], context=main_window.commands | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.camera_groups_model = self.camera_groups_model_type( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
items=main_window.state.get("camera_groups", []), context=main_window.commands | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.model = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"sessions_model": self.sessions_model, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"camera_model": self.camera_model, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"unlink_videos_model": self.unlinked_videos_model, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"camera_groups_model": self.camera_groups_model, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return self.model | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -681,6 +732,14 @@ def create_tables(self) -> Union[GenericTableView, Dict[str, GenericTableView]]: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ellipsis_left=True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Create camera groups table | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.camera_groups_table = GenericTableView( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
is_activatable=True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
state=main_window.state, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
row_name="selected_camera_group", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
model=self.camera_groups_model, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.main_window.state.connect( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"selected_session", self.main_window.update_cameras_model | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -689,10 +748,15 @@ def create_tables(self) -> Union[GenericTableView, Dict[str, GenericTableView]]: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"selected_session", self.main_window.update_unlinked_videos_model | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.main_window.state.connect( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"camera_groups", self._update_camera_groups_model | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.table = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"sessions_table": self.sessions_table, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"camera_table": self.camera_table, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"unlinked_videos_table": self.unlinked_videos_table, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"camera_groups_table": self.camera_groups_table, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return self.table | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -736,6 +800,124 @@ def lay_everything_out(self) -> None: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
video_link_button = self.create_video_link_button() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.wgt_layout.addWidget(video_link_button) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
camera_groups_container = self.create_camera_groups_table() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.wgt_layout.addWidget(camera_groups_container) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def create_camera_groups_table(self) -> QWidget: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"""Create the camera groups table and buttons.""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
main_window = self.main_window | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Create a container widget with a title | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
container = QGroupBox("Camera Groups") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
container_layout = QVBoxLayout() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
container.setLayout(container_layout) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Create the camera groups table | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if not hasattr(self, 'camera_groups_model') or self.camera_groups_model is None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Create the model if it doesn't exist | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.camera_groups_model = self.camera_groups_model_type( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
items=main_window.state.get("camera_groups", []), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
context=main_window.commands | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Create the camera groups table | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.camera_groups_table = GenericTableView( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
is_activatable=True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
state=main_window.state, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
row_name="selected_camera_group", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
model=self.camera_groups_model, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
container_layout.addWidget(self.camera_groups_table) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Create buttons for camera groups | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
hb = QHBoxLayout() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.add_button(hb, "Create Group", self._create_camera_group) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.add_button(hb, "Delete Group", self._delete_camera_group) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
hbw = QWidget() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
hbw.setLayout(hb) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
container_layout.addWidget(hbw) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Connect state changes to model updates | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
main_window.state.connect("camera_groups", self._update_camera_groups_model) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return container | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def _update_camera_groups_model(self, camera_groups): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"""Update the camera groups model when the state changes.""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if hasattr(self, 'camera_groups_model') and self.camera_groups_model: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.camera_groups_model.items = camera_groups | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.camera_groups_model.beginResetModel() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.camera_groups_model.endResetModel() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
print(f"Updated camera groups model with {len(camera_groups)} groups") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def create_add_to_group_button(self) -> QWidget: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"""Create the 'Add to Group' button.""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
hb = QHBoxLayout() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.add_button(hb, "Add to Group", self._add_camera_to_group) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
hbw = QWidget() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
hbw.setLayout(hb) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return hbw | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def _create_camera_group(self): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"""Create a new camera group.""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
name, ok = QInputDialog.getText( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Force update the table | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if hasattr(self, 'camera_groups_table') and self.camera_groups_table: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.camera_groups_table.model().beginResetModel() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.camera_groups_table.model().endResetModel() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def _delete_camera_group(self): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"""Delete the selected camera group.""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
camera_group = self.main_window.state["selected_camera_group"] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if camera_group: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.main_window.commands.deleteCameraGroup(camera_group) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more. This entire method is a duplicate
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
class InstanceGroupDock(DockWidget): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"""Dock widget for displaying instance 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.
Expose the property kwarg: