@@ -100,7 +100,7 @@ def connect_change_signal(self, widget: QComboBox, slot):
100100
101101
102102class DeviceComboBoxHandler (ComboBoxHandler ):
103- """Handler for BEC device comboboxes."""
103+ """Handler for BEC device comboboxes. The widget value is the device name. """
104104
105105 def get_value (self , widget , ** kwargs ) -> str :
106106 return widget .currentText ().strip ()
@@ -119,7 +119,7 @@ def connect_change_signal(self, widget, slot):
119119
120120
121121class SignalComboBoxHandler (ComboBoxHandler ):
122- """Handler for BEC signal comboboxes."""
122+ """Handler for BEC signal comboboxes. The widget value is the signal object name. """
123123
124124 def get_value (self , widget , ** kwargs ) -> str | None :
125125 signal = widget .get_signal_name ().strip ()
@@ -246,14 +246,28 @@ class WidgetIO:
246246 ToggleSwitch : ToggleSwitchHandler ,
247247 QSlider : SlideHandler ,
248248 }
249+ _deferred_handlers_registered = False
249250
250251 @classmethod
251- def register_handler (cls , widget_class : type [ QWidget ], handler : type [ WidgetHandler ] ) -> None :
252+ def _register_deferred_handlers (cls ) -> None :
252253 """
253- Register a handler for a widget class. Widget modules that cannot be imported here
254- (e.g. to avoid circular imports) register their handlers on import.
254+ Register handlers for widgets that import this module themselves and therefore
255+ cannot be imported here at module level without a circular import. The import is
256+ deferred to the first handler lookup, when all modules are fully initialized.
255257 """
256- cls ._handlers [widget_class ] = handler
258+ if cls ._deferred_handlers_registered :
259+ return
260+ cls ._deferred_handlers_registered = True
261+ # pylint: disable=import-outside-toplevel
262+ from bec_widgets .widgets .control .device_input .device_combobox .device_combobox import (
263+ DeviceComboBox ,
264+ )
265+ from bec_widgets .widgets .control .device_input .signal_combobox .signal_combobox import (
266+ SignalComboBox ,
267+ )
268+
269+ cls ._handlers [DeviceComboBox ] = DeviceComboBoxHandler
270+ cls ._handlers [SignalComboBox ] = SignalComboBoxHandler
257271
258272 @staticmethod
259273 def get_value (widget , ignore_errors = False , ** kwargs ):
@@ -329,18 +343,7 @@ def _find_handler(widget):
329343 Returns:
330344 handler_class: The handler class if found, otherwise None.
331345 """
332- if (
333- isinstance (widget , QComboBox )
334- and hasattr (widget , "set_signal" )
335- and hasattr (widget , "get_signal_name" )
336- ):
337- return SignalComboBoxHandler
338- if (
339- isinstance (widget , QComboBox )
340- and hasattr (widget , "set_device" )
341- and hasattr (widget , "device_selected" )
342- ):
343- return DeviceComboBoxHandler
346+ WidgetIO ._register_deferred_handlers ()
344347 for base in type (widget ).__mro__ :
345348 if base in WidgetIO ._handlers :
346349 return WidgetIO ._handlers [base ]
0 commit comments