2022-10-10 20:34:50 +00:00
|
|
|
# preferences_window.py
|
2022-08-31 17:57:47 +00:00
|
|
|
#
|
|
|
|
# Change the look of Adwaita, with ease
|
2023-01-03 18:20:21 +00:00
|
|
|
# Copyright (C) 2022-2023, Gradience Team
|
2022-08-31 17:57:47 +00:00
|
|
|
#
|
|
|
|
# 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 <https://www.gnu.org/licenses/>.
|
|
|
|
|
2022-09-07 16:00:33 +00:00
|
|
|
from gi.repository import Gtk, Adw
|
2022-08-31 17:57:47 +00:00
|
|
|
|
2023-02-09 17:22:59 +00:00
|
|
|
from gradience.backend.flatpak_overrides import create_gtk_user_override, remove_gtk_user_override
|
|
|
|
from gradience.backend.flatpak_overrides import create_gtk_global_override, remove_gtk_global_override
|
|
|
|
|
2022-12-02 21:52:47 +00:00
|
|
|
from gradience.backend.constants import rootdir
|
2022-12-03 23:00:18 +00:00
|
|
|
|
|
|
|
from gradience.backend.logger import Logger
|
|
|
|
|
|
|
|
logging = Logger()
|
2022-08-31 17:57:47 +00:00
|
|
|
|
|
|
|
|
2022-10-10 20:34:50 +00:00
|
|
|
@Gtk.Template(resource_path=f"{rootdir}/ui/preferences_window.ui")
|
2022-08-31 17:57:47 +00:00
|
|
|
class GradiencePreferencesWindow(Adw.PreferencesWindow):
|
|
|
|
__gtype_name__ = "GradiencePreferencesWindow"
|
2022-09-01 16:19:45 +00:00
|
|
|
|
2023-02-09 17:22:59 +00:00
|
|
|
gtk4_user_theming_switch = Gtk.Template.Child()
|
|
|
|
gtk4_global_theming_switch = Gtk.Template.Child()
|
2022-09-03 20:47:45 +00:00
|
|
|
|
2023-02-09 17:22:59 +00:00
|
|
|
gtk3_user_theming_switch = Gtk.Template.Child()
|
|
|
|
gtk3_global_theming_switch = Gtk.Template.Child()
|
2022-08-31 17:57:47 +00:00
|
|
|
|
|
|
|
def __init__(self, parent, **kwargs):
|
|
|
|
super().__init__(**kwargs)
|
|
|
|
|
|
|
|
self.parent = parent
|
|
|
|
self.settings = parent.settings
|
2023-02-09 17:22:59 +00:00
|
|
|
|
2023-01-03 18:20:21 +00:00
|
|
|
self.app = self.parent.get_application()
|
2023-02-09 17:22:59 +00:00
|
|
|
self.win = self.app.get_active_window()
|
2022-08-31 17:57:47 +00:00
|
|
|
|
2023-02-09 17:22:59 +00:00
|
|
|
self.set_transient_for(self.win)
|
2023-01-03 16:21:20 +00:00
|
|
|
|
2022-08-31 17:57:47 +00:00
|
|
|
self.setup()
|
|
|
|
|
|
|
|
def setup(self):
|
|
|
|
self.setup_flatpak_group()
|
2022-09-01 16:19:45 +00:00
|
|
|
|
2022-08-31 17:57:47 +00:00
|
|
|
def setup_flatpak_group(self):
|
2022-09-03 20:47:45 +00:00
|
|
|
user_flatpak_theming_gtk4 = self.settings.get_boolean(
|
2022-09-07 15:52:50 +00:00
|
|
|
"user-flatpak-theming-gtk4"
|
|
|
|
)
|
2022-09-03 20:47:45 +00:00
|
|
|
|
|
|
|
user_flatpak_theming_gtk3 = self.settings.get_boolean(
|
2022-09-07 15:52:50 +00:00
|
|
|
"user-flatpak-theming-gtk3"
|
|
|
|
)
|
2022-09-03 20:47:45 +00:00
|
|
|
|
2023-02-09 17:22:59 +00:00
|
|
|
self.gtk4_user_theming_switch.set_state(
|
|
|
|
user_flatpak_theming_gtk4
|
|
|
|
)
|
2022-08-31 17:57:47 +00:00
|
|
|
|
2023-02-09 17:22:59 +00:00
|
|
|
# self.gtk4_global_theming_switch.set_state(global_flatpak_theming_gtk4)
|
|
|
|
|
|
|
|
self.gtk3_user_theming_switch.set_state(
|
|
|
|
user_flatpak_theming_gtk3
|
|
|
|
)
|
|
|
|
|
|
|
|
# self.gtk3_global_theming_switch.set_state(global_flatpak_theming_gtk3)
|
2022-08-31 17:57:47 +00:00
|
|
|
|
2023-02-09 17:22:59 +00:00
|
|
|
self.gtk4_user_theming_switch.connect(
|
|
|
|
"state-set", self.on_gtk4_user_theming_switch_toggled
|
2022-09-07 15:52:50 +00:00
|
|
|
)
|
2022-08-31 17:57:47 +00:00
|
|
|
|
2023-02-09 17:22:59 +00:00
|
|
|
self.gtk3_user_theming_switch.connect(
|
|
|
|
"state-set", self.on_gtk3_user_theming_switch_toggled
|
2022-09-07 15:52:50 +00:00
|
|
|
)
|
2022-09-03 20:47:45 +00:00
|
|
|
|
2023-02-09 17:22:59 +00:00
|
|
|
def on_gtk4_user_theming_switch_toggled(self, *args):
|
|
|
|
state = self.gtk4_user_theming_switch.props.state
|
2022-08-31 17:57:47 +00:00
|
|
|
|
2022-09-01 16:19:45 +00:00
|
|
|
if not state:
|
2022-12-11 11:53:18 +00:00
|
|
|
create_gtk_user_override(self.settings, "gtk4", self)
|
2022-08-31 17:57:47 +00:00
|
|
|
else:
|
2022-12-11 11:53:18 +00:00
|
|
|
remove_gtk_user_override(self.settings, "gtk4", self)
|
2022-08-31 17:57:47 +00:00
|
|
|
|
2022-12-03 23:00:18 +00:00
|
|
|
logging.debug(
|
2022-09-07 15:52:50 +00:00
|
|
|
f"user-flatpak-theming-gtk4: {self.settings.get_boolean('user-flatpak-theming-gtk4')}"
|
|
|
|
)
|
2022-09-03 20:47:45 +00:00
|
|
|
|
2023-02-09 17:22:59 +00:00
|
|
|
def on_gtk3_user_theming_switch_toggled(self, *args):
|
|
|
|
state = self.gtk3_user_theming_switch.props.state
|
2022-09-03 20:47:45 +00:00
|
|
|
|
|
|
|
if not state:
|
2022-12-11 11:53:18 +00:00
|
|
|
create_gtk_user_override(self.settings, "gtk3", self)
|
2022-09-03 20:47:45 +00:00
|
|
|
else:
|
2022-12-11 11:53:18 +00:00
|
|
|
remove_gtk_user_override(self.settings, "gtk3", self)
|
2022-09-03 20:47:45 +00:00
|
|
|
|
2022-12-03 23:00:18 +00:00
|
|
|
logging.debug(
|
2022-09-07 15:52:50 +00:00
|
|
|
f"user-flatpak-theming-gtk3: {self.settings.get_boolean('user-flatpak-theming-gtk3')}"
|
|
|
|
)
|
2022-08-31 17:57:47 +00:00
|
|
|
|
2023-02-09 17:22:59 +00:00
|
|
|
def on_gtk4_global_theming_switch_toggled(self, *args):
|
|
|
|
state = self.gtk4_global_theming_switch.props.state
|
2022-09-03 20:47:45 +00:00
|
|
|
|
|
|
|
if not state:
|
2022-12-11 11:53:18 +00:00
|
|
|
create_gtk_global_override(self.settings, "gtk4", self)
|
2022-09-03 20:47:45 +00:00
|
|
|
else:
|
2022-12-11 11:53:18 +00:00
|
|
|
remove_gtk_global_override(self.settings, "gtk4", self)
|
2022-09-03 20:47:45 +00:00
|
|
|
|
2022-12-03 23:00:18 +00:00
|
|
|
logging.debug(
|
2022-09-07 15:52:50 +00:00
|
|
|
f"global-flatpak-theming-gtk4: {self.settings.get_boolean('global-flatpak-theming-gtk4')}"
|
|
|
|
)
|
2022-09-05 16:40:09 +00:00
|
|
|
|
2023-02-09 17:22:59 +00:00
|
|
|
def on_gtk3_global_theming_switch_toggled(self, *args):
|
|
|
|
state = self.gtk3_global_theming_switch.props.state
|
2022-08-31 17:57:47 +00:00
|
|
|
|
2022-09-01 16:19:45 +00:00
|
|
|
if not state:
|
2022-12-11 11:53:18 +00:00
|
|
|
create_gtk_global_override(self.settings, "gtk3", self)
|
2022-08-31 17:57:47 +00:00
|
|
|
else:
|
2022-12-11 11:53:18 +00:00
|
|
|
remove_gtk_global_override(self.settings, "gtk3", self)
|
2022-09-03 20:47:45 +00:00
|
|
|
|
2022-12-03 23:00:18 +00:00
|
|
|
logging.debug(
|
2022-09-07 15:52:50 +00:00
|
|
|
f"global-flatpak-theming-gtk3: {self.settings.get_boolean('global-flatpak-theming-gtk3')}"
|
|
|
|
)
|