1
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2026-03-08 09:47:48 +01:00

fix: remove singleShots from BECConnector and adjustments of dock area logic

This commit is contained in:
2026-01-26 13:08:50 +01:00
parent 6113debc6c
commit e26a90c62f
2 changed files with 22 additions and 11 deletions

View File

@@ -186,7 +186,7 @@ class BECConnector:
# If set to True, the parent_id will be always set to None, thus enforcing that the widget is accessible as a root widget of the BECGuiClient object.
self.root_widget = root_widget
QTimer.singleShot(0, self._update_object_name)
self._update_object_name()
@property
def parent_id(self) -> str | None:
@@ -207,7 +207,7 @@ class BECConnector:
"""
self.rpc_register.remove_rpc(self)
self.setObjectName(name.replace("-", "_").replace(" ", "_"))
QTimer.singleShot(0, self._update_object_name)
self._update_object_name()
def _update_object_name(self) -> None:
"""
@@ -220,7 +220,8 @@ class BECConnector:
self.rpc_register.add_rpc(self)
try:
self.name_established.emit(self.object_name)
except RuntimeError:
except RuntimeError as e:
logger.warning(f"Error emitting name_established signal: {e}")
return
def _enforce_unique_sibling_name(self):
@@ -234,7 +235,6 @@ class BECConnector:
if not shb.isValid(self):
return
QApplication.sendPostedEvents()
parent_bec = WidgetHierarchy._get_becwidget_ancestor(self)
if parent_bec:

View File

@@ -6,7 +6,7 @@ from typing import Any, Callable, Literal, Mapping, Sequence, cast
from bec_lib import bec_logger
from bec_qthemes import material_icon
from qtpy.QtCore import QByteArray, QSettings, Qt, QTimer
from qtpy.QtCore import QByteArray, QSettings, QSize, Qt, QTimer
from qtpy.QtGui import QIcon
from qtpy.QtWidgets import QApplication, QDialog, QVBoxLayout, QWidget
from shiboken6 import isValid
@@ -302,6 +302,13 @@ class DockAreaWidget(BECWidget, QWidget):
dock = CDockWidget(self.dock_manager, widget.objectName(), self)
dock.setWidget(widget)
widget_min_size = widget.minimumSize()
widget_min_hint = widget.minimumSizeHint()
dock_min_size = QSize(
max(widget_min_size.width(), widget_min_hint.width()),
max(widget_min_size.height(), widget_min_hint.height()),
)
dock.setMinimumSize(dock_min_size)
dock._dock_preferences = dict(dock_preferences or {})
dock.setFeature(CDockWidget.DockWidgetFeature.DockWidgetDeleteOnClose, True)
dock.setFeature(CDockWidget.DockWidgetFeature.CustomCloseHandling, True)
@@ -324,7 +331,9 @@ class DockAreaWidget(BECWidget, QWidget):
if hasattr(widget, "widget_removed"):
widget.widget_removed.connect(on_widget_destroyed)
dock.setMinimumSizeHintMode(CDockWidget.eMinimumSizeHintMode.MinimumSizeHintFromDockWidget)
dock.setMinimumSizeHintMode(
CDockWidget.eMinimumSizeHintMode.MinimumSizeHintFromDockWidgetMinimumSize
)
dock_area_widget = None
if tab_with is not None:
if not isValid(tab_with):
@@ -1302,11 +1311,13 @@ class DockAreaWidget(BECWidget, QWidget):
apply_widget_icon=apply_widget_icon,
)
def _on_name_established(_name: str) -> None:
# Defer creation so BECConnector sibling name enforcement has completed.
QTimer.singleShot(0, lambda: self._create_dock_from_spec(spec))
widget.name_established.connect(_on_name_established)
# def _on_name_established(_name: str) -> None:
# # Defer creation so BECConnector sibling name enforcement has completed.
# QTimer.singleShot(0, lambda: self._create_dock_from_spec(spec))
# print(f"[BasicDockArea] Deferred dock creation for '{_name}'")
#
# widget.name_established.connect(_on_name_established)
self._create_dock_from_spec(spec)
return widget
spec = self._build_creation_spec(