Skip to content

Awareness

elva.widgets.awareness

Textual widgets for displaying awareness states.

Classes:

  • ClientView

    Widget defining the view of a singular awareness state.

  • AwarenessView

    Container representing all awareness states.

ClientView

Bases: Static

Widget defining the view of a singular awareness state.

AwarenessView

Bases: VerticalScroll

Container representing all awareness states.

Methods:

  • compose

    Hook adding child widgets.

  • get_client_view

    Get the client view for a singular awareness state.

Attributes:

BORDER_TITLE = 'Clients' class-attribute instance-attribute

The default border title.

DEFAULT_CSS = '\n AwarenessView {\n * {\n padding: 0 0 1 0;\n }\n }\n ' class-attribute instance-attribute

Default CSS.

states = reactive(tuple, recompose=True) class-attribute instance-attribute

Attribute holding the awareness states.

It causes a recompose of this widget on being changed.

compose()

Hook adding child widgets.

Source code in src/elva/widgets/awareness.py
def compose(self):
    """
    Hook adding child widgets.
    """
    if self.states:
        state, *other_states = self.states
        yield self.get_client_view(state, local=True)

        for state in other_states:
            yield self.get_client_view(state)

get_client_view(state, local=False)

Get the client view for a singular awareness state.

Parameters:

  • state (tuple[int, dict]) –

    a tuple from the awareness states mapping holding the client ID and the corresponding state value mapping.

  • local (bool, default: False ) –

    flag whether to tag this client view as local (True) or not (False).

Returns:

  • ClientView

    the widget representing the client state.

Source code in src/elva/widgets/awareness.py
def get_client_view(
    self, state: tuple[int, dict], local: bool = False
) -> ClientView:
    """
    Get the client view for a singular awareness state.

    Arguments:
        state: a tuple from the awareness states mapping holding the client ID and the corresponding state value mapping.
        local: flag whether to tag this client view as local (`True`) or not (`False`).

    Returns:
        the widget representing the client state.
    """
    client, data = state

    # try to get the display name from the state data
    user = data.get("user")
    name = ""

    if isinstance(user, dict):
        name = user.get("name", name)

    if name:
        client = name

    add = " (me)" if local else ""
    return ClientView(f"∙ {client}{add}")