pyqt_reactive.forms.widget_registry

Widget registry with metaclass auto-registration.

Mirrors StorageBackendMeta pattern - widgets auto-register when their classes are defined, eliminating manual registration boilerplate.

Design: - WidgetMeta metaclass handles auto-registration - WIDGET_IMPLEMENTATIONS: Global registry of all widget types - WIDGET_CAPABILITIES: Tracks which ABCs each widget implements - Fail-loud if widget missing _widget_id or abstract methods

Functions

get_widget_capabilities(widget_class)

Get the ABCs that a widget class implements.

get_widget_class(widget_id)

Get widget class by ID.

list_widgets_with_capability(capability)

Find all widgets that implement a specific ABC.

Classes

WidgetMeta(name, bases, attrs)

Metaclass for automatic widget registration.

class pyqt_reactive.forms.widget_registry.WidgetMeta(name, bases, attrs)[source]

Metaclass for automatic widget registration.

Mirrors StorageBackendMeta pattern: 1. Only registers concrete implementations (no abstract methods) 2. Requires _widget_id attribute for identification 3. Auto-populates WIDGET_IMPLEMENTATIONS registry 4. Tracks capabilities (which ABCs implemented)

Example

class LineEditAdapter(QLineEdit, ValueGettable, ValueSettable,

metaclass=WidgetMeta):

_widget_id = “line_edit”

def get_value(self) -> Any:

return self.text()

def set_value(self, value: Any) -> None:

self.setText(str(value) if value is not None else “”)

The widget auto-registers in WIDGET_IMPLEMENTATIONS[“line_edit”] when the class is defined.

pyqt_reactive.forms.widget_registry.get_widget_class(widget_id: str) Type[source]

Get widget class by ID.

Parameters:

widget_id – The widget identifier (e.g., “line_edit”)

Returns:

The widget class

Raises:

KeyError – If widget_id not registered

pyqt_reactive.forms.widget_registry.get_widget_capabilities(widget_class: Type) Set[Type][source]

Get the ABCs that a widget class implements.

Parameters:

widget_class – The widget class to query

Returns:

Set of ABC classes the widget implements

pyqt_reactive.forms.widget_registry.list_widgets_with_capability(capability: Type) list[Type][source]

Find all widgets that implement a specific ABC.

Parameters:

capability – The ABC class to search for (e.g., ValueGettable)

Returns:

List of widget classes implementing the ABC

Example

>>> from pyqt_reactive.protocols import PlaceholderCapable
>>> widgets = list_widgets_with_capability(PlaceholderCapable)
>>> print([w.__name__ for w in widgets])
['LineEditAdapter', 'SpinBoxAdapter', 'ComboBoxAdapter']