From 6db3557cff05466df7f386d14eb8cfd335fd5700 Mon Sep 17 00:00:00 2001 From: kramo <93832451+kra-mo@users.noreply.github.com> Date: Sat, 8 Jul 2023 00:47:24 +0200 Subject: [PATCH] Add a game counter to total games --- data/gtk/window.blp | 18 ++++++++++++++++-- src/preferences.py | 6 ++++++ src/shared.py.in | 2 ++ src/window.py | 25 ++++++++++++++++--------- 4 files changed, 40 insertions(+), 11 deletions(-) diff --git a/data/gtk/window.blp b/data/gtk/window.blp index a2e115e..99f31d0 100644 --- a/data/gtk/window.blp +++ b/data/gtk/window.blp @@ -93,7 +93,6 @@ template $CartridgesWindow : Adw.ApplicationWindow { margin-top: 12; margin-bottom: 12; margin-start: 6; - margin-end: 6; spacing: 12; Image { @@ -102,13 +101,20 @@ template $CartridgesWindow : Adw.ApplicationWindow { Label { halign: start; label: _("All Games"); + margin-end: 6; + } + Label all_games_no_label { + hexpand: true; + halign: end; + margin-end: 6; + + styles ["dim-label"] } } Box added_row_box { margin-top: 12; margin-bottom: 12; margin-start: 6; - margin-end: 6; spacing: 12; Image { @@ -117,6 +123,14 @@ template $CartridgesWindow : Adw.ApplicationWindow { Label { halign: start; label: _("Added"); + margin-end: 6; + } + Label added_games_no_label { + hexpand: true; + halign: end; + margin-end: 6; + + styles ["dim-label"] } } ListBoxRow { diff --git a/src/preferences.py b/src/preferences.py index afc9ec7..7fa5a0a 100644 --- a/src/preferences.py +++ b/src/preferences.py @@ -203,6 +203,7 @@ class PreferencesWindow(Adw.PreferencesWindow): self.file_chooser.select_folder(self.win, None, callback, callback_data) def undo_remove_all(self, *_args): + shared.win.get_application().state = shared.AppState.UNDO_REMOVE_ALL_GAMES for game in self.removed_games: game.removed = False game.save() @@ -210,8 +211,11 @@ class PreferencesWindow(Adw.PreferencesWindow): self.removed_games = set() self.toast.dismiss() + shared.win.get_application().state = shared.AppState.DEFAULT + shared.win.create_source_rows() def remove_all_games(self, *_args): + shared.win.get_application().state = shared.AppState.REMOVE_ALL_GAMES for game in shared.store: if not game.removed: self.removed_games.add(game) @@ -223,6 +227,8 @@ class PreferencesWindow(Adw.PreferencesWindow): self.win.navigation_view.pop() self.add_toast(self.toast) + shared.win.get_application().state = shared.AppState.DEFAULT + shared.win.create_source_rows() def reset_app(self, *_args): rmtree(shared.data_dir / "cartridges", True) diff --git a/src/shared.py.in b/src/shared.py.in index 81e31b1..d5fa386 100644 --- a/src/shared.py.in +++ b/src/shared.py.in @@ -28,6 +28,8 @@ class AppState(IntEnum): DEFAULT = auto() LOAD_FROM_DISK = auto() IMPORT = auto() + REMOVE_ALL_GAMES = auto() + UNDO_REMOVE_ALL_GAMES = auto() APP_ID = "@APP_ID@" diff --git a/src/window.py b/src/window.py index acb74a6..cd200d3 100644 --- a/src/window.py +++ b/src/window.py @@ -31,7 +31,9 @@ class CartridgesWindow(Adw.ApplicationWindow): navigation_view = Gtk.Template.Child() sidebar = Gtk.Template.Child() all_games_row_box = Gtk.Template.Child() + all_games_no_label = Gtk.Template.Child() added_row_box = Gtk.Template.Child() + added_games_no_label = Gtk.Template.Child() toast_overlay = Gtk.Template.Child() primary_menu_button = Gtk.Template.Child() show_sidebar_button = Gtk.Template.Child() @@ -89,6 +91,7 @@ class CartridgesWindow(Adw.ApplicationWindow): (count,) if (count := sum(removed)) != len(removed) else False ) # Return a tuple because 0 == False and 1 == True + total_games_no = 0 restored = False selected_id = ( @@ -102,9 +105,14 @@ class CartridgesWindow(Adw.ApplicationWindow): restored = True if added_missing := ( - not shared.store.source_games.get("imported") or not get_removed("imported") + not shared.store.source_games.get("imported") + or not (removed := get_removed("imported")) ): self.sidebar.select_row(self.all_games_row_box.get_parent()) + else: + games_no = len(shared.store.source_games["imported"]) - removed[0] + self.added_games_no_label.set_label(str(games_no)) + total_games_no += games_no self.added_row_box.get_parent().set_visible(not added_missing) self.sidebar.get_row_at_index(2).set_visible(False) @@ -118,15 +126,14 @@ class CartridgesWindow(Adw.ApplicationWindow): if not (removed := get_removed(source_id)): continue - row = Gtk.Box() + row = Gtk.Box(margin_top=12, margin_bottom=12) games_no = len(shared.store.source_games[source_id]) - removed[0] + total_games_no += games_no row.append( Gtk.Label( label=self.get_application().get_source_name(source_id), halign=Gtk.Align.START, - margin_top=12, - margin_bottom=12, margin_start=6, margin_end=6, ) @@ -137,9 +144,7 @@ class CartridgesWindow(Adw.ApplicationWindow): label=games_no, hexpand=True, halign=Gtk.Align.END, - margin_top=12, - margin_bottom=12, - margin_end=12, + margin_end=6, ) ) @@ -166,8 +171,10 @@ class CartridgesWindow(Adw.ApplicationWindow): self.sidebar.get_row_at_index(2).set_visible(True) - if not restored: - self.sidebar.select_row(self.all_games_row_box.get_parent()) + self.all_games_no_label.set_label(str(total_games_no)) + + if not restored: + self.sidebar.select_row(self.all_games_row_box.get_parent()) def row_selected(self, _widget, row): if not row: