34 lines
1.2 KiB
Python
34 lines
1.2 KiB
Python
from textual import on
|
|
from textual.app import ComposeResult
|
|
from textual.screen import ModalScreen
|
|
from textual.widgets import Input, Label, Button
|
|
from textual.containers import Horizontal
|
|
|
|
class OpenMessageScreen(ModalScreen[int | None]):
|
|
|
|
def compose(self) -> ComposeResult:
|
|
yield Horizontal(
|
|
Label("📨 ID", id="message_label"),
|
|
Input(placeholder="Enter message ID (integer only)", type="integer", id="open_message_input"),
|
|
Button("Cancel", id="cancel"),
|
|
Button("Open", variant="primary", id="submit"),
|
|
id="open_message_container",
|
|
classes="modal_screen"
|
|
)
|
|
|
|
@on(Input.Submitted)
|
|
def handle_message_id(self, event) -> None:
|
|
input_widget = self.query_one("#open_message_input", Input)
|
|
message_id = int(input_widget.value if input_widget.value else 0)
|
|
self.dismiss(message_id)
|
|
|
|
|
|
def button_on_click(self, event) -> None:
|
|
if event.button.id == "cancel":
|
|
self.dismiss()
|
|
elif event.button.id == "submit":
|
|
input_widget = self.query_one("#open_message_input", Input)
|
|
message_id = int(input_widget.value if input_widget.value else 0)
|
|
self.dismiss(message_id)
|
|
|