Skip to content

Screens

elva.widgets.screens

Textual screens for ELVA apps.

Classes:

  • CredentialScreen

    Modal screen providing a form for credential input.

  • ErrorScreen

    Modal screen displaying an exception message.

CredentialScreen(options, body=None, user=None)

Bases: ModalScreen

Modal screen providing a form for credential input.

Parameters:

  • options (dict[str, Any]) –

    mapping of options for the connection provider.

  • body (None | str, default: None ) –

    informational message displayed above the credential form.

  • user (None | str, default: None ) –

    user name.

Methods:

Attributes:

  • options (dict) –

    Mapping of options for the connection provider.

  • body (Static) –

    Instance of the static widget displaying an informational message.

  • user (Input) –

    Instance of the input widget for the user name.

  • password (Input) –

    Instance of the input widget for the password.

Source code in src/elva/widgets/screens.py
def __init__(
    self, options: dict[str, Any], body: None | str = None, user: None | str = None
):
    """
    Arguments:
        options: mapping of options for the connection provider.
        body: informational message displayed above the credential form.
        user: user name.
    """
    super().__init__(classes="modalscreen", id="credentialscreen")
    self.options = options
    self.body = Static(RichText(body, justify="center"), id="body")

    self.user = Input(placeholder="user", id="user")
    self.user.value = user or ""
    self.password = Input(placeholder="password", password=True, id="password")

options = options instance-attribute

Mapping of options for the connection provider.

body = Static(RichText(body, justify='center'), id='body') instance-attribute

Instance of the static widget displaying an informational message.

user = Input(placeholder='user', id='user') instance-attribute

Instance of the input widget for the user name.

password = Input(placeholder='password', password=True, id='password') instance-attribute

Instance of the input widget for the password.

compose()

Hook arranging child widgets.

Source code in src/elva/widgets/screens.py
def compose(self):
    """
    Hook arranging child widgets.
    """
    with Grid(classes="form"):
        yield self.body
        yield self.user
        yield self.password
        yield Button("Confirm", classes="confirm")

update_and_return_credentials()

Save input credentials and return them after closing the screen.

This method saves the credentials encoded in a basic authorization header in the options attribute for usage in the connection provider.

Source code in src/elva/widgets/screens.py
def update_and_return_credentials(self):
    """
    Save input credentials and return them after closing the screen.

    This method saves the credentials encoded in a basic authorization header in the [`options`][elva.widgets.screens.CredentialScreen.options] attribute for usage in the connection provider.
    """
    credentials = (self.user.value, self.password.value)
    header = basic_authorization_header(*credentials)
    self.options["additional_headers"] = header
    self.password.clear()
    self.dismiss(credentials)

on_button_pressed(event)

Hook called on a button pressed event.

The credentials get updated and the screen closed.

Parameters:

  • event (Message) –

    message object holding information about the button pressed event.

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

    The credentials get updated and the screen closed.

    Arguments:
        event: message object holding information about the button pressed event.
    """
    self.update_and_return_credentials()

key_enter()

Hook called on an enter pressed event.

The credentials get updated and the screen closed.

Source code in src/elva/widgets/screens.py
def key_enter(self):
    """
    Hook called on an enter pressed event.

    The credentials get updated and the screen closed.
    """
    self.update_and_return_credentials()

ErrorScreen(exc)

Bases: ModalScreen

Modal screen displaying an exception message.

Parameters:

  • exc (str) –

    the exception message to display.

Methods:

Attributes:

  • exc (str) –

    The exception message to display.

Source code in src/elva/widgets/screens.py
def __init__(self, exc: str):
    """
    Arguments:
        exc: the exception message to display.
    """
    super().__init__(classes="modalscreen", id="errorscreen")
    self.exc = exc

exc = exc instance-attribute

The exception message to display.

compose()

Hook arranging child widgets.

Source code in src/elva/widgets/screens.py
def compose(self):
    """
    Hook arranging child widgets.
    """
    with Grid(classes="form"):
        yield Static(
            RichText(
                "The following error occured and the app will close now:",
                justify="center",
            )
        )
        yield Static(RichText(str(self.exc), justify="center"))
        yield Button("OK", classes="confirm")

on_button_pressed(event)

Hook called on a button pressed event.

It closes the screen.

Parameters:

  • event (Message) –

    the message object holding information about the button pressed event.

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

    It closes the screen.

    Arguments:
        event: the message object holding information about the button pressed event.
    """
    self.dismiss(self.exc)