style the modals
This commit is contained in:
Binary file not shown.
@@ -1,20 +1,25 @@
|
||||
import asyncio
|
||||
import subprocess
|
||||
|
||||
from textual import work
|
||||
from maildir_gtd.screens.CreateTask import CreateTaskScreen
|
||||
|
||||
|
||||
def action_create_task(app) -> None:
|
||||
"""Show the input modal for creating a task."""
|
||||
def check_task(task_args: str) -> bool:
|
||||
|
||||
async def check_task(task_args: str) -> bool:
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["task", "add"] + task_args.split(" "),
|
||||
capture_output=True,
|
||||
text=True
|
||||
result = await asyncio.create_subprocess_shell(
|
||||
f"task add {task_args}",
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
stdout, stderr = await result.communicate()
|
||||
if result.returncode == 0:
|
||||
app.show_status("Task created successfully.")
|
||||
app.show_status(f"Task created: {stdout.decode()}")
|
||||
else:
|
||||
app.show_status(f"Failed to create task: {result.stderr}")
|
||||
app.show_status(f"Failed to create task: {stderr.decode()}", severity="error")
|
||||
except Exception as e:
|
||||
app.show_status(f"Error: {e}", severity="error")
|
||||
return True
|
||||
|
||||
@@ -111,3 +111,18 @@ Markdown {
|
||||
#envelopes-list ListItem:odd {
|
||||
background: rgb(25, 24, 26);
|
||||
}
|
||||
|
||||
#open_message_container, #create_task_container {
|
||||
dock: bottom;
|
||||
width: 100%;
|
||||
padding: 0 1;
|
||||
height: 5;
|
||||
|
||||
Input {
|
||||
width: 1fr;
|
||||
}
|
||||
Label, Button {
|
||||
width: auto;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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