0
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-07-13 19:21:50 +02:00

fix(bec_connector): move RPC registration into single shot method to ensure the rpc name is in sync

This commit is contained in:
2025-04-12 19:22:14 +02:00
parent 4381fcc4c2
commit 3b16c9f5a2

View File

@ -99,6 +99,7 @@ class BECConnector:
self.bec_dispatcher = BECDispatcher(client=client) self.bec_dispatcher = BECDispatcher(client=client)
self.client = self.bec_dispatcher.client if client is None else client self.client = self.bec_dispatcher.client if client is None else client
self._parent_dock = parent_dock # TODO also remove at some point -> issue created #473 self._parent_dock = parent_dock # TODO also remove at some point -> issue created #473
self.rpc_register = RPCRegister()
if not self.client in BECConnector.EXIT_HANDLERS: if not self.client in BECConnector.EXIT_HANDLERS:
# register function to clean connections at exit; # register function to clean connections at exit;
@ -148,10 +149,6 @@ class BECConnector:
if connector_parent is not None: if connector_parent is not None:
self.parent_id = connector_parent.gui_id self.parent_id = connector_parent.gui_id
QTimer.singleShot(0, self._enforce_unique_sibling_name)
self.rpc_register = RPCRegister()
self.rpc_register.add_rpc(self)
# Error popups # Error popups
self.error_utility = ErrorPopupUtility() self.error_utility = ErrorPopupUtility()
@ -159,6 +156,18 @@ class BECConnector:
# Store references to running workers so they're not garbage collected prematurely. # Store references to running workers so they're not garbage collected prematurely.
self._workers = [] self._workers = []
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.
This method is called through a single shot timer kicked off in the constructor.
"""
# 1) Enforce unique objectName among siblings with the same BECConnector parent
self._enforce_unique_sibling_name()
# 2) Register the object for RPC
self.rpc_register.add_rpc(self)
def _enforce_unique_sibling_name(self): def _enforce_unique_sibling_name(self):
""" """
Enforce that this BECConnector has a unique objectName among its siblings. Enforce that this BECConnector has a unique objectName among its siblings.