style the modals
This commit is contained in:
Binary file not shown.
@@ -1,20 +1,25 @@
|
|||||||
|
import asyncio
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
from textual import work
|
||||||
from maildir_gtd.screens.CreateTask import CreateTaskScreen
|
from maildir_gtd.screens.CreateTask import CreateTaskScreen
|
||||||
|
|
||||||
|
|
||||||
def action_create_task(app) -> None:
|
def action_create_task(app) -> None:
|
||||||
"""Show the input modal for creating a task."""
|
"""Show the input modal for creating a task."""
|
||||||
def check_task(task_args: str) -> bool:
|
|
||||||
|
async def check_task(task_args: str) -> bool:
|
||||||
try:
|
try:
|
||||||
result = subprocess.run(
|
result = await asyncio.create_subprocess_shell(
|
||||||
["task", "add"] + task_args.split(" "),
|
f"task add {task_args}",
|
||||||
capture_output=True,
|
stdout=asyncio.subprocess.PIPE,
|
||||||
text=True
|
stderr=asyncio.subprocess.PIPE
|
||||||
)
|
)
|
||||||
|
stdout, stderr = await result.communicate()
|
||||||
if result.returncode == 0:
|
if result.returncode == 0:
|
||||||
app.show_status("Task created successfully.")
|
app.show_status(f"Task created: {stdout.decode()}")
|
||||||
else:
|
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:
|
except Exception as e:
|
||||||
app.show_status(f"Error: {e}", severity="error")
|
app.show_status(f"Error: {e}", severity="error")
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -111,3 +111,18 @@ Markdown {
|
|||||||
#envelopes-list ListItem:odd {
|
#envelopes-list ListItem:odd {
|
||||||
background: rgb(25, 24, 26);
|
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"),
|
Input(placeholder="arguments", id="task_input"),
|
||||||
),
|
),
|
||||||
Horizontal(
|
Horizontal(
|
||||||
Button("Cancel"),
|
Button("Cancel", id="cancel"),
|
||||||
Button("Submit")
|
Button("Submit", id="submit", variant="primary"),
|
||||||
),
|
),
|
||||||
id="create_task_container",
|
id="create_task_container",
|
||||||
classes="modal_screen"
|
classes="modal_screen"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@on(Input.Submitted)
|
@on(Input.Submitted)
|
||||||
def handle_task_args(self) -> None:
|
def handle_task_args(self) -> None:
|
||||||
input_widget = self.query_one("#task_input", Input)
|
input_widget = self.query_one("#task_input", Input)
|
||||||
|
self.visible = False
|
||||||
self.disabled = True
|
self.disabled = True
|
||||||
self.loading = True
|
self.loading = True
|
||||||
task_args = input_widget.value
|
task_args = input_widget.value
|
||||||
@@ -32,3 +34,11 @@ class CreateTaskScreen(ModalScreen[str]):
|
|||||||
def on_key(self, event) -> None:
|
def on_key(self, event) -> None:
|
||||||
if (event.key == "escape" or event.key == "ctrl+c"):
|
if (event.key == "escape" or event.key == "ctrl+c"):
|
||||||
self.dismiss()
|
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.app import ComposeResult
|
||||||
from textual.screen import ModalScreen
|
from textual.screen import ModalScreen
|
||||||
from textual.widgets import Input, Label, Button
|
from textual.widgets import Input, Label, Button
|
||||||
from textual.containers import Container
|
from textual.containers import Horizontal
|
||||||
|
|
||||||
class OpenMessageScreen(ModalScreen[int | None]):
|
class OpenMessageScreen(ModalScreen[int | None]):
|
||||||
|
|
||||||
def compose(self) -> ComposeResult:
|
def compose(self) -> ComposeResult:
|
||||||
yield Container(
|
yield Horizontal(
|
||||||
Label("📨", id="message_label"),
|
Label("📨 ID", id="message_label"),
|
||||||
Input(placeholder="Enter message ID (integer only)", type="integer", id="open_message_input"),
|
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",
|
id="open_message_container",
|
||||||
classes="modal_screen"
|
classes="modal_screen"
|
||||||
)
|
)
|
||||||
|
|
||||||
@on(Input.Submitted)
|
@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)
|
input_widget = self.query_one("#open_message_input", Input)
|
||||||
message_id = int(input_widget.value if input_widget.value else 0)
|
message_id = int(input_widget.value if input_widget.value else 0)
|
||||||
self.dismiss(message_id)
|
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