-
Notifications
You must be signed in to change notification settings - Fork 20
feat: add renaming frames functionality, fix: crash when trying to delete a group #51
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
base: noetic-devel
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -116,6 +116,7 @@ def create_main_widget(self): | |
| ## | ||
| widget.btn_add.clicked.connect(self.btn_add_clicked) | ||
| widget.btn_delete.clicked.connect(self.btn_delete_clicked) | ||
| widget.btn_rename.clicked.connect(self.btn_rename_clicked) | ||
| widget.btn_duplicate.clicked.connect(self.btn_duplicate_clicked) | ||
| widget.list_frames.currentItemChanged.connect(self.selected_frame_changed) | ||
| widget.list_tf.currentItemChanged.connect(self.update_measurement) | ||
|
|
@@ -151,6 +152,7 @@ def create_main_widget(self): | |
| widget.txt_c.editingFinished.connect(self.c_valueChanged) | ||
|
|
||
| widget.txt_group.editingFinished.connect(self.group_valueChanged) | ||
| widget.txt_name.editingFinished.connect(self.frameName_valueChanged) | ||
|
|
||
| widget.btn_rad.toggled.connect(self.update_fields) | ||
|
|
||
|
|
@@ -559,6 +561,24 @@ def btn_duplicate_clicked(self, checked): | |
|
|
||
| self.editor.command(Command_CopyElement(self.editor, name, source_name, parent_name)) | ||
| self.signal_update_tf.emit(False, False) | ||
|
|
||
| @Slot(bool) | ||
| def btn_rename_clicked(self, checked): | ||
| item = self.widget.list_frames.currentItem() | ||
| if not item: | ||
| return | ||
|
|
||
| # Check if the item is a frame. Early returns if selected item is not a frame (e.g. a group) | ||
| source_name = item.text(0) | ||
| if self.editor.frames.get(source_name) is None: | ||
| return | ||
|
|
||
| new_name = self.get_valid_frame_name("Rename Frame", default_name=source_name) | ||
| if not new_name: | ||
| return | ||
|
|
||
| self.editor.command(Command_RenameElement(self.editor, self.editor.frames[source_name], new_name)) | ||
| self.signal_update_tf.emit(True, True) | ||
|
|
||
| def get_sleep_time(self): | ||
| return max(5.0 / self.editor.hz, 0.1) | ||
|
|
@@ -585,7 +605,13 @@ def btn_delete_clicked(self, checked): | |
| item = self.widget.list_frames.currentItem() | ||
| if not item: | ||
| return | ||
| self.editor.command(Command_RemoveElement(self.editor, self.editor.frames[item.text(0)])) | ||
|
|
||
| # Check if the item is a frame. Early returns if selected item is not a frame (e.g. a group) | ||
| source_name = item.text(0) | ||
| if self.editor.frames.get(source_name) is None: | ||
| return | ||
|
|
||
| self.editor.command(Command_RemoveElement(self.editor, self.editor.frames[source_name])) | ||
| self.signal_update_tf.emit(True, True) | ||
|
|
||
| ## PARENTING ## | ||
|
|
@@ -714,7 +740,26 @@ def group_valueChanged(self): | |
| if self.editor.active_frame.group != value: | ||
| self.editor.command(Command_SetGroup(self.editor, self.editor.active_frame, value)) | ||
|
|
||
| @Slot() | ||
| def frameName_valueChanged(self): | ||
| item = self.widget.list_frames.currentItem() | ||
| if not item: | ||
| return | ||
| source_name = item.text(0) | ||
|
|
||
| new_name = self.widget.txt_name.text() | ||
| existing_tf_frames = set(self.editor.all_frame_ids()) | ||
| existing_editor_frames = set(self.editor.all_editor_frame_ids()) | ||
|
Comment on lines
+751
to
+752
Collaborator
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. i dont think it is required to make them into a set if you just check if an element is in the list 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. Still Open. |
||
|
|
||
| # allow recreating if frame was published by frameditor node originally | ||
| if source_name != new_name and (new_name in existing_editor_frames or (new_name in existing_tf_frames and not Frame.was_published_by_frameeditor(new_name))): | ||
| self.widget.txt_name.setText(source_name) | ||
| QtWidgets.QMessageBox.warning(self.widget, "Invalid Frame Name", | ||
| f"The frame name {new_name} already exists. Cannot create a new frame with the same name.") | ||
| return None | ||
|
|
||
| self.editor.command(Command_RenameElement(self.editor, self.editor.frames[source_name], new_name)) | ||
| self.signal_update_tf.emit(True, True) | ||
|
|
||
| ## FRAME STYLE ## | ||
| ## | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| string source_name | ||
| string new_name | ||
| --- | ||
| int32 error_code |
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.
could you specify the exception a bit more? I think here it should be key and attribute errors
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.
Done. I added the
AttributeErrorexception when the dictionary entry cannot be found. The general exception is still there in case I missed something.