Fix back button: restore on_button_pressed handler in all screens

This commit is contained in:
shuki
2026-03-07 07:15:49 +02:00
parent a66cab8304
commit 98c1292162
8 changed files with 32 additions and 48 deletions

View File

@@ -3,7 +3,7 @@ from textual.screen import Screen
from textual.widgets import Header, Footer, Static, Button, Select from textual.widgets import Header, Footer, Static, Button, Select
from tui.widgets.header import GnizaHeader as Header # noqa: F811 from tui.widgets.header import GnizaHeader as Header # noqa: F811
from textual.containers import Vertical, Horizontal from textual.containers import Vertical, Horizontal
from textual.events import Click
from tui.config import list_conf_dir, has_targets, has_remotes from tui.config import list_conf_dir, has_targets, has_remotes
from tui.jobs import job_manager from tui.jobs import job_manager
from tui.widgets import ConfirmDialog, DocsPanel from tui.widgets import ConfirmDialog, DocsPanel
@@ -68,7 +68,9 @@ class BackupScreen(Screen):
pass pass
def on_button_pressed(self, event: Button.Pressed) -> None: def on_button_pressed(self, event: Button.Pressed) -> None:
if event.button.id == "btn-backup": if event.button.id == "btn-back":
self.app.pop_screen()
elif event.button.id == "btn-backup":
target_sel = self.query_one("#backup-target", Select) target_sel = self.query_one("#backup-target", Select)
if not isinstance(target_sel.value, str): if not isinstance(target_sel.value, str):
self.notify("Please select a source", severity="error") self.notify("Please select a source", severity="error")
@@ -102,9 +104,5 @@ class BackupScreen(Screen):
job_manager.start_job(self.app, job, "backup", "--all") job_manager.start_job(self.app, job, "backup", "--all")
self.app.switch_screen("running_tasks") self.app.switch_screen("running_tasks")
def on_click(self, event: Click) -> None:
if event.widget.id == "btn-back":
self.app.pop_screen()
def action_go_back(self) -> None: def action_go_back(self) -> None:
self.app.pop_screen() self.app.pop_screen()

View File

@@ -3,7 +3,7 @@ from textual.screen import Screen
from textual.widgets import Header, Footer, Static, Button, DataTable from textual.widgets import Header, Footer, Static, Button, DataTable
from tui.widgets.header import GnizaHeader as Header # noqa: F811 from tui.widgets.header import GnizaHeader as Header # noqa: F811
from textual.containers import Vertical, Horizontal from textual.containers import Vertical, Horizontal
from textual.events import Click
from textual import work from textual import work
from tui.config import list_conf_dir, parse_conf, CONFIG_DIR from tui.config import list_conf_dir, parse_conf, CONFIG_DIR
@@ -61,7 +61,9 @@ class RemotesScreen(Screen):
return None return None
def on_button_pressed(self, event: Button.Pressed) -> None: def on_button_pressed(self, event: Button.Pressed) -> None:
if event.button.id == "btn-add": if event.button.id == "btn-back":
self.app.pop_screen()
elif event.button.id == "btn-add":
self.app.push_screen("remote_edit", callback=lambda _: self._refresh_table()) self.app.push_screen("remote_edit", callback=lambda _: self._refresh_table())
elif event.button.id == "btn-edit": elif event.button.id == "btn-edit":
name = self._selected_remote() name = self._selected_remote()
@@ -121,9 +123,5 @@ class RemotesScreen(Screen):
self.notify(f"Destination '{name}' deleted.") self.notify(f"Destination '{name}' deleted.")
self._refresh_table() self._refresh_table()
def on_click(self, event: Click) -> None:
if event.widget.id == "btn-back":
self.app.pop_screen()
def action_go_back(self) -> None: def action_go_back(self) -> None:
self.app.pop_screen() self.app.pop_screen()

View File

@@ -3,7 +3,7 @@ from textual.screen import Screen
from textual.widgets import Header, Footer, Static, Button, Select, Input, RadioSet, RadioButton, Switch from textual.widgets import Header, Footer, Static, Button, Select, Input, RadioSet, RadioButton, Switch
from tui.widgets.header import GnizaHeader as Header # noqa: F811 from tui.widgets.header import GnizaHeader as Header # noqa: F811
from textual.containers import Vertical, Horizontal from textual.containers import Vertical, Horizontal
from textual.events import Click
from textual import work, on from textual import work, on
from tui.config import list_conf_dir, parse_conf, CONFIG_DIR from tui.config import list_conf_dir, parse_conf, CONFIG_DIR
@@ -98,7 +98,9 @@ class RestoreScreen(Screen):
self.notify("No snapshots found", severity="warning") self.notify("No snapshots found", severity="warning")
def on_button_pressed(self, event: Button.Pressed) -> None: def on_button_pressed(self, event: Button.Pressed) -> None:
if event.button.id == "btn-browse-dest": if event.button.id == "btn-back":
self.app.pop_screen()
elif event.button.id == "btn-browse-dest":
self.app.push_screen( self.app.push_screen(
FolderPicker("Select destination directory"), FolderPicker("Select destination directory"),
callback=self._dest_selected, callback=self._dest_selected,
@@ -156,9 +158,5 @@ class RestoreScreen(Screen):
job_manager.start_job(self.app, job, *args) job_manager.start_job(self.app, job, *args)
self.app.switch_screen("running_tasks") self.app.switch_screen("running_tasks")
def on_click(self, event: Click) -> None:
if event.widget.id == "btn-back":
self.app.pop_screen()
def action_go_back(self) -> None: def action_go_back(self) -> None:
self.app.pop_screen() self.app.pop_screen()

View File

@@ -3,7 +3,7 @@ from textual.screen import Screen
from textual.widgets import Header, Footer, Static, Button, Select, Input from textual.widgets import Header, Footer, Static, Button, Select, Input
from tui.widgets.header import GnizaHeader as Header # noqa: F811 from tui.widgets.header import GnizaHeader as Header # noqa: F811
from textual.containers import Vertical, Horizontal from textual.containers import Vertical, Horizontal
from textual.events import Click
from textual import work from textual import work
from tui.config import list_conf_dir, parse_conf, update_conf_key, CONFIG_DIR from tui.config import list_conf_dir, parse_conf, update_conf_key, CONFIG_DIR
@@ -46,7 +46,9 @@ class RetentionScreen(Screen):
yield Footer() yield Footer()
def on_button_pressed(self, event: Button.Pressed) -> None: def on_button_pressed(self, event: Button.Pressed) -> None:
if event.button.id == "btn-cleanup": if event.button.id == "btn-back":
self.app.pop_screen()
elif event.button.id == "btn-cleanup":
target_sel = self.query_one("#ret-target", Select) target_sel = self.query_one("#ret-target", Select)
if not isinstance(target_sel.value, str): if not isinstance(target_sel.value, str):
self.notify("Select a source first", severity="error") self.notify("Select a source first", severity="error")
@@ -91,9 +93,5 @@ class RetentionScreen(Screen):
log_screen.write(f"\n[red]Cleanup failed (exit code {rc}).[/red]") log_screen.write(f"\n[red]Cleanup failed (exit code {rc}).[/red]")
log_screen.finish() log_screen.finish()
def on_click(self, event: Click) -> None:
if event.widget.id == "btn-back":
self.app.pop_screen()
def action_go_back(self) -> None: def action_go_back(self) -> None:
self.app.pop_screen() self.app.pop_screen()

View File

@@ -5,7 +5,7 @@ from textual.screen import Screen
from textual.widgets import Header, Footer, Static, Button, DataTable from textual.widgets import Header, Footer, Static, Button, DataTable
from tui.widgets.header import GnizaHeader as Header # noqa: F811 from tui.widgets.header import GnizaHeader as Header # noqa: F811
from textual.containers import Vertical, Horizontal from textual.containers import Vertical, Horizontal
from textual.events import Click
from textual import work from textual import work
from tui.config import list_conf_dir, parse_conf, update_conf_key, CONFIG_DIR from tui.config import list_conf_dir, parse_conf, update_conf_key, CONFIG_DIR
@@ -99,7 +99,9 @@ class ScheduleScreen(Screen):
return None return None
def on_button_pressed(self, event: Button.Pressed) -> None: def on_button_pressed(self, event: Button.Pressed) -> None:
if event.button.id == "btn-add": if event.button.id == "btn-back":
self.app.pop_screen()
elif event.button.id == "btn-add":
from tui.screens.schedule_edit import ScheduleEditScreen from tui.screens.schedule_edit import ScheduleEditScreen
self.app.push_screen(ScheduleEditScreen(), callback=self._on_schedule_saved) self.app.push_screen(ScheduleEditScreen(), callback=self._on_schedule_saved)
elif event.button.id == "btn-edit": elif event.button.id == "btn-edit":
@@ -223,9 +225,5 @@ class ScheduleScreen(Screen):
log_screen.write(stderr) log_screen.write(stderr)
log_screen.finish() log_screen.finish()
def on_click(self, event: Click) -> None:
if event.widget.id == "btn-back":
self.app.pop_screen()
def action_go_back(self) -> None: def action_go_back(self) -> None:
self.app.pop_screen() self.app.pop_screen()

View File

@@ -3,7 +3,7 @@ from textual.screen import Screen
from textual.widgets import Header, Footer, Static, Button, Input, Select from textual.widgets import Header, Footer, Static, Button, Input, Select
from tui.widgets.header import GnizaHeader as Header # noqa: F811 from tui.widgets.header import GnizaHeader as Header # noqa: F811
from textual.containers import Vertical, Horizontal from textual.containers import Vertical, Horizontal
from textual.events import Click
from textual import work from textual import work
from tui.config import parse_conf, write_conf, CONFIG_DIR from tui.config import parse_conf, write_conf, CONFIG_DIR
@@ -92,7 +92,9 @@ class SettingsScreen(Screen):
self.query_one("#section-web").border_title = "Web Dashboard" self.query_one("#section-web").border_title = "Web Dashboard"
def on_button_pressed(self, event: Button.Pressed) -> None: def on_button_pressed(self, event: Button.Pressed) -> None:
if event.button.id == "btn-save": if event.button.id == "btn-back":
self.app.pop_screen()
elif event.button.id == "btn-save":
self._save() self._save()
elif event.button.id == "btn-test-email": elif event.button.id == "btn-test-email":
self._save() self._save()
@@ -140,9 +142,5 @@ class SettingsScreen(Screen):
log_screen.write(stderr) log_screen.write(stderr)
log_screen.finish() log_screen.finish()
def on_click(self, event: Click) -> None:
if event.widget.id == "btn-back":
self.app.pop_screen()
def action_go_back(self) -> None: def action_go_back(self) -> None:
self.app.pop_screen() self.app.pop_screen()

View File

@@ -6,7 +6,7 @@ from textual.screen import Screen
from textual.widgets import Header, Footer, Static, Button, Select, DataTable from textual.widgets import Header, Footer, Static, Button, Select, DataTable
from tui.widgets.header import GnizaHeader as Header # noqa: F811 from tui.widgets.header import GnizaHeader as Header # noqa: F811
from textual.containers import Vertical, Horizontal from textual.containers import Vertical, Horizontal
from textual.events import Click
from textual import work from textual import work
from tui.config import list_conf_dir from tui.config import list_conf_dir
@@ -58,7 +58,9 @@ class SnapshotsScreen(Screen):
pass pass
def on_button_pressed(self, event: Button.Pressed) -> None: def on_button_pressed(self, event: Button.Pressed) -> None:
if event.button.id == "btn-load": if event.button.id == "btn-back":
self.app.pop_screen()
elif event.button.id == "btn-load":
self._load_snapshots() self._load_snapshots()
elif event.button.id == "btn-browse": elif event.button.id == "btn-browse":
self._browse_snapshot() self._browse_snapshot()
@@ -134,9 +136,5 @@ class SnapshotsScreen(Screen):
browser = SnapshotBrowser(f"{target} / {snapshot}", files) browser = SnapshotBrowser(f"{target} / {snapshot}", files)
self.app.push_screen(browser) self.app.push_screen(browser)
def on_click(self, event: Click) -> None:
if event.widget.id == "btn-back":
self.app.pop_screen()
def action_go_back(self) -> None: def action_go_back(self) -> None:
self.app.pop_screen() self.app.pop_screen()

View File

@@ -3,7 +3,7 @@ from textual.screen import Screen
from textual.widgets import Header, Footer, Static, Button, DataTable from textual.widgets import Header, Footer, Static, Button, DataTable
from tui.widgets.header import GnizaHeader as Header # noqa: F811 from tui.widgets.header import GnizaHeader as Header # noqa: F811
from textual.containers import Vertical, Horizontal from textual.containers import Vertical, Horizontal
from textual.events import Click
from tui.config import list_conf_dir, parse_conf, CONFIG_DIR from tui.config import list_conf_dir, parse_conf, CONFIG_DIR
from tui.widgets import ConfirmDialog, DocsPanel from tui.widgets import ConfirmDialog, DocsPanel
@@ -53,7 +53,9 @@ class TargetsScreen(Screen):
return None return None
def on_button_pressed(self, event: Button.Pressed) -> None: def on_button_pressed(self, event: Button.Pressed) -> None:
if event.button.id == "btn-add": if event.button.id == "btn-back":
self.app.pop_screen()
elif event.button.id == "btn-add":
self.app.push_screen("target_edit", callback=lambda _: self._refresh_table()) self.app.push_screen("target_edit", callback=lambda _: self._refresh_table())
elif event.button.id == "btn-edit": elif event.button.id == "btn-edit":
name = self._selected_target() name = self._selected_target()
@@ -79,9 +81,5 @@ class TargetsScreen(Screen):
self.notify(f"Source '{name}' deleted.") self.notify(f"Source '{name}' deleted.")
self._refresh_table() self._refresh_table()
def on_click(self, event: Click) -> None:
if event.widget.id == "btn-back":
self.app.pop_screen()
def action_go_back(self) -> None: def action_go_back(self) -> None:
self.app.pop_screen() self.app.pop_screen()