Added an edit_photo_modal.py to allow modification of the photo after ingestion

This commit is contained in:
Gustavo Henrique Santos Souza de Miranda 2025-06-29 21:51:27 -03:00
parent 1209b8147c
commit cf56fda3de
1 changed files with 68 additions and 0 deletions

View File

@ -0,0 +1,68 @@
from textual.app import ComposeResult
from textual.screen import Screen
from textual.widgets import Static, Input, Button
from textual.containers import Container, Horizontal
from pilgrim.models.photo import Photo
class EditPhotoModal(Screen):
"""Modal for editing an existing photo (name and caption only)"""
def __init__(self, photo: Photo):
super().__init__()
self.photo = photo
self.result = None
def compose(self) -> ComposeResult:
yield Container(
Static("✏️ Edit Photo", classes="EditPhotoModal-Title"),
Static("File path (read-only):", classes="EditPhotoModal-Label"),
Input(
value=self.photo.filepath,
id="filepath-input",
classes="EditPhotoModal-Input",
disabled=True
),
Static("Photo name:", classes="EditPhotoModal-Label"),
Input(
value=self.photo.name,
placeholder="Enter photo name...",
id="name-input",
classes="EditPhotoModal-Input"
),
Static("Caption (optional):", classes="EditPhotoModal-Label"),
Input(
value=self.photo.caption or "",
placeholder="Enter caption...",
id="caption-input",
classes="EditPhotoModal-Input"
),
Horizontal(
Button("Save Changes", id="save-button", classes="EditPhotoModal-Button"),
Button("Cancel", id="cancel-button", classes="EditPhotoModal-Button"),
classes="EditPhotoModal-Buttons"
),
classes="EditPhotoModal-Dialog"
)
def on_button_pressed(self, event: Button.Pressed) -> None:
if event.button.id == "save-button":
name = self.query_one("#name-input", Input).value
caption = self.query_one("#caption-input", Input).value
if not name.strip():
self.notify("Photo name is required", severity="error")
return
# Return the updated photo data
self.result = {
"filepath": self.photo.filepath, # Keep original filepath
"name": name.strip(),
"caption": caption.strip() if caption.strip() else None
}
self.dismiss(self.result)
elif event.button.id == "cancel-button":
self.dismiss()
def on_mount(self) -> None:
"""Focus on the name input when modal opens"""
self.query_one("#name-input", Input).focus()