mirror of
https://github.com/GradienceTeam/Gradience.git
synced 2024-11-02 19:44:00 +00:00
e412a2c537
Signed-off-by: tfuxu <73042332+tfuxu@users.noreply.github.com> Co-authored-by: 0xMRTT <0xMRTT@evta.fr> Co-authored-by: 0xMRTT <0xMRTT@proton.me> Co-authored-by: daudix-UFO <ddaudix@gmail.com>
94 lines
3.3 KiB
Python
94 lines
3.3 KiB
Python
# shell_prefs_window.py
|
|
#
|
|
# Change the look of Adwaita, with ease
|
|
# Copyright (C) 2023, Gradience Team
|
|
#
|
|
# 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/>.
|
|
|
|
from gi.repository import Gtk, Adw
|
|
|
|
from gradience.backend.utils.colors import rgb_to_hash
|
|
from gradience.backend.constants import rootdir
|
|
|
|
from gradience.frontend.widgets.option_row import GradienceOptionRow
|
|
from gradience.frontend.schemas.shell_schema import shell_schema
|
|
|
|
from gradience.backend.logger import Logger
|
|
|
|
logging = Logger()
|
|
|
|
|
|
@Gtk.Template(resource_path=f"{rootdir}/ui/shell_prefs_window.ui")
|
|
class GradienceShellPrefsWindow(Adw.PreferencesWindow):
|
|
__gtype_name__ = "GradienceShellPrefsWindow"
|
|
|
|
custom_colors_group = Gtk.Template.Child("custom-colors-group")
|
|
|
|
def __init__(self, parent, shell_colors: dict, **kwargs):
|
|
super().__init__(**kwargs)
|
|
|
|
self.shell_colors = shell_colors
|
|
|
|
self.parent = parent
|
|
self.settings = parent.settings
|
|
self.app = self.parent.get_application()
|
|
|
|
self.set_transient_for(self.app.get_active_window())
|
|
|
|
self.setup()
|
|
|
|
def setup(self):
|
|
for variable in shell_schema["variables"]:
|
|
pref_variable = GradienceOptionRow(
|
|
variable["name"],
|
|
variable["title"]
|
|
#variable.get("explanation")
|
|
)
|
|
self.custom_colors_group.add(pref_variable)
|
|
|
|
pref_variable.color_value.connect("color-set", self.on_color_value_changed, pref_variable)
|
|
pref_variable.text_value.connect("changed", self.on_text_value_changed, pref_variable)
|
|
|
|
self.set_colors(pref_variable, variable)
|
|
|
|
def set_colors(self, widget, variable):
|
|
if len(self.shell_colors) != len(shell_schema["variables"]):
|
|
try:
|
|
self.shell_colors[variable["name"]] = variable["default_value"]
|
|
except KeyError:
|
|
try:
|
|
self.shell_colors[variable["name"]] = self.app.variables[variable["var_name"]]
|
|
except KeyError:
|
|
raise
|
|
finally:
|
|
widget.update_value(self.shell_colors[variable["name"]])
|
|
else:
|
|
widget.update_value(self.shell_colors[variable["name"]])
|
|
|
|
def on_color_value_changed(self, widget, parent, *_args):
|
|
color_name = parent.props.name
|
|
color_value = widget.get_rgba().to_string()
|
|
|
|
if color_value.startswith("rgb") or color_value.startswith("rgba"):
|
|
color_hex, alpha = rgb_to_hash(color_value)
|
|
if not alpha:
|
|
color_value = color_hex
|
|
|
|
self.shell_colors[color_name] = color_value
|
|
|
|
def on_text_value_changed(self, widget, parent, *_args):
|
|
color_name = parent.props.name
|
|
color_value = widget.get_text()
|
|
|
|
self.shell_colors[color_name] = color_value
|