Skip to content

Commit

Permalink
Add Preferences Window & Theme Preview Toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
Foldex committed Apr 16, 2023
1 parent a905504 commit 4343617
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 4 deletions.
4 changes: 4 additions & 0 deletions data/io.github.Foldex.AdwSteamGtk.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,9 @@
<default>false</default>
</key>

<key name="prefs-ui-preview-theme" type="b">
<default>true</default>
</key>

</schema>
</schemalist>
5 changes: 4 additions & 1 deletion src/adwaita_steam_gtk.gresource.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/io/github/Foldex/AdwSteamGtk">
<file>window.ui</file>
<file>ui/window.ui</file>
</gresource>
<gresource prefix="/io/github/Foldex/AdwSteamGtk">
<file>ui/prefs.ui</file>
</gresource>
</gresources>
7 changes: 7 additions & 0 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
from . import cli
from . import info
from . import update

from .window import AdwaitaSteamGtkWindow
from .prefs import AdwaitaSteamGtkPrefs


class Adwaita_steam_gtkApplication(Adw.Application):
Expand All @@ -37,6 +39,7 @@ def __init__(self):

self.create_action('quit', self.on_quit_action, ['<primary>q'])
self.create_action('about', self.on_about_action)
self.create_action('prefs', self.on_prefs_action)

self.add_main_option(
"check",
Expand Down Expand Up @@ -121,6 +124,10 @@ def on_about_action(self, widget, _):
about.add_credit_section('Upstream', info.UPSTREAM)
about.present()

def on_prefs_action(self, widget, _):
prefs = AdwaitaSteamGtkPrefs(self.props.active_window)
prefs.present()

def on_quit_action(self, widget, _):
self.quit()

Expand Down
6 changes: 4 additions & 2 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ gnome = import('gnome')

blueprints = custom_target('blueprints',
input: files(
'window.blp',
'ui/window.blp',
'ui/prefs.blp',
),
output: '.',
command: [find_program('blueprint-compiler'), 'batch-compile', '@OUTPUT@', '@CURRENT_SOURCE_DIR@', '@INPUT@'],
Expand Down Expand Up @@ -55,14 +56,15 @@ configure_file(
adwaita_steam_gtk_sources = [
'__init__.py',
'main.py',
'window.py',
'cli.py',
'dl.py',
'install.py',
'paths.py',
'style.py',
'update.py',
'zip.py',
'pages/window.py',
'pages/prefs.py',
]

install_data(adwaita_steam_gtk_sources, install_dir: moduledir)
44 changes: 44 additions & 0 deletions src/pages/prefs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# prefs.py
#
# Copyright 2022 Foldex
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from gi.repository import Adw, Gtk

@Gtk.Template(resource_path='/io/github/Foldex/AdwSteamGtk/ui/prefs.ui')
class AdwaitaSteamGtkPrefs(Adw.PreferencesWindow):
__gtype_name__ = 'AdwaitaSteamGtkPrefs'

preview_theme_switch = Gtk.Template.Child()

def __init__(self, parent, **kwargs):
super().__init__(**kwargs)
self.parent = parent
self.settings = parent.settings
self.app = self.parent.get_application()
self.win = self.app.get_active_window()
self.set_transient_for(self.win)

self.load_config()

def load_config(self):
preview_theme = self.settings.get_boolean("prefs-ui-preview-theme")
self.preview_theme_switch.set_active(preview_theme)
self.preview_theme_switch.connect("state-set", self.on_preview_theme_switch_toggle)

def on_preview_theme_switch_toggle(self, *args):
state = not self.preview_theme_switch.props.state
self.settings.set_boolean("prefs-ui-preview-theme", state)
self.parent.load_app_style(self.parent.color_theme_options, None)
8 changes: 7 additions & 1 deletion src/window.py → src/pages/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from . import update
from . import zip

@Gtk.Template(resource_path='/io/github/Foldex/AdwSteamGtk/window.ui')
@Gtk.Template(resource_path='/io/github/Foldex/AdwSteamGtk/ui/window.ui')
class AdwaitaSteamGtkWindow(Gtk.ApplicationWindow):
__gtype_name__ = 'AdwaitaSteamGtkWindow'

Expand Down Expand Up @@ -60,6 +60,12 @@ def load_app_style(self, comborow, _):
self.style_provider = Gtk.CssProvider()
Gtk.StyleContext.add_provider_for_display(Gdk.Display.get_default(), self.style_provider, Gtk.STYLE_PROVIDER_PRIORITY_USER + 1)

preview_theme = self.settings.get_boolean("prefs-ui-preview-theme")

if not preview_theme:
self.style_provider.load_from_data("", -1)
return

selected_theme = self.get_selected_pref(comborow).lower()
ret, msg = style.generate_style(selected_theme)

Expand Down
24 changes: 24 additions & 0 deletions src/ui/prefs.blp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Gtk 4.0;
using Adw 1;

template AdwaitaSteamGtkPrefs : Adw.PreferencesWindow {
title: _("Preferences");
default-height: 400;
default-width: 600;
modal: true;

Adw.PreferencesPage general_page {
Adw.PreferencesGroup ui_group {
title: _("Interface");

Adw.ActionRow {
title: _("Preview Themes");
subtitle: _("Styles the interface to match the currently selected theme.");
activatable-widget: preview_theme_switch;
Gtk.Switch preview_theme_switch {
valign: center;
}
}
}
}
}
4 changes: 4 additions & 0 deletions src/window.blp → src/ui/window.blp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ template AdwaitaSteamGtkWindow : ApplicationWindow {

menu primary_menu {
section {
item {
label: _("_Preferences");
action: "app.prefs";
}
item {
label: _("_About AdwSteamGtk");
action: "app.about";
Expand Down

0 comments on commit 4343617

Please sign in to comment.