add MessageScreen back and tweak/enhance screen layouts

this will be used for a help screen, which isn't done yet, but this
makes the edit screen incrementally better too

Signed-off-by: Brian S. Stephan <bss@incorporeal.org>
This commit is contained in:
Brian S. Stephan 2024-03-11 12:59:58 -05:00
parent 5fc2339c74
commit 1d887c9fdf
Signed by: bss
GPG Key ID: 3DE06D3180895FCB
2 changed files with 43 additions and 10 deletions

View File

@ -5,12 +5,12 @@ Tree {
Button {
border: round gray;
content-align: center middle;
width: 100%;
max-width: 50%;
height: 100%;
margin: 0 1;
}
EditScreen {
EditScreen, MessageScreen {
align: center middle;
}
@ -31,14 +31,25 @@ EditScreen Label {
}
#edit-dialog {
grid-size: 2;
grid-rows: 1fr 3fr 1fr 2fr;
padding: 0 1;
grid-rows: 1fr 1fr 1fr 1fr;
width: 50%;
height: 50%;
border: tall gray 100%;
}
#message-dialog {
padding: 0 1;
grid-rows: 3fr 1fr;
width: 50%;
height: 50%;
border: tall gray 100%;
}
#button-container {
align: right middle;
}
#field-name, #field-input, #input-errors {
column-span: 2;
}

View File

@ -12,7 +12,7 @@ from rich.highlighter import ReprHighlighter
from rich.text import Text
from textual import on
from textual.app import App, ComposeResult
from textual.containers import Grid
from textual.containers import Container, Grid, Horizontal
from textual.logging import TextualHandler
from textual.screen import ModalScreen
from textual.validation import Number
@ -57,11 +57,12 @@ class EditScreen(ModalScreen):
# we don't handle whatever these are yet
self.input_field = Label(repr(self.field_value), id='field-input')
yield Grid(
Label(self.field_descriptor.full_name, id="field-name"),
self.input_field,
Pretty('', id='input-errors', classes='hidden'),
Button("Confirm", id='confirm-button'),
Button("Cancel", id='cancel-button'),
Container(Label(self.field_descriptor.full_name, id="field-name"), id="field-name-container"),
Container(self.input_field, id="input-field-container"),
Container(Pretty('', id='input-errors', classes='hidden'), id="error-container"),
Horizontal(Button("Confirm", id='confirm-button'),
Button("Cancel", id='cancel-button'),
id="button-container"),
id='edit-dialog',
)
@ -102,6 +103,27 @@ class EditScreen(ModalScreen):
self.node.set_label(pb_field_to_node_label(self.field_descriptor, field_value))
class MessageScreen(ModalScreen):
"""Simple screen for displaying messages."""
def __init__(self, text: str, *args, **kwargs):
"""Store the message for later display."""
self.text = text
super().__init__(*args, **kwargs)
def compose(self) -> ComposeResult:
"""Build the pop-up window with the desired message displayed."""
yield Grid(
Container(Label(self.text, id="message-text"), id="text-container"),
Container(Button("OK", id='ok-button'), id="button-container"),
id='message-dialog',
)
def on_button_pressed(self, event: Button.Pressed) -> None:
"""Process the button action (close the window)."""
self.app.pop_screen()
class ConfigEditor(App):
"""Display the GP2040-CE configuration as a tree."""