Module userland.scripts.messages.view_screen

Message viewer screen

Classes

class ViewScreen (*args,
message: Message,
tags: Sequence[str],
**kwargs)
Expand source code
class ViewScreen(Screen):
    """Message viewer screen"""

    BINDINGS = [
        ("escape", "app.pop_screen", "Exit"),
        Binding("f", "", show=False),
    ]

    CSS = """
        Horizontal Label {
            width: 50%;
        }

        Label {
            margin: 0;
        }

        MarkdownViewer {
            padding-top: 1;
        }

        #header {
            background: #007 100%;
            color: #fff;
            height: 5;
            padding-left: 1;
            padding-right: 1;
            padding-top: 1;
        }

        #title {
            width: auto;
            margin-bottom: 1;
        }
    """

    message: Message
    tags: Sequence[str]

    def __init__(self, *args, message: Message, tags: Sequence[str], **kwargs):
        super(ViewScreen, self).__init__(*args, **kwargs)
        self.message = message
        self.tags = tags

    def compose(self) -> ComposeResult:
        assert self.message.author

        with Vertical():
            with Vertical(id="header"):
                with Horizontal():
                    yield Label(
                        "[bold underline ansi_cyan]Author:[/]    "
                        f"{self.message.author.name}"
                    )
                    yield Label(
                        "[bold underline ansi_cyan]Posted:[/] "
                        f"{self.message.created.strftime('%H:%M %a %b %d %Y')}"
                    )

                with Horizontal():
                    yield Label(
                        "[bold underline ansi_cyan]Recipient:[/] "
                        f"{self.message.recipient.name if self.message.recipient else '<N/A>'}"
                    )
                    yield Label(
                        f"[bold underline ansi_cyan]Tags:[/]   "
                        f"{', '.join(self.tags)}"
                    )

                yield Label(
                    f"[bold underline ansi_cyan]Title:[/]     "
                    f"{self.message.title}",
                    id="title",
                )

            yield MarkdownViewer(
                markdown=self.message.content,
                show_table_of_contents=False,
            )
            yield Footer()

Message viewer 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.

Ancestors

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

Class variables

var BINDINGS
var CSS
var can_focus
var can_focus_children
var message : Message
var tags : Sequence[str]

Methods

def compose(self) ‑> Iterable[textual.widget.Widget]
Expand source code
def compose(self) -> ComposeResult:
    assert self.message.author

    with Vertical():
        with Vertical(id="header"):
            with Horizontal():
                yield Label(
                    "[bold underline ansi_cyan]Author:[/]    "
                    f"{self.message.author.name}"
                )
                yield Label(
                    "[bold underline ansi_cyan]Posted:[/] "
                    f"{self.message.created.strftime('%H:%M %a %b %d %Y')}"
                )

            with Horizontal():
                yield Label(
                    "[bold underline ansi_cyan]Recipient:[/] "
                    f"{self.message.recipient.name if self.message.recipient else '<N/A>'}"
                )
                yield Label(
                    f"[bold underline ansi_cyan]Tags:[/]   "
                    f"{', '.join(self.tags)}"
                )

            yield Label(
                f"[bold underline ansi_cyan]Title:[/]     "
                f"{self.message.title}",
                id="title",
            )

        yield MarkdownViewer(
            markdown=self.message.content,
            show_table_of_contents=False,
        )
        yield Footer()

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()