1
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2026-04-14 12:40:54 +02:00

Compare commits

...

2 Commits

Author SHA1 Message Date
semantic-release
531d9c621d 2.3.0
Automatically generated by python-semantic-release
2025-05-09 12:36:13 +00:00
dc151cdfe3 feat(bec_connector): ability to change object name during runtime 2025-05-09 14:27:44 +02:00
4 changed files with 69 additions and 1 deletions

View File

@@ -1,6 +1,14 @@
# CHANGELOG
## v2.3.0 (2025-05-09)
### Features
- **bec_connector**: Ability to change object name during runtime
([`dc151cd`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/dc151cdfe39f1f0507eeee307a35c1677ae4d8c5))
## v2.2.0 (2025-05-09)
### Features

View File

@@ -205,6 +205,17 @@ class BECConnector:
f"This is not necessarily an error as the parent may be deleted before the child and includes already a cleanup. The following exception was raised:\n{content}"
)
def change_object_name(self, name: str) -> None:
"""
Change the object name of the widget. Unregister old name and register the new one.
Args:
name (str): The new object name.
"""
self.rpc_register.remove_rpc(self)
self.setObjectName(name.replace("-", "_").replace(" ", "_"))
QTimer.singleShot(0, self._update_object_name)
def _update_object_name(self) -> None:
"""
Enforce a unique object name among siblings and register the object for RPC.

View File

@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
[project]
name = "bec_widgets"
version = "2.2.0"
version = "2.3.0"
description = "BEC Widgets"
requires-python = ">=3.10"
classifiers = [

View File

@@ -82,3 +82,52 @@ def test_bec_connector_submit_task(bec_connector):
while not completed:
QApplication.processEvents()
time.sleep(0.1)
def test_bec_connector_change_object_name(bec_connector):
# Store the original object name and RPC register state
original_name = bec_connector.objectName()
original_gui_id = bec_connector.gui_id
# Call the method with a new name
new_name = "new_test_name"
bec_connector.change_object_name(new_name)
# Process events to allow the single shot timer to execute
QApplication.processEvents()
# Verify that the object name was changed correctly
assert bec_connector.objectName() == new_name
assert bec_connector.object_name == new_name
# Verify that the object is registered in the RPC register with the new name
assert bec_connector.rpc_register.object_is_registered(bec_connector)
# Verify that the object with the original name is no longer registered
# The object should still have the same gui_id
assert bec_connector.gui_id == original_gui_id
# Check that no object with the original name exists in the RPC register
all_objects = bec_connector.rpc_register.list_all_connections().values()
assert not any(obj.objectName() == original_name for obj in all_objects)
# Store the current name for the next test
previous_name = bec_connector.objectName()
# Test with spaces and hyphens
name_with_spaces_and_hyphens = "test name-with-hyphens"
expected_name = "test_name_with_hyphens"
bec_connector.change_object_name(name_with_spaces_and_hyphens)
# Process events to allow the single shot timer to execute
QApplication.processEvents()
# Verify that the object name was changed correctly with replacements
assert bec_connector.objectName() == expected_name
assert bec_connector.object_name == expected_name
# Verify that the object is still registered in the RPC register after the second name change
assert bec_connector.rpc_register.object_is_registered(bec_connector)
# Verify that the object with the previous name is no longer registered
all_objects = bec_connector.rpc_register.list_all_connections().values()
assert not any(obj.objectName() == previous_name for obj in all_objects)