Module userland.scripts.messages.save_modal

Save confirmation screen

Classes

class SaveModal (*args, reply_to: Message | None = None, **kwargs)

Save confirmation screen

Initialize the screen.

Args

name
The name of the screen.
id
The ID of the screen in the DOM.
classes
The CSS classes for the screen.
Expand source code
class SaveModal(ModalScreen):
    """Save confirmation screen"""

    CSS = """
        SaveModal {
            align: center middle;
            background: rgba(0, 0, 0, 0.5);
        }

        Button {
            margin: 1;
            width: 33%;
        }

        #save {
            margin-left: 0;
            margin-top: 1;
        }

        #wrapper {
            background: $primary-background;
            height: 7;
            padding: 1;
            width: 60;
        }
    """

    reply_to: Message | None

    def __init__(self, *args, reply_to: Message | None = None, **kwargs):
        super().__init__(*args, **kwargs)
        self.reply_to = reply_to

    def compose(self):
        yield Vertical(
            Label("Do you want to save your message?"),
            Horizontal(
                Button("Save", variant="success", id="save"),
                Button("Continue", variant="primary", id="continue"),
                Button("Discard", variant="error", id="discard"),
            ),
            id="wrapper",
        )

    async def on_button_pressed(self, event: Button.Pressed) -> None:
        assert event.button.id

        if event.button.id == "continue":
            self.app.pop_screen()  # pop this modal
            return

        if event.button.id == "save":
            self.app.pop_screen()
            await self.app.push_screen(DetailsModal(reply_to=self.reply_to))
            return

        self.app.pop_screen()  # pop this modal
        self.app.pop_screen()  # pop the editor

    async def key_escape(self, _):
        self.app.pop_screen()  # pop this modal

Ancestors

  • textual.screen.ModalScreen
  • textual.screen.Screen
  • typing.Generic
  • textual.widget.Widget
  • textual.dom.DOMNode
  • textual.message_pump.MessagePump

Class variables

var CSS
var can_focus
var can_focus_children
var reply_toMessage | None

Methods

def compose(self)

Called by Textual to create child widgets.

This method is called when a widget is mounted or by setting recompose=True when calling [refresh()][textual.widget.Widget.refresh].

Note that you don't typically need to explicitly call this method.

Example

def compose(self) -> ComposeResult:
    yield Header()
    yield Label("Press the button below:")
    yield Button()
    yield Footer()
async def key_escape(self, _)
async def on_button_pressed(self, event: textual.widgets._button.Button.Pressed) ‑> None