Code indexing in gitaly is broken and leads to code not being visible to the user. We work on the issue with highest priority.

Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • bec/bec_widgets
1 result
Show changes
Commits on Source (4)
......@@ -65,7 +65,7 @@ class RPCRegister:
return register._broadcast_on_hold
@broadcast_update
def add_rpc(self, rpc: QObject):
def add_rpc(self, rpc: BECConnector):
"""
Add an RPC object to the register.
......@@ -136,6 +136,18 @@ class RPCRegister:
for callback in self.callbacks:
callback(connections)
def object_is_registered(self, obj: BECConnector) -> bool:
"""
Check if an object is registered in the RPC register.
Args:
obj(QObject): The object to check.
Returns:
bool: True if the object is registered, False otherwise.
"""
return obj.gui_id in self._rpc_register
def add_callback(self, callback: Callable[[dict], None]):
"""
Add a callback that will be called whenever the registry is updated.
......
......@@ -93,12 +93,17 @@ class BECConnector:
# Ensure the parent is always the first argument for QObject
parent = kwargs.pop("parent", None)
# This initializes the QObject or any qt related class BECConnector has to be used from this line down with QObject, otherwise hierarchy logic will not work
# TODO do a proper check if the class is a QObject -> issue #475
super().__init__(parent=parent, **kwargs)
assert isinstance(
self, QObject
), "BECConnector must be used with a QObject or any qt related class."
# BEC related connections
self.bec_dispatcher = BECDispatcher(client=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.rpc_register = RPCRegister()
if not self.client in BECConnector.EXIT_HANDLERS:
# register function to clean connections at exit;
......@@ -132,7 +137,6 @@ class BECConnector:
else:
self.gui_id: str = self.config.gui_id # type: ignore
# TODO Hierarchy can be refreshed upon creation -> also registry should be notified if objectName changes -> issue #472
if object_name is not None:
self.setObjectName(object_name)
......@@ -148,10 +152,6 @@ class BECConnector:
if connector_parent is not None:
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
self.error_utility = ErrorPopupUtility()
......@@ -159,6 +159,18 @@ class BECConnector:
# Store references to running workers so they're not garbage collected prematurely.
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):
"""
Enforce that this BECConnector has a unique objectName among its siblings.
......@@ -203,6 +215,19 @@ class BECConnector:
break
counter += 1
# pylint: disable=invalid-name
def setObjectName(self, name: str) -> None:
"""
Set the object name of the widget.
Args:
name (str): The new object name.
"""
super().setObjectName(name)
self.object_name = name
if self.rpc_register.object_is_registered(self):
self.rpc_register.broadcast()
def submit_task(self, fn, *args, on_complete: pyqtSlot = None, **kwargs) -> Worker:
"""
Submit a task to run in a separate thread. The task will run the specified
......