Skip to content

Status

elva.widgets.status

Textual widgets for building a status bar.

Classes:

StatusBar

Bases: Grid

Main container of status widgets.

FeatureStatus(params, *args, config=None, rename=None, **kwargs)

Bases: Button

Button indicating the status of a feature.

Parameters:

  • params (list[str]) –

    list of configuration parameters associated with this feature.

  • config (None | dict[str, Any], default: None ) –

    mapping of configuration parameters to their values.

  • rename (None | dict[str, str], default: None ) –

    mapping of old parameter names to new parameter names.

  • args (tuple, default: () ) –

    positional arguments passed to Button.

  • kwargs (dict, default: {} ) –

    keyword arguments passed to Button.

Methods:

  • trim

    Trim and rename a given config with respect to the feature's configuration parameters.

  • update

    Update the internal configuration parameter mapping.

  • apply

    Hook called on mounting the widget and on configuration update.

  • on_mount

    Hook called on mounting the widget.

Attributes:

  • params (list[str]) –

    List of configuration parameters associated with this feature.

  • rename (None | dict[str, str]) –

    Mapping of old parameter names to new parameter names.

  • config (None | dict[str, Any]) –

    Mapping of configuration parameters to their values.

  • is_ready (bool) –

    Flag whether the feature is ready or not.

Source code in src/elva/widgets/status.py
def __init__(
    self,
    params: list[str],
    *args: tuple,
    config: None | dict[str, Any] = None,
    rename: None | dict[str, str] = None,
    **kwargs: dict,
):
    """
    Arguments:
        params: list of configuration parameters associated with this feature.
        config: mapping of configuration parameters to their values.
        rename: mapping of old parameter names to new parameter names.
        args: positional arguments passed to [`Button`][textual.widgets.Button].
        kwargs: keyword arguments passed to [`Button`][textual.widgets.Button].
    """
    super().__init__(*args, **kwargs)
    self.params = params
    self.rename = rename
    self.config = self.trim(config)

params = params instance-attribute

List of configuration parameters associated with this feature.

rename = rename instance-attribute

Mapping of old parameter names to new parameter names.

config = self.trim(config) instance-attribute

Mapping of configuration parameters to their values.

is_ready property

Flag whether the feature is ready or not.

It is supposed to hold the logic for determining the current status of the feature.

This property is defined as a no-op and supposed to be implemented in the inheriting class.

Returns:

  • bool

    True if the feature is ready, else False.

trim(config)

Trim and rename a given config with respect to the feature's configuration parameters.

Parameters:

  • config (dict[str, Any]) –

    mapping of configuration parameters to their values.

Returns:

  • dict[str, Any]

    trimmed and renamed configuration parameter mapping.

Source code in src/elva/widgets/status.py
def trim(self, config: dict[str, Any]) -> dict[str, Any]:
    """
    Trim and rename a given config with respect to the feature's configuration parameters.

    Arguments:
        config: mapping of configuration parameters to their values.

    Returns:
        trimmed and renamed configuration parameter mapping.
    """
    if config is not None:
        trimmed = dict((param, config.get(param)) for param in self.params)

        if self.rename is not None:
            for from_param, to_param in self.rename.items():
                trimmed[to_param] = trimmed.pop(from_param)

        return trimmed

update(config)

Update the internal configuration parameter mapping.

The given configuration gets trimmed, renamed and replaces the currently stored configuration if different.

Parameters:

  • config (dict[str, Any]) –

    mapping of configuration parameters to their values.

Source code in src/elva/widgets/status.py
def update(self, config: dict[str, Any]):
    """
    Update the internal configuration parameter mapping.

    The given configuration gets trimmed, renamed and replaces the currently stored configuration if different.

    Arguments:
        config: mapping of configuration parameters to their values.
    """
    trimmed = self.trim(config)
    changed = trimmed != self.config

    self.config = trimmed

    if changed:
        self.apply()

apply()

Hook called on mounting the widget and on configuration update.

It is supposed to hold the logic for a change in configuration parameters.

This method is defined as a no-op and supposed to be implemented in the inheriting class.

Source code in src/elva/widgets/status.py
def apply(self):
    """
    Hook called on mounting the widget and on configuration update.

    It is supposed to hold the logic for a change in configuration parameters.

    This method is defined as a no-op and supposed to be implemented in the inheriting class.
    """
    ...

on_mount()

Hook called on mounting the widget.

This method calls apply.

Source code in src/elva/widgets/status.py
def on_mount(self):
    """
    Hook called on mounting the widget.

    This method calls [`apply`][elva.widgets.status.FeatureStatus.apply].
    """
    self.apply()

ComponentStatus(yobject, params, *args, **kwargs)

Bases: FeatureStatus

Button indicating the status of a component.

Parameters:

  • yobject (Doc | Text | Array | Map) –

    instance of the Y object being used by the internal component.

  • params (list[str]) –

    list of configuration parameters associated with this component.

  • args (tuple, default: () ) –

    positional arguments passed to FeatureStatus.

  • kwargs (dict, default: {} ) –

    keyword arguments passed to FeatureStatus.

Methods:

  • apply

    Hook called on mounting the widget and on configuration update.

  • on_button_pressed

    Hook called on a pressed button event.

Attributes:

Source code in src/elva/widgets/status.py
def __init__(
    self,
    yobject: Doc | Text | Array | Map,
    params: list[str],
    *args: tuple,
    **kwargs: dict,
):
    """
    Arguments:
        yobject: instance of the Y object being used by the internal component.
        params: list of configuration parameters associated with this component.
        args: positional arguments passed to [`FeatureStatus`][elva.widgets.status.FeatureStatus].
        kwargs: keyword arguments passed to [`FeatureStatus`][elva.widgets.status.FeatureStatus].
    """
    self.yobject = yobject
    super().__init__(params, *args, **kwargs)

component instance-attribute

Instance of the component represented by this widget.

control instance-attribute

Alias for component.

yobject = yobject instance-attribute

Instance of the Y object being used by the internal component.

apply()

Hook called on mounting the widget and on configuration update.

This method starts the component if ready, else the component gets cancelled.

Source code in src/elva/widgets/status.py
def apply(self):
    """
    Hook called on mounting the widget and on configuration update.

    This method starts the component if ready, else the component gets cancelled.
    """
    if self.is_ready:
        component = self.component(self.yobject, **self.config)
        self.run_worker(
            component.start(), name="component", exclusive=True, exit_on_error=False
        )
        self.control = component
    else:
        self.workers.cancel_node(self)

on_button_pressed(message)

Hook called on a pressed button event.

Basically, it toggles to component's running state.

Parameters:

  • message (Message) –

    the message holding information about the pressed button event.

Source code in src/elva/widgets/status.py
def on_button_pressed(self, message: Message):
    """
    Hook called on a pressed button event.

    Basically, it toggles to component's running state.

    Arguments:
        message: the message holding information about the pressed button event.
    """
    if self.variant in ["success", "warning"]:
        self.workers.cancel_node(self)
    else:
        self.apply()