Bases: ModalScreen[int | None]
Prompt the user for a numeric value.
Source code in peagen/tui/components/number_input_screen.py
| def __init__(self, prompt: str, initial: int) -> None:
super().__init__()
self.prompt = prompt
self.initial = initial
|
Source code in peagen/tui/components/number_input_screen.py
17
18
19
20
21
22
23
24
25
26
27 | def compose(self) -> ComposeResult: # pragma: no cover - UI code
with Vertical(id="number_input_box"):
yield Label(self.prompt)
yield Input(
value=str(self.initial),
id="number_input",
placeholder="value",
)
with Horizontal():
yield Button("OK", id="submit", variant="primary")
yield Button("Cancel", id="cancel")
|
Source code in peagen/tui/components/number_input_screen.py
29
30
31
32
33
34
35
36
37
38 | def on_button_pressed(self, event: Button.Pressed) -> None:
if event.button.id == "submit":
value = self.query_one("#number_input", Input).value
try:
num = int(value)
except Exception:
num = None
self.dismiss(num)
elif event.button.id == "cancel":
self.dismiss(None)
|