Skip to content

Body Registry API

Source: ui/body_registry.py

Shared access to active shell bodies when navigation or search needs to reuse existing tile containers. See the Body registry concept.

Store shared tile bodies used by home and export screens (and in-place search).

BodyRegistry

Process-wide registry for reusable home and export tile containers.

Source code in src/learning_app/ui/body_registry.py
class BodyRegistry:
    """Process-wide registry for reusable home and export tile containers."""

    _home: TilesContainer | None = None
    _export: TilesContainer | None = None

    @classmethod
    def set_home(cls, body: TilesContainer):
        """Register the tile container used by the home route.

        Args:
            body: Home tile container to retain.
        """
        cls._home = body

    @classmethod
    def get_home(cls) -> TilesContainer:
        """Return the registered home tile container.

        Returns:
            The current home tile container.

        Raises:
            AssertionError: If no home body has been registered.
        """
        assert cls._home is not None, "Home body is not set"
        return cls._home

    @classmethod
    def has_home(cls) -> bool:
        """Return whether a home tile container is registered.

        Returns:
            ``True`` when a home body is available.
        """
        return cls._home is not None

    @classmethod
    def set_export(cls, body: TilesContainer):
        """Register the tile container used by the export workflow.

        Args:
            body: Export tile container to retain.
        """
        cls._export = body

    @classmethod
    def get_export(cls) -> TilesContainer:
        """Return the registered export tile container.

        Returns:
            The current export tile container.

        Raises:
            AssertionError: If no export body has been registered.
        """
        assert cls._export is not None, "Export body is not set"
        return cls._export

    @classmethod
    def has_export(cls) -> bool:
        """Return whether an export tile container is registered.

        Returns:
            ``True`` when an export body is available.
        """
        return cls._export is not None

set_home classmethod

set_home(body: TilesContainer)

Register the tile container used by the home route.

Parameters:

Name Type Description Default
body TilesContainer

Home tile container to retain.

required
Source code in src/learning_app/ui/body_registry.py
@classmethod
def set_home(cls, body: TilesContainer):
    """Register the tile container used by the home route.

    Args:
        body: Home tile container to retain.
    """
    cls._home = body

get_home classmethod

get_home() -> TilesContainer

Return the registered home tile container.

Returns:

Type Description
TilesContainer

The current home tile container.

Raises:

Type Description
AssertionError

If no home body has been registered.

Source code in src/learning_app/ui/body_registry.py
@classmethod
def get_home(cls) -> TilesContainer:
    """Return the registered home tile container.

    Returns:
        The current home tile container.

    Raises:
        AssertionError: If no home body has been registered.
    """
    assert cls._home is not None, "Home body is not set"
    return cls._home

has_home classmethod

has_home() -> bool

Return whether a home tile container is registered.

Returns:

Type Description
bool

True when a home body is available.

Source code in src/learning_app/ui/body_registry.py
@classmethod
def has_home(cls) -> bool:
    """Return whether a home tile container is registered.

    Returns:
        ``True`` when a home body is available.
    """
    return cls._home is not None

set_export classmethod

set_export(body: TilesContainer)

Register the tile container used by the export workflow.

Parameters:

Name Type Description Default
body TilesContainer

Export tile container to retain.

required
Source code in src/learning_app/ui/body_registry.py
@classmethod
def set_export(cls, body: TilesContainer):
    """Register the tile container used by the export workflow.

    Args:
        body: Export tile container to retain.
    """
    cls._export = body

get_export classmethod

get_export() -> TilesContainer

Return the registered export tile container.

Returns:

Type Description
TilesContainer

The current export tile container.

Raises:

Type Description
AssertionError

If no export body has been registered.

Source code in src/learning_app/ui/body_registry.py
@classmethod
def get_export(cls) -> TilesContainer:
    """Return the registered export tile container.

    Returns:
        The current export tile container.

    Raises:
        AssertionError: If no export body has been registered.
    """
    assert cls._export is not None, "Export body is not set"
    return cls._export

has_export classmethod

has_export() -> bool

Return whether an export tile container is registered.

Returns:

Type Description
bool

True when an export body is available.

Source code in src/learning_app/ui/body_registry.py
@classmethod
def has_export(cls) -> bool:
    """Return whether an export tile container is registered.

    Returns:
        ``True`` when an export body is available.
    """
    return cls._export is not None