From c98a106d979a961afc2457d4b341d21effbecd9b Mon Sep 17 00:00:00 2001 From: Gustavo Henrique Santos Souza de Miranda Date: Mon, 14 Jul 2025 02:06:25 -0300 Subject: [PATCH 1/7] Fixed the new diary modal to accept the key "enter" and automatically the function --- src/pilgrim/ui/screens/new_diary_modal.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/pilgrim/ui/screens/new_diary_modal.py b/src/pilgrim/ui/screens/new_diary_modal.py index 2695216..cafd468 100644 --- a/src/pilgrim/ui/screens/new_diary_modal.py +++ b/src/pilgrim/ui/screens/new_diary_modal.py @@ -8,6 +8,7 @@ from textual.widgets import Label, Input, Button class NewDiaryModal(ModalScreen[str]): BINDINGS = [ Binding("escape", "cancel", "Cancel"), + Binding("enter", "create_diary", "Create",priority=True), ] def __init__(self): super().__init__() @@ -31,15 +32,23 @@ class NewDiaryModal(ModalScreen[str]): def on_button_pressed(self, event: Button.Pressed) -> None: """Handles button clicks.""" if event.button.id == "create_diary_button": - diary_name = self.name_input.value.strip() - if diary_name: - self.dismiss(diary_name) - else: - self.notify("Diary name cannot be empty.", severity="warning") - self.name_input.focus() + self.action_create_diary() elif event.button.id == "cancel_button": self.dismiss("") def action_cancel(self) -> None: """Action to cancel the modal.""" - self.dismiss("") \ No newline at end of file + self.dismiss("") + + def action_create_diary(self) -> None: + diary_name = self.name_input.value.strip() + if diary_name: + self.dismiss(diary_name) + else: + self.notify("Diary name cannot be empty.", severity="warning") + self.name_input.focus() + + def on_input_submitted(self, event: Input.Submitted) -> None: + if event.input.id == "NewDiaryModal-NameInput": + self.action_create_diary() + From f174fd1d8a6277512d4413dea93e72a997cf0c83 Mon Sep 17 00:00:00 2001 From: Gustavo Henrique Santos Souza de Miranda Date: Mon, 14 Jul 2025 02:23:29 -0300 Subject: [PATCH 2/7] Fixed the edit diary modal to accept the key "enter" and automatically the function --- src/pilgrim/ui/screens/edit_diary_modal.py | 30 +++++++++++++++------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/pilgrim/ui/screens/edit_diary_modal.py b/src/pilgrim/ui/screens/edit_diary_modal.py index 4f577eb..e54b71f 100644 --- a/src/pilgrim/ui/screens/edit_diary_modal.py +++ b/src/pilgrim/ui/screens/edit_diary_modal.py @@ -8,6 +8,7 @@ from textual.widgets import Label, Input, Button class EditDiaryModal(ModalScreen[tuple[int,str]]): BINDINGS = [ Binding("escape", "cancel", "Cancel"), + Binding("enter", "edit_diary", "Save",priority=True), ] def __init__(self, diary_id: int): @@ -32,17 +33,28 @@ class EditDiaryModal(ModalScreen[tuple[int,str]]): def on_button_pressed(self, event: Button.Pressed) -> None: if event.button.id == "save_diary_button": - new_diary_name = self.name_input.value.strip() - if new_diary_name and new_diary_name != self.current_diary_name: - self.dismiss((self.diary_id, new_diary_name)) - elif new_diary_name == self.current_diary_name: - self.notify("No changes made.", severity="warning") - self.dismiss(None) - else: - self.notify("Diary name cannot be empty.", severity="warning") - self.name_input.focus() + self.action_edit_diary() elif event.button.id == "cancel_button": self.dismiss(None) + def on_key(self, event): + if event.key == "enter": + self.action_edit_diary() + event.prevent_default() + + def action_edit_diary(self) -> None: + new_diary_name = self.name_input.value.strip() + if new_diary_name and new_diary_name != self.current_diary_name: + self.dismiss((self.diary_id, new_diary_name)) + elif new_diary_name == self.current_diary_name: + self.notify("No changes made.", severity="warning") + self.dismiss(None) + else: + self.notify("Diary name cannot be empty.", severity="warning") + self.name_input.focus() + + def on_input_submitted(self, event: Input.Submitted) -> None: + if event.input.id == "edit_diary_name_input": + self.action_edit_diary() def action_cancel(self) -> None: self.dismiss(None) \ No newline at end of file From 18760e174cafe3a1a5d8b22d861183619fa5753f Mon Sep 17 00:00:00 2001 From: Gustavo Henrique Santos Souza de Miranda Date: Tue, 15 Jul 2025 02:14:53 -0300 Subject: [PATCH 3/7] Add a functionality that automatically opens the diary after creation, Change the responsibility of diary creation to the new_diary_modal.py instead of the diary_list_screen.py --- src/pilgrim/ui/screens/diary_list_screen.py | 30 +++++++-------------- src/pilgrim/ui/screens/new_diary_modal.py | 26 +++++++++++++++--- 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/pilgrim/ui/screens/diary_list_screen.py b/src/pilgrim/ui/screens/diary_list_screen.py index 066fbae..b553ed2 100644 --- a/src/pilgrim/ui/screens/diary_list_screen.py +++ b/src/pilgrim/ui/screens/diary_list_screen.py @@ -206,29 +206,17 @@ class DiaryListScreen(Screen): """Action to create new diary""" self.app.push_screen(NewDiaryModal(),self._on_new_diary_submitted) - def _on_new_diary_submitted(self,result): - self.notify(str(result)) - if result: - self.notify(f"Creating Diary:{result}'...") - self.call_later(self._async_create_diary,result) + def _on_new_diary_submitted(self, result): + """Callback after diary creation""" + if result: # Se result não é string vazia, o diário foi criado + self.notify(f"Returning to diary list...") + # Atualiza a lista de diários + self.refresh_diaries() else: - self.notify(f"Canceled...") - - async def _async_create_diary(self,name: str): - - try: - service = self.app.service_manager.get_travel_diary_service() - created_diary = await service.async_create(name) - if created_diary: - self.diary_id_map[created_diary.id] = created_diary.id - await self.async_refresh_diaries() - self.notify(f"Diary: '{name}' created!") - else: - self.notify("Error Creating the diary") - except Exception as e: - self.notify(f"Exception on creating the diary: {str(e)}") - + self.notify(f"Creation canceled...") + def _on_screen_resume(self) -> None: + self.refresh_diaries() def action_edit_selected_diary(self): """Action to edit selected diary""" diff --git a/src/pilgrim/ui/screens/new_diary_modal.py b/src/pilgrim/ui/screens/new_diary_modal.py index cafd468..2238875 100644 --- a/src/pilgrim/ui/screens/new_diary_modal.py +++ b/src/pilgrim/ui/screens/new_diary_modal.py @@ -4,14 +4,17 @@ from textual.containers import Vertical, Horizontal from textual.screen import ModalScreen from textual.widgets import Label, Input, Button +from pilgrim.ui.screens.edit_entry_screen import EditEntryScreen + class NewDiaryModal(ModalScreen[str]): BINDINGS = [ Binding("escape", "cancel", "Cancel"), Binding("enter", "create_diary", "Create",priority=True), ] - def __init__(self): + def __init__(self,autoopen=True): super().__init__() + self.auto_open = autoopen self.name_input = Input(id="NewDiaryModal-NameInput",classes="NewDiaryModal-NameInput") # This ID is fine, it's specific to the input def compose(self) -> ComposeResult: @@ -34,7 +37,7 @@ class NewDiaryModal(ModalScreen[str]): if event.button.id == "create_diary_button": self.action_create_diary() elif event.button.id == "cancel_button": - self.dismiss("") + self.dismiss() def action_cancel(self) -> None: """Action to cancel the modal.""" @@ -43,7 +46,7 @@ class NewDiaryModal(ModalScreen[str]): def action_create_diary(self) -> None: diary_name = self.name_input.value.strip() if diary_name: - self.dismiss(diary_name) + self.call_later(self._async_create_diary, diary_name) else: self.notify("Diary name cannot be empty.", severity="warning") self.name_input.focus() @@ -52,3 +55,20 @@ class NewDiaryModal(ModalScreen[str]): if event.input.id == "NewDiaryModal-NameInput": self.action_create_diary() + async def _async_create_diary(self, name: str): + + try: + service = self.app.service_manager.get_travel_diary_service() + created_diary = await service.async_create(name) + if created_diary: + self.dismiss(name) + self.app.push_screen(EditEntryScreen(diary_id=created_diary.id)) + self.notify(f"Diary: '{name}' created!") + else: + self.notify("Error Creating the diary") + except Exception as e: + self.notify(f"Exception on creating the diary: {str(e)}") + + + + From f838a5b42132d76877df8080b02f1ae4e7be71bc Mon Sep 17 00:00:00 2001 From: Gustavo Henrique Santos Souza de Miranda Date: Tue, 15 Jul 2025 15:51:30 -0300 Subject: [PATCH 4/7] Add the auto-open option to the new_diary_modal.py --- src/pilgrim/ui/screens/new_diary_modal.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pilgrim/ui/screens/new_diary_modal.py b/src/pilgrim/ui/screens/new_diary_modal.py index 2238875..c98af64 100644 --- a/src/pilgrim/ui/screens/new_diary_modal.py +++ b/src/pilgrim/ui/screens/new_diary_modal.py @@ -62,7 +62,10 @@ class NewDiaryModal(ModalScreen[str]): created_diary = await service.async_create(name) if created_diary: self.dismiss(name) - self.app.push_screen(EditEntryScreen(diary_id=created_diary.id)) + + if self.auto_open: + self.app.push_screen(EditEntryScreen(diary_id=created_diary.id)) + self.notify(f"Diary: '{name}' created!") else: self.notify("Error Creating the diary") From a3123fe32271fedebeaff428bbe7365a0f095938 Mon Sep 17 00:00:00 2001 From: Gustavo Henrique Santos Souza de Miranda Date: Wed, 16 Jul 2025 00:25:37 -0300 Subject: [PATCH 5/7] Bump the version to 0.0.4 on about_screen.py and pyproject.toml --- pyproject.toml | 2 +- src/pilgrim/ui/screens/about_screen.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 6657a3e..eb7ec6b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ [project] name = "Pilgrim" - version = "0.0.3" + version = "0.0.4" authors = [ { name="Gustavo Henrique Santos Souza de Miranda", email="gustavohssmiranda@gmail.com" } ] diff --git a/src/pilgrim/ui/screens/about_screen.py b/src/pilgrim/ui/screens/about_screen.py index 52626bf..2d8566d 100644 --- a/src/pilgrim/ui/screens/about_screen.py +++ b/src/pilgrim/ui/screens/about_screen.py @@ -20,7 +20,7 @@ class AboutScreen(Screen[bool]): self.app_title = Label("Pilgrim", id="AboutScreen_AboutTitle",classes="AboutScreen_AboutTitle") self.content = Label("A TUI Based Travel Diary Application", id="AboutScreen_AboutContent", classes="AboutScreen_AboutContent") - self.version = Label("Version: 0.0.1", id="AboutScreen_AboutVersion", + self.version = Label("Version: 0.0.4", id="AboutScreen_AboutVersion", classes="AboutScreen_AboutVersion") self.developer = Label("Developed By: Gustavo Henrique Miranda ", id="AboutScreen_AboutAuthor") self.contact = Label("git.gustavomiranda.xyz", id="AboutScreen_AboutContact", From 2b851fc7c798b1024f3a57ed5ba5387ee8002d14 Mon Sep 17 00:00:00 2001 From: Gustavo Henrique Santos Souza de Miranda Date: Wed, 16 Jul 2025 00:39:28 -0300 Subject: [PATCH 6/7] Add the use of importlib.metadata.version to keep the version string in sync with the pyproject.toml --- src/pilgrim/ui/screens/about_screen.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pilgrim/ui/screens/about_screen.py b/src/pilgrim/ui/screens/about_screen.py index 2d8566d..eb6cd80 100644 --- a/src/pilgrim/ui/screens/about_screen.py +++ b/src/pilgrim/ui/screens/about_screen.py @@ -3,7 +3,7 @@ from textual.binding import Binding from textual.screen import Screen from textual.widgets import Header, Footer, Button, Label, TextArea from textual.containers import Container - +from importlib.metadata import version class AboutScreen(Screen[bool]): """Screen to display application information.""" @@ -20,7 +20,7 @@ class AboutScreen(Screen[bool]): self.app_title = Label("Pilgrim", id="AboutScreen_AboutTitle",classes="AboutScreen_AboutTitle") self.content = Label("A TUI Based Travel Diary Application", id="AboutScreen_AboutContent", classes="AboutScreen_AboutContent") - self.version = Label("Version: 0.0.4", id="AboutScreen_AboutVersion", + self.version = Label(f"Version: {version('Pilgrim')}", id="AboutScreen_AboutVersion", classes="AboutScreen_AboutVersion") self.developer = Label("Developed By: Gustavo Henrique Miranda ", id="AboutScreen_AboutAuthor") self.contact = Label("git.gustavomiranda.xyz", id="AboutScreen_AboutContact", From 167c2d892883c5d500ce9d0d9bfdece538d47fea Mon Sep 17 00:00:00 2001 From: Gustavo Henrique Santos Souza de Miranda Date: Wed, 16 Jul 2025 00:50:07 -0300 Subject: [PATCH 7/7] Change to call the method in the super class on the _on_screen_resume method --- src/pilgrim/ui/screens/diary_list_screen.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pilgrim/ui/screens/diary_list_screen.py b/src/pilgrim/ui/screens/diary_list_screen.py index b553ed2..649a508 100644 --- a/src/pilgrim/ui/screens/diary_list_screen.py +++ b/src/pilgrim/ui/screens/diary_list_screen.py @@ -216,6 +216,7 @@ class DiaryListScreen(Screen): self.notify(f"Creation canceled...") def _on_screen_resume(self) -> None: + super()._on_screen_resume() self.refresh_diaries() def action_edit_selected_diary(self):