mirror of
https://github.com/gmbrax/Pilgrim.git
synced 2026-11-10 00:10:17 +00:00
Added the edit_entry_screen.py and modified the mock entry_service_mock.py to be async and also add the screen change on diary_list_screen.py and added the rename_entry_modal.py and added all the necessary CSS on the pilgrim.css
This commit is contained in:
parent
981b38f994
commit
58807460d7
@@ -0,0 +1,58 @@
|
||||
from textual.app import ComposeResult
|
||||
from textual.containers import Vertical, Horizontal
|
||||
from textual.screen import ModalScreen
|
||||
from textual.widgets import Label, Input, Button
|
||||
|
||||
|
||||
class RenameEntryModal(ModalScreen[str]):
|
||||
"""A modal screen to rename a diary entry."""
|
||||
|
||||
BINDINGS = [
|
||||
("escape", "cancel", "Cancel"),
|
||||
]
|
||||
|
||||
def __init__(self, current_name: str):
|
||||
super().__init__()
|
||||
self._current_name = current_name
|
||||
self.name_input = Input(
|
||||
value=self._current_name,
|
||||
placeholder="Type the new name...",
|
||||
id="rename_input",
|
||||
classes="RenameEntryModal-name-input"
|
||||
)
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
with Vertical(id="rename_entry_dialog", classes="RenameEntryModal-dialog"):
|
||||
yield Label("Rename Entry", classes="dialog-title RenameEntryModal-title")
|
||||
yield Label("New Entry Title:", classes="RenameEntryModal-label")
|
||||
yield self.name_input
|
||||
with Horizontal(classes="dialog-buttons RenameEntryModal-buttons"):
|
||||
yield Button("Save", variant="primary", id="save", classes="RenameEntryModal-save-button")
|
||||
yield Button("Cancel", variant="default", id="cancel", classes="RenameEntryModal-cancel-button")
|
||||
|
||||
def on_mount(self) -> None:
|
||||
"""Focuses on the input when the screen is mounted."""
|
||||
self.name_input.focus()
|
||||
self.name_input.cursor_position = len(self.name_input.value)
|
||||
|
||||
def on_button_pressed(self, event: Button.Pressed) -> None:
|
||||
"""Handles button clicks."""
|
||||
if event.button.id == "save":
|
||||
new_name = self.name_input.value.strip()
|
||||
if new_name:
|
||||
self.dismiss(new_name) # Returns the new name
|
||||
else:
|
||||
self.dismiss(None) # Considers empty name as cancellation
|
||||
else:
|
||||
self.dismiss(None) # Returns None for cancellation
|
||||
|
||||
def on_input_submitted(self, event: Input.Submitted) -> None:
|
||||
"""Allows saving by pressing Enter."""
|
||||
new_name = event.value.strip()
|
||||
if new_name:
|
||||
self.dismiss(new_name)
|
||||
else:
|
||||
self.dismiss(None)
|
||||
|
||||
def action_cancel(self) -> None:
|
||||
self.dismiss(None)
|
||||
Reference in New Issue
Block a user