Compare commits

...

2 Commits

Author SHA1 Message Date
Gustavo Henrique Santos Souza de Miranda cb31ba5662 changed ui.py to add command palettes commands and changed diary_list_screen.py to add access to the about_screen.py 2025-06-20 00:20:06 -03:00
Gustavo Henrique Santos Souza de Miranda 33509af0de Added about_screen.py 2025-06-19 22:35:32 -03:00
3 changed files with 104 additions and 4 deletions

View File

@ -0,0 +1,65 @@
from textual.app import ComposeResult
from textual.binding import Binding
from textual.screen import Screen
from textual.widgets import Header, Footer, Button, Label, TextArea
from textual.containers import Container
class AboutScreen(Screen[bool]):
"""Tela para exibir informações sobre a aplicação."""
TITLE = "Pilgrim - About"
BINDINGS = [
Binding("escape", "dismiss", "Close"),
]
def __init__(self):
super().__init__()
self.header = Header()
self.footer = Footer()
self.app_title = Label("Pilgrim", id="AboutScreen_AboutTitle")
self.content = Label("A TUI Based Travel Diary Application", id="AboutScreen_AboutContent")
self.version = Label("Version: 0.0.1", id="AboutScreen_AboutVersion")
self.developer = Label("Developed By: Gustavo Henrique Miranda ", id="AboutScreen_AboutAuthor")
self.contact = Label("git.gustavomiranda.xyz", id="AboutScreen_AboutContact")
self.license = TextArea(id="AboutScreen_AboutLicense")
self.license.text = """Copyright (c) 2025 GHMiranda.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."""
self.license.read_only = True
self.about_container = Container(self.app_title, self.content, self.version, self.developer, self.contact,
id="AboutScreen_SubContainer")
self.container = Container(self.about_container, self.license, id="AboutScreen_AboutContainer")
def compose(self) -> ComposeResult:
yield self.header
yield self.container
yield self.footer
def on_button_pressed(self, event: Button.Pressed) -> None:
"""Lida com os cliques dos botões."""
if "about-close-button" in event.button.classes:
self.dismiss(False)
elif "about-info-button" in event.button.classes:
self.notify("Mais informações seriam exibidas aqui!", title="Info")
def action_dismiss(self) -> None:
"""Fecha o about box usando dismiss."""
self.dismiss(False)
def on_key(self, event) -> None:
"""Intercepta teclas específicas."""
if event.key == "escape":
self.dismiss(False)
event.prevent_default()
elif event.key == "enter":
self.dismiss(False)
event.prevent_default()

View File

@ -8,6 +8,7 @@ from textual.binding import Binding
from textual.containers import Vertical, Container, Horizontal
from pilgrim.models.travel_diary import TravelDiary
from pilgrim.ui.screens.about_screen import AboutScreen
from pilgrim.ui.screens.edit_diary_modal import EditDiaryModal
from pilgrim.ui.screens.new_diary_modal import NewDiaryModal
@ -283,4 +284,7 @@ class DiaryListScreen(Screen):
def action_open_selected_diary(self):
"""Ação do binding ENTER"""
self.action_open_diary()
self.action_open_diary()
def action_about_cmd(self):
self.app.push_screen(AboutScreen())

View File

@ -1,8 +1,12 @@
from pathlib import Path
from typing import Iterable
from textual.app import App, SystemCommand
from textual.screen import Screen
from textual.app import App
from pilgrim.service.servicemanager import ServiceManager
from pilgrim.ui.screens.about_screen import AboutScreen
from pilgrim.ui.screens.diary_list_screen import DiaryListScreen
CSS_FILE_PATH = Path(__file__).parent / "styles" / "pilgrim.css"
@ -11,11 +15,38 @@ CSS_FILE_PATH = Path(__file__).parent / "styles" / "pilgrim.css"
class UIApp(App):
CSS_PATH = CSS_FILE_PATH
def __init__(self,service_manager: ServiceManager):
super().__init__()
def __init__(self,service_manager: ServiceManager, **kwargs):
super().__init__(**kwargs)
self.service_manager = service_manager
def on_mount(self) -> None:
"""Chamado quando a app inicia. Carrega a tela principal."""
self.push_screen(DiaryListScreen())
def get_system_commands(self, screen: Screen) -> Iterable[SystemCommand]:
"""Return commands based on current screen."""
# Commands for DiaryListScreen
if isinstance(screen, DiaryListScreen):
yield SystemCommand(
"About Pilgrim",
"Open About Pilgrim",
screen.action_about_cmd
)
elif isinstance(screen, AboutScreen):
yield SystemCommand(
"Back to List",
"Return to the diary list",
screen.dismiss
)
# Always include quit command
yield SystemCommand(
"Quit Application",
"Exit Pilgrim",
self.action_quit
)