From 77f9d425765061f137c997062a3bf769a939bc64 Mon Sep 17 00:00:00 2001 From: appel_c Date: Thu, 24 Apr 2025 14:52:42 +0200 Subject: [PATCH] fix: unique name for widgets, fix new method for docks; closes #534 --- bec_widgets/widgets/containers/dock/dock.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/bec_widgets/widgets/containers/dock/dock.py b/bec_widgets/widgets/containers/dock/dock.py index 20b74c42..1ffd9f7d 100644 --- a/bec_widgets/widgets/containers/dock/dock.py +++ b/bec_widgets/widgets/containers/dock/dock.py @@ -12,6 +12,7 @@ from bec_widgets.cli.rpc.rpc_widget_handler import widget_handler from bec_widgets.utils import ConnectionConfig, GridLayoutManager from bec_widgets.utils.bec_widget import BECWidget from bec_widgets.utils.container_utils import WidgetContainerUtils +from bec_widgets.utils.error_popups import SafeSlot logger = bec_logger.logger @@ -279,6 +280,7 @@ class BECDock(BECWidget, Dock): widgets.extend(dock.elements.keys()) return widgets + @SafeSlot(popup_error=True) def new( self, widget: BECWidget | str, @@ -301,6 +303,13 @@ class BECDock(BECWidget, Dock): colspan(int): The number of columns the widget should span. shift(Literal["down", "up", "left", "right"]): The direction to shift the widgets if the position is occupied. """ + if name is not None: + if not WidgetContainerUtils.has_name_valid_chars(name): + raise ValueError( + f"Name {name} contains invalid characters. " + f"Only alphanumeric characters and underscores are allowed." + ) + if row is None: row = self.layout.rowCount()