style the modals
This commit is contained in:
@@ -14,16 +14,18 @@ class CreateTaskScreen(ModalScreen[str]):
|
||||
Input(placeholder="arguments", id="task_input"),
|
||||
),
|
||||
Horizontal(
|
||||
Button("Cancel"),
|
||||
Button("Submit")
|
||||
Button("Cancel", id="cancel"),
|
||||
Button("Submit", id="submit", variant="primary"),
|
||||
),
|
||||
id="create_task_container",
|
||||
classes="modal_screen"
|
||||
)
|
||||
|
||||
|
||||
@on(Input.Submitted)
|
||||
def handle_task_args(self) -> None:
|
||||
input_widget = self.query_one("#task_input", Input)
|
||||
self.visible = False
|
||||
self.disabled = True
|
||||
self.loading = True
|
||||
task_args = input_widget.value
|
||||
@@ -32,3 +34,11 @@ class CreateTaskScreen(ModalScreen[str]):
|
||||
def on_key(self, event) -> None:
|
||||
if (event.key == "escape" or event.key == "ctrl+c"):
|
||||
self.dismiss()
|
||||
|
||||
def button_on_click(self, event):
|
||||
if event.button.id == "cancel":
|
||||
self.dismiss()
|
||||
elif event.button.id == "submit":
|
||||
input_widget = self.query_one("#task_input", Input)
|
||||
task_args = input_widget.value
|
||||
self.dismiss(task_args)
|
||||
|
||||
@@ -2,26 +2,32 @@ 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 Container
|
||||
from textual.containers import Horizontal
|
||||
|
||||
class OpenMessageScreen(ModalScreen[int | None]):
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Container(
|
||||
Label("📨", id="message_label"),
|
||||
yield Horizontal(
|
||||
Label("📨 ID", id="message_label"),
|
||||
Input(placeholder="Enter message ID (integer only)", type="integer", id="open_message_input"),
|
||||
Button("Open", variant="primary", id="open_message_button"),
|
||||
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) -> None:
|
||||
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)
|
||||
|
||||
@on(Input._on_key)
|
||||
def handle_close(self, event) -> None:
|
||||
if (event.key == "escape" or event.key == "ctrl+c"):
|
||||
self.dismiss()
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user