From 536e6792e7074f04c8da31e4487591e7c0bd18d0 Mon Sep 17 00:00:00 2001 From: kramo <93832451+kra-mo@users.noreply.github.com> Date: Tue, 4 Jul 2023 19:04:39 +0200 Subject: [PATCH] Port to Adw.SwitchRow --- data/gtk/preferences.blp | 77 ++++++---------------------------------- src/preferences.py | 19 +++++----- 2 files changed, 20 insertions(+), 76 deletions(-) diff --git a/data/gtk/preferences.blp b/data/gtk/preferences.blp index fbc2dee..902e6b7 100644 --- a/data/gtk/preferences.blp +++ b/data/gtk/preferences.blp @@ -12,37 +12,22 @@ template $PreferencesWindow : Adw.PreferencesWindow { Adw.PreferencesGroup behavior_group { title: _("Behavior"); - Adw.ActionRow { + Adw.SwitchRow exit_after_launch_switch { title: _("Exit After Launching Games"); - activatable-widget: exit_after_launch_switch; - - Switch exit_after_launch_switch { - valign: center; - } } - Adw.ActionRow { + Adw.SwitchRow cover_launches_game_switch { title: _("Cover Image Launches Game"); subtitle: _("Swaps the behavior of the cover image and the play button"); - activatable-widget: cover_launches_game_switch; - - Switch cover_launches_game_switch { - valign: center; - } } } Adw.PreferencesGroup images_group { title: _("Images"); - Adw.ActionRow { + Adw.SwitchRow high_quality_images_switch { title: _("High Quality Images"); subtitle: _("Save game covers losslessly at the cost of storage"); - activatable-widget: high_quality_images_switch; - - Switch high_quality_images_switch { - valign: center; - } } } @@ -124,22 +109,12 @@ template $PreferencesWindow : Adw.PreferencesWindow { } } - Adw.ActionRow { + Adw.SwitchRow lutris_import_steam_switch { title: _("Import Steam Games"); - activatable-widget: lutris_import_steam_switch; - - Switch lutris_import_steam_switch { - valign: center; - } } - Adw.ActionRow { + Adw.SwitchRow lutris_import_flatpak_switch { title: _("Import Flatpak Games"); - activatable-widget: lutris_import_flatpak_switch; - - Switch lutris_import_flatpak_switch { - valign: center; - } } } @@ -156,31 +131,16 @@ template $PreferencesWindow : Adw.PreferencesWindow { } } - Adw.ActionRow { + Adw.SwitchRow heroic_import_epic_switch { title: _("Import Epic Games"); - activatable-widget: heroic_import_epic_switch; - - Switch heroic_import_epic_switch { - valign: center; - } } - Adw.ActionRow { + Adw.SwitchRow heroic_import_gog_switch { title: _("Import GOG Games"); - activatable-widget: heroic_import_gog_switch; - - Switch heroic_import_gog_switch { - valign: center; - } } - Adw.ActionRow { + Adw.SwitchRow heroic_import_sideload_switch { title: _("Import Sideloaded Games"); - activatable-widget: heroic_import_sideload_switch; - - Switch heroic_import_sideload_switch { - valign: center; - } } } @@ -267,32 +227,17 @@ template $PreferencesWindow : Adw.PreferencesWindow { Adw.PreferencesGroup sgdb_behavior_group { title: _("Behavior"); - Adw.ActionRow sgdb_switch_row { + Adw.SwitchRow sgdb_switch { title: _("Use SteamGridDB"); subtitle: _("Download images when adding or importing games"); - activatable-widget: sgdb_switch; - - Switch sgdb_switch { - valign: center; - } } - Adw.ActionRow { + Adw.SwitchRow sgdb_prefer_switch { title: _("Prefer Over Official Images"); - activatable-widget: sgdb_prefer_switch; - - Switch sgdb_prefer_switch { - valign: center; - } } - Adw.ActionRow { + Adw.SwitchRow sgdb_animated_switch { title: _("Prefer Animated Images"); - activatable-widget: sgdb_animated_switch; - - Switch sgdb_animated_switch { - valign: center; - } } } } diff --git a/src/preferences.py b/src/preferences.py index 4653764..abdc307 100644 --- a/src/preferences.py +++ b/src/preferences.py @@ -90,7 +90,6 @@ class PreferencesWindow(Adw.PreferencesWindow): sgdb_key_group = Gtk.Template.Child() sgdb_key_entry_row = Gtk.Template.Child() sgdb_switch = Gtk.Template.Child() - sgdb_switch_row = Gtk.Template.Child() sgdb_prefer_switch = Gtk.Template.Child() sgdb_animated_switch = Gtk.Template.Child() @@ -162,15 +161,6 @@ class PreferencesWindow(Adw.PreferencesWindow): ) ) - def set_sgdb_sensitive(widget): - if not widget.get_text(): - shared.schema.set_boolean("sgdb", False) - - self.sgdb_switch_row.set_sensitive(widget.get_text()) - - self.sgdb_key_entry_row.connect("changed", set_sgdb_sensitive) - set_sgdb_sensitive(self.sgdb_key_entry_row) - # Switches self.bind_switches( ( @@ -189,6 +179,15 @@ class PreferencesWindow(Adw.PreferencesWindow): ) ) + def set_sgdb_sensitive(widget): + if not widget.get_text(): + shared.schema.set_boolean("sgdb", False) + + self.sgdb_switch.set_sensitive(widget.get_text()) + + self.sgdb_key_entry_row.connect("changed", set_sgdb_sensitive) + set_sgdb_sensitive(self.sgdb_key_entry_row) + def get_switch(self, setting): return getattr(self, f'{setting.replace("-", "_")}_switch')