2022-07-17 11:46:05 +00:00
|
|
|
|
# main.py
|
|
|
|
|
#
|
2022-08-11 08:16:44 +00:00
|
|
|
|
# Change the look of Adwaita, with ease
|
2022-08-15 23:19:03 +00:00
|
|
|
|
# Copyright (C) 2022 Gradience Team
|
2022-07-17 11:46:05 +00:00
|
|
|
|
#
|
2022-08-11 08:16:44 +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.
|
2022-08-11 16:39:24 +00:00
|
|
|
|
#
|
2022-08-11 08:16:44 +00:00
|
|
|
|
# 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.
|
2022-08-11 16:39:24 +00:00
|
|
|
|
#
|
2022-08-11 08:16:44 +00:00
|
|
|
|
# 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-07-17 11:46:05 +00:00
|
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
import json
|
2022-07-17 17:07:40 +00:00
|
|
|
|
import os
|
2022-09-24 18:20:17 +00:00
|
|
|
|
import threading
|
|
|
|
|
|
|
|
|
|
from pathlib import Path
|
2022-08-11 12:22:08 +00:00
|
|
|
|
from material_color_utilities_python import *
|
2022-07-29 11:56:36 +00:00
|
|
|
|
|
2022-09-24 18:20:17 +00:00
|
|
|
|
from gi.repository import Gtk, Gdk, Gio, Adw, GLib, Xdp, XdpGtk4
|
|
|
|
|
|
2022-10-10 19:20:35 +00:00
|
|
|
|
from gradience.settings_schema import settings_schema
|
|
|
|
|
from gradience.ui.window import GradienceMainWindow
|
|
|
|
|
from gradience.ui.app_type_dialog import GradienceAppTypeDialog
|
|
|
|
|
from gradience.ui.custom_css_group import GradienceCustomCSSGroup
|
|
|
|
|
from gradience.constants import (
|
2022-09-07 15:52:50 +00:00
|
|
|
|
rootdir,
|
|
|
|
|
app_id,
|
|
|
|
|
rel_ver,
|
|
|
|
|
version,
|
|
|
|
|
bugtracker_url,
|
|
|
|
|
help_url,
|
|
|
|
|
project_url,
|
|
|
|
|
)
|
2022-10-10 19:20:35 +00:00
|
|
|
|
from gradience.modules.css import load_preset_from_css
|
|
|
|
|
from gradience.ui.welcome import GradienceWelcomeWindow
|
|
|
|
|
from gradience.ui.preferences import GradiencePreferencesWindow
|
|
|
|
|
from gradience.modules.utils import to_slug_case, buglog, run_command
|
|
|
|
|
from gradience.plugins_list import GradiencePluginsList
|
|
|
|
|
from gradience.ui.presets_manager_window import GradiencePresetWindow
|
|
|
|
|
from gradience.modules.preset import Preset, presets_dir
|
2022-09-14 12:49:39 +00:00
|
|
|
|
|
|
|
|
|
|
2022-08-19 19:14:05 +00:00
|
|
|
|
class GradienceApplication(Adw.Application):
|
2022-07-17 11:46:05 +00:00
|
|
|
|
"""The main application singleton class."""
|
2022-09-07 15:52:50 +00:00
|
|
|
|
|
2022-08-31 17:57:47 +00:00
|
|
|
|
__gtype_name__ = "GradienceApplication"
|
|
|
|
|
|
|
|
|
|
settings = Gio.Settings.new(app_id)
|
2022-07-17 11:46:05 +00:00
|
|
|
|
|
2022-08-15 18:33:41 +00:00
|
|
|
|
def __init__(self):
|
2022-09-23 11:14:21 +00:00
|
|
|
|
super().__init__(application_id=app_id, flags=Gio.ApplicationFlags.FLAGS_NONE)
|
2022-08-15 18:33:41 +00:00
|
|
|
|
self.set_resource_base_path(rootdir)
|
2022-07-17 11:46:05 +00:00
|
|
|
|
|
2022-07-24 11:00:05 +00:00
|
|
|
|
self.portal = Xdp.Portal()
|
2022-07-29 11:56:36 +00:00
|
|
|
|
|
2022-08-01 17:09:45 +00:00
|
|
|
|
self.preset_name = ""
|
2022-08-01 19:42:42 +00:00
|
|
|
|
self.is_dirty = False
|
2022-08-01 17:09:45 +00:00
|
|
|
|
|
2022-07-17 15:02:29 +00:00
|
|
|
|
self.variables = {}
|
2022-07-29 11:56:36 +00:00
|
|
|
|
self.pref_variables = {}
|
|
|
|
|
|
2022-07-21 19:03:18 +00:00
|
|
|
|
self.palette = {}
|
2022-07-29 11:56:36 +00:00
|
|
|
|
self.pref_palette_shades = {}
|
|
|
|
|
|
2022-07-24 17:46:37 +00:00
|
|
|
|
self.custom_css = {}
|
2022-07-29 11:56:36 +00:00
|
|
|
|
self.custom_css_group = None
|
|
|
|
|
|
|
|
|
|
self.custom_presets = {}
|
2022-07-21 19:03:18 +00:00
|
|
|
|
self.global_errors = []
|
2022-07-24 17:46:37 +00:00
|
|
|
|
self.current_css_provider = None
|
2022-07-29 11:56:36 +00:00
|
|
|
|
|
2022-07-17 15:02:29 +00:00
|
|
|
|
self.is_ready = False
|
|
|
|
|
|
2022-08-19 21:28:32 +00:00
|
|
|
|
self.first_run = self.settings.get_boolean("first-run")
|
2022-09-22 05:13:26 +00:00
|
|
|
|
self.last_opened_version = self.settings.get_string(
|
|
|
|
|
"last-opened-version")
|
2022-08-19 19:00:45 +00:00
|
|
|
|
|
2022-09-28 12:05:32 +00:00
|
|
|
|
self.favourite = set(self.settings.get_value("favourite"))
|
|
|
|
|
|
2022-08-20 16:15:28 +00:00
|
|
|
|
self.style_manager = Adw.StyleManager.get_default()
|
2022-09-04 09:25:39 +00:00
|
|
|
|
|
2022-09-22 17:55:19 +00:00
|
|
|
|
self.preset = None
|
|
|
|
|
|
2022-07-29 11:56:36 +00:00
|
|
|
|
def do_activate(self):
|
|
|
|
|
"""Called when the application is activated.
|
|
|
|
|
|
|
|
|
|
We raise the application's main window, creating it if
|
|
|
|
|
necessary.
|
|
|
|
|
"""
|
|
|
|
|
|
2022-08-10 15:11:39 +00:00
|
|
|
|
self.win = self.props.active_window
|
|
|
|
|
if not self.win:
|
2022-09-17 14:23:27 +00:00
|
|
|
|
self.win = GradienceMainWindow(
|
|
|
|
|
application=self,
|
|
|
|
|
default_height=self.settings.get_int("window-height"),
|
|
|
|
|
default_width=self.settings.get_int("window-width"),
|
|
|
|
|
fullscreened=self.settings.get_boolean("window-fullscreen"),
|
2022-09-17 17:10:00 +00:00
|
|
|
|
maximized=self.settings.get_boolean("window-maximized"),
|
2022-09-17 14:23:27 +00:00
|
|
|
|
)
|
2022-09-04 09:08:32 +00:00
|
|
|
|
self.plugins_list = GradiencePluginsList(self.win)
|
2022-09-10 08:19:54 +00:00
|
|
|
|
self.setup_plugins()
|
2022-07-17 11:46:05 +00:00
|
|
|
|
|
2022-07-24 11:00:05 +00:00
|
|
|
|
self.create_action("open_preset_directory", self.open_preset_directory)
|
2022-08-10 08:46:52 +00:00
|
|
|
|
self.create_stateful_action(
|
|
|
|
|
"load_preset",
|
|
|
|
|
GLib.VariantType.new("s"),
|
|
|
|
|
GLib.Variant("s", "adwaita"),
|
|
|
|
|
self.load_preset_action,
|
|
|
|
|
)
|
2022-09-07 15:52:50 +00:00
|
|
|
|
self.create_action("apply_color_scheme",
|
|
|
|
|
self.show_apply_color_scheme_dialog)
|
2022-08-20 00:14:58 +00:00
|
|
|
|
|
2022-09-07 15:52:50 +00:00
|
|
|
|
self.create_action("show_adwaita_demo", self.show_adwaita_demo)
|
2022-08-20 01:43:47 +00:00
|
|
|
|
|
2022-09-07 15:52:50 +00:00
|
|
|
|
self.create_action("show_gtk4_widget_factory",
|
|
|
|
|
self.show_gtk4_widget_factory)
|
2022-08-20 01:43:47 +00:00
|
|
|
|
|
2022-09-07 15:52:50 +00:00
|
|
|
|
self.create_action("show_gtk4_demo", self.show_gtk4_demo)
|
2022-08-20 01:43:47 +00:00
|
|
|
|
|
2022-09-01 13:09:59 +00:00
|
|
|
|
self.create_action(
|
2022-09-07 15:52:50 +00:00
|
|
|
|
"restore_color_scheme", self.show_restore_color_scheme_dialog
|
|
|
|
|
)
|
2022-09-24 18:20:17 +00:00
|
|
|
|
self.create_action("manage_presets", self.show_presets_manager)
|
2022-09-01 13:22:24 +00:00
|
|
|
|
|
2022-09-07 15:52:50 +00:00
|
|
|
|
self.create_action("reset_color_scheme",
|
|
|
|
|
self.show_reset_color_scheme_dialog)
|
2022-08-31 17:57:47 +00:00
|
|
|
|
self.create_action("preferences", self.show_preferences)
|
2022-07-18 10:51:25 +00:00
|
|
|
|
self.create_action("save_preset", self.show_save_preset_dialog)
|
2022-07-17 11:46:05 +00:00
|
|
|
|
self.create_action("about", self.show_about_window)
|
2022-09-13 19:14:09 +00:00
|
|
|
|
self.load_preset_from_css()
|
2022-08-01 09:31:36 +00:00
|
|
|
|
|
2022-09-13 21:01:29 +00:00
|
|
|
|
self.reload_user_defined_presets()
|
|
|
|
|
|
2022-09-25 20:45:04 +00:00
|
|
|
|
if self.first_run:
|
2022-09-22 20:56:52 +00:00
|
|
|
|
welcome = GradienceWelcomeWindow(self.win)
|
|
|
|
|
welcome.present()
|
2022-08-19 21:28:32 +00:00
|
|
|
|
else:
|
2022-09-25 21:13:44 +00:00
|
|
|
|
if rel_ver != self.last_opened_version:
|
2022-09-25 20:45:04 +00:00
|
|
|
|
welcome = GradienceWelcomeWindow(self.win, update=True)
|
|
|
|
|
welcome.present()
|
|
|
|
|
else:
|
|
|
|
|
buglog("normal run")
|
|
|
|
|
self.win.present()
|
2022-08-19 21:28:32 +00:00
|
|
|
|
|
2022-09-28 12:05:32 +00:00
|
|
|
|
def save_favourite(self):
|
2022-09-28 12:46:35 +00:00
|
|
|
|
self.settings.set_value(
|
|
|
|
|
"favourite", GLib.Variant("as", self.favourite))
|
2022-09-28 12:05:32 +00:00
|
|
|
|
|
2022-09-13 21:01:29 +00:00
|
|
|
|
def reload_user_defined_presets(self):
|
|
|
|
|
if self.props.active_window.presets_menu.get_n_items() > 1:
|
|
|
|
|
self.props.active_window.presets_menu.remove(1)
|
|
|
|
|
|
2022-10-02 01:57:29 +00:00
|
|
|
|
if not os.path.exists(presets_dir):
|
|
|
|
|
os.makedirs(presets_dir)
|
2022-09-13 21:01:29 +00:00
|
|
|
|
|
|
|
|
|
self.custom_presets = {"user": {}}
|
2022-10-02 01:57:29 +00:00
|
|
|
|
for repo in Path(presets_dir).iterdir():
|
2022-09-13 21:01:29 +00:00
|
|
|
|
if repo.is_dir(): # repo
|
|
|
|
|
presets_list = {}
|
|
|
|
|
for file_name in repo.iterdir():
|
|
|
|
|
file_name = str(file_name)
|
|
|
|
|
if file_name.endswith(".json"):
|
|
|
|
|
try:
|
|
|
|
|
with open(
|
2022-10-02 01:57:29 +00:00
|
|
|
|
os.path.join(presets_dir, file_name),
|
2022-09-13 21:01:29 +00:00
|
|
|
|
"r",
|
|
|
|
|
encoding="utf-8",
|
|
|
|
|
) as file:
|
|
|
|
|
preset_text = file.read()
|
|
|
|
|
preset = json.loads(preset_text)
|
|
|
|
|
if preset.get("variables") is None:
|
|
|
|
|
raise KeyError("variables")
|
|
|
|
|
if preset.get("palette") is None:
|
|
|
|
|
raise KeyError("palette")
|
2022-09-23 11:14:21 +00:00
|
|
|
|
presets_list[file_name.replace(".json", "")] = preset[
|
|
|
|
|
"name"
|
|
|
|
|
]
|
2022-09-13 21:01:29 +00:00
|
|
|
|
except Exception:
|
|
|
|
|
self.win.toast_overlay.add_toast(
|
|
|
|
|
Adw.Toast(title=_("Failed to load preset"))
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
self.custom_presets[repo.name] = presets_list
|
|
|
|
|
elif repo.is_file():
|
|
|
|
|
buglog("file")
|
|
|
|
|
# keep compatiblity with old presets
|
|
|
|
|
if repo.name.endswith(".json"):
|
2022-10-02 01:57:29 +00:00
|
|
|
|
if not os.path.isdir(os.path.join(presets_dir, "user")):
|
|
|
|
|
os.mkdir(os.path.join(presets_dir, "user"))
|
2022-09-23 19:18:34 +00:00
|
|
|
|
|
2022-09-13 21:01:29 +00:00
|
|
|
|
os.rename(repo, os.path.join(
|
2022-10-02 01:57:29 +00:00
|
|
|
|
presets_dir, "user", repo.name))
|
2022-09-13 21:01:29 +00:00
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
with open(
|
2022-10-02 01:57:29 +00:00
|
|
|
|
os.path.join(presets_dir, "user", repo),
|
2022-09-13 21:01:29 +00:00
|
|
|
|
"r",
|
|
|
|
|
encoding="utf-8",
|
|
|
|
|
) as file:
|
|
|
|
|
preset_text = file.read()
|
|
|
|
|
preset = json.loads(preset_text)
|
|
|
|
|
if preset.get("variables") is None:
|
|
|
|
|
raise KeyError("variables")
|
|
|
|
|
if preset.get("palette") is None:
|
|
|
|
|
raise KeyError("palette")
|
2022-09-23 11:14:21 +00:00
|
|
|
|
presets_list["user"][file_name.replace(".json", "")] = preset[
|
|
|
|
|
"name"
|
|
|
|
|
]
|
2022-09-13 21:01:29 +00:00
|
|
|
|
except Exception:
|
|
|
|
|
self.win.toast_overlay.add_toast(
|
|
|
|
|
Adw.Toast(title=_("Failed to load preset"))
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
buglog(self.custom_presets)
|
|
|
|
|
custom_menu_section = Gio.Menu()
|
2022-09-16 15:40:59 +00:00
|
|
|
|
try:
|
|
|
|
|
if (
|
|
|
|
|
self.custom_presets["user"]
|
|
|
|
|
or self.custom_presets["curated"]
|
|
|
|
|
or self.custom_presets["official"]
|
|
|
|
|
):
|
|
|
|
|
for repo, content in self.custom_presets.items():
|
|
|
|
|
|
|
|
|
|
for preset, preset_name in content.items():
|
2022-09-28 12:05:32 +00:00
|
|
|
|
buglog(preset_name)
|
|
|
|
|
if preset_name in self.favourite:
|
|
|
|
|
menu_item = Gio.MenuItem()
|
|
|
|
|
menu_item.set_label(preset_name)
|
|
|
|
|
if not preset.startswith("error"):
|
|
|
|
|
menu_item.set_action_and_target_value(
|
2022-09-28 12:46:35 +00:00
|
|
|
|
"app.load_preset",
|
|
|
|
|
GLib.Variant("s", "custom-" + preset),
|
2022-09-28 12:05:32 +00:00
|
|
|
|
)
|
|
|
|
|
else:
|
|
|
|
|
menu_item.set_action_and_target_value("")
|
|
|
|
|
custom_menu_section.append_item(menu_item)
|
2022-09-16 15:40:59 +00:00
|
|
|
|
else:
|
|
|
|
|
menu_item = Gio.MenuItem()
|
2022-10-01 16:01:15 +00:00
|
|
|
|
menu_item.set_label(_("No presets found"))
|
2022-09-16 15:40:59 +00:00
|
|
|
|
custom_menu_section.append_item(menu_item)
|
|
|
|
|
|
|
|
|
|
except KeyError:
|
2022-10-02 01:57:29 +00:00
|
|
|
|
if not os.path.exists(os.path.join(presets_dir, "user")):
|
|
|
|
|
os.makedirs(os.path.join(presets_dir, "user"))
|
|
|
|
|
if not os.path.exists(os.path.join(presets_dir, "curated")):
|
|
|
|
|
os.makedirs(os.path.join(presets_dir, "curated"))
|
|
|
|
|
if not os.path.exists(os.path.join(presets_dir, "official")):
|
|
|
|
|
os.makedirs(os.path.join(presets_dir, "official"))
|
2022-09-13 21:01:29 +00:00
|
|
|
|
open_in_file_manager_item = Gio.MenuItem()
|
|
|
|
|
open_in_file_manager_item.set_label(_("Open in File Manager"))
|
|
|
|
|
open_in_file_manager_item.set_action_and_target_value(
|
|
|
|
|
"app.open_preset_directory"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# custom_menu_section.append_item(open_in_file_manager_item)
|
|
|
|
|
self.props.active_window.presets_menu.append_section(
|
2022-09-28 21:10:07 +00:00
|
|
|
|
_("Favourite Presets"), custom_menu_section
|
2022-09-13 21:01:29 +00:00
|
|
|
|
)
|
|
|
|
|
|
2022-09-24 18:20:17 +00:00
|
|
|
|
def show_presets_manager(self, *args):
|
2022-09-13 21:01:29 +00:00
|
|
|
|
presets = GradiencePresetWindow(self)
|
|
|
|
|
presets.set_transient_for(self.win)
|
|
|
|
|
presets.set_modal(True)
|
|
|
|
|
presets.present()
|
|
|
|
|
|
2022-09-24 18:20:17 +00:00
|
|
|
|
add_rows_thread = threading.Thread(target=presets.add_explore_rows)
|
|
|
|
|
add_rows_thread.start()
|
|
|
|
|
|
2022-09-13 19:14:09 +00:00
|
|
|
|
def load_preset_from_css(self):
|
2022-09-13 19:25:53 +00:00
|
|
|
|
try:
|
|
|
|
|
variables, palette, custom_css = load_preset_from_css(
|
|
|
|
|
os.path.join(
|
2022-09-13 19:26:19 +00:00
|
|
|
|
os.environ.get("XDG_CONFIG_HOME",
|
|
|
|
|
os.environ["HOME"] + "/.config"),
|
|
|
|
|
"gtk-4.0",
|
|
|
|
|
"gtk.css",
|
|
|
|
|
)
|
2022-09-13 19:25:53 +00:00
|
|
|
|
)
|
|
|
|
|
preset = {
|
|
|
|
|
"name": "User",
|
|
|
|
|
"variables": variables,
|
|
|
|
|
"palette": palette,
|
2022-09-13 19:26:19 +00:00
|
|
|
|
"custom_css": {"gtk4": custom_css},
|
2022-09-13 19:25:53 +00:00
|
|
|
|
}
|
2022-09-14 12:49:39 +00:00
|
|
|
|
self.preset = Preset(preset=preset)
|
|
|
|
|
self.load_preset_variables_from_preset()
|
2022-09-13 19:26:19 +00:00
|
|
|
|
except OSError: # fallback to adwaita
|
2022-09-13 19:25:53 +00:00
|
|
|
|
if self.style_manager.get_dark():
|
|
|
|
|
self.load_preset_from_resource(
|
|
|
|
|
f"{rootdir}/presets/adwaita-dark.json")
|
|
|
|
|
else:
|
2022-09-13 19:26:19 +00:00
|
|
|
|
self.load_preset_from_resource(
|
|
|
|
|
f"{rootdir}/presets/adwaita.json")
|
2022-09-13 19:14:09 +00:00
|
|
|
|
|
2022-07-25 14:35:40 +00:00
|
|
|
|
def open_preset_directory(self, *_args):
|
2022-07-24 11:00:05 +00:00
|
|
|
|
parent = XdpGtk4.parent_new_gtk(self.props.active_window)
|
2022-08-10 08:46:52 +00:00
|
|
|
|
|
2022-07-24 18:43:32 +00:00
|
|
|
|
def open_dir_callback(_, result):
|
|
|
|
|
self.portal.open_uri_finish(result)
|
2022-08-10 08:46:52 +00:00
|
|
|
|
|
2022-07-24 11:00:05 +00:00
|
|
|
|
self.portal.open_uri(
|
|
|
|
|
parent,
|
2022-09-07 15:52:50 +00:00
|
|
|
|
"file://"
|
|
|
|
|
+ os.path.join(
|
|
|
|
|
os.environ.get("XDG_CONFIG_HOME",
|
|
|
|
|
os.environ["HOME"] + "/.config"),
|
2022-08-11 16:39:52 +00:00
|
|
|
|
"presets",
|
|
|
|
|
),
|
2022-07-24 11:00:05 +00:00
|
|
|
|
Xdp.OpenUriFlags.NONE,
|
|
|
|
|
None,
|
2022-08-10 08:46:52 +00:00
|
|
|
|
open_dir_callback,
|
2022-07-24 11:00:05 +00:00
|
|
|
|
)
|
|
|
|
|
|
2022-07-17 19:27:57 +00:00
|
|
|
|
def load_preset_from_file(self, preset_path):
|
2022-08-25 10:33:09 +00:00
|
|
|
|
buglog(f"load preset from file {preset_path}")
|
2022-09-14 12:49:39 +00:00
|
|
|
|
self.preset = Preset(preset_path=preset_path)
|
|
|
|
|
self.load_preset_variables_from_preset()
|
2022-07-17 19:27:57 +00:00
|
|
|
|
|
|
|
|
|
def load_preset_from_resource(self, preset_path):
|
2022-08-17 21:35:59 +00:00
|
|
|
|
preset_text = Gio.resources_lookup_data(
|
|
|
|
|
preset_path, 0).get_data().decode()
|
2022-09-14 12:49:39 +00:00
|
|
|
|
self.preset = Preset(text=preset_text)
|
|
|
|
|
self.load_preset_variables_from_preset()
|
2022-09-14 12:50:12 +00:00
|
|
|
|
|
2022-09-14 12:49:39 +00:00
|
|
|
|
def load_preset_variables_from_preset(self, preset=None):
|
|
|
|
|
if preset is not None:
|
|
|
|
|
self.preset = preset
|
|
|
|
|
self.is_ready = False
|
|
|
|
|
buglog(self.preset)
|
|
|
|
|
self.preset_name = self.preset.preset_name
|
|
|
|
|
self.variables = self.preset.variables
|
|
|
|
|
self.palette = self.preset.palette
|
|
|
|
|
self.custom_css = self.preset.custom_css
|
|
|
|
|
|
|
|
|
|
for key in self.variables.keys():
|
|
|
|
|
if key in self.pref_variables:
|
|
|
|
|
self.pref_variables[key].update_value(self.variables[key])
|
|
|
|
|
for key in self.palette.keys():
|
|
|
|
|
if key in self.pref_palette_shades:
|
|
|
|
|
self.pref_palette_shades[key].update_shades(self.palette[key])
|
|
|
|
|
self.custom_css_group.load_custom_css(self.custom_css)
|
|
|
|
|
|
|
|
|
|
self.clear_dirty()
|
|
|
|
|
|
|
|
|
|
self.reload_variables()
|
2022-07-17 19:27:57 +00:00
|
|
|
|
|
2022-07-21 19:03:18 +00:00
|
|
|
|
def load_preset_variables(self, preset):
|
2022-08-01 19:42:42 +00:00
|
|
|
|
self.is_ready = False
|
|
|
|
|
|
2022-08-01 17:09:45 +00:00
|
|
|
|
self.preset_name = preset["name"]
|
2022-07-17 15:02:29 +00:00
|
|
|
|
self.variables = preset["variables"]
|
2022-07-21 19:03:18 +00:00
|
|
|
|
self.palette = preset["palette"]
|
2022-07-24 17:46:37 +00:00
|
|
|
|
if "custom_css" in preset:
|
|
|
|
|
self.custom_css = preset["custom_css"]
|
2022-07-25 08:18:32 +00:00
|
|
|
|
else:
|
2022-07-26 13:31:16 +00:00
|
|
|
|
for app_type in settings_schema["custom_css_app_types"]:
|
2022-07-25 08:18:32 +00:00
|
|
|
|
self.custom_css[app_type] = ""
|
2022-07-17 15:02:29 +00:00
|
|
|
|
for key in self.variables.keys():
|
2022-07-17 11:46:05 +00:00
|
|
|
|
if key in self.pref_variables:
|
2022-07-17 15:02:29 +00:00
|
|
|
|
self.pref_variables[key].update_value(self.variables[key])
|
2022-07-21 19:03:18 +00:00
|
|
|
|
for key in self.palette.keys():
|
|
|
|
|
if key in self.pref_palette_shades:
|
|
|
|
|
self.pref_palette_shades[key].update_shades(self.palette[key])
|
2022-07-24 17:46:37 +00:00
|
|
|
|
self.custom_css_group.load_custom_css(self.custom_css)
|
2022-07-17 11:46:05 +00:00
|
|
|
|
|
2022-08-01 19:42:42 +00:00
|
|
|
|
self.clear_dirty()
|
|
|
|
|
|
2022-07-17 15:02:29 +00:00
|
|
|
|
self.reload_variables()
|
2022-07-17 11:46:05 +00:00
|
|
|
|
|
2022-09-07 15:57:00 +00:00
|
|
|
|
@staticmethod
|
|
|
|
|
def rgba_from_argb(argb, alpha=None) -> str:
|
2022-08-11 13:39:31 +00:00
|
|
|
|
base = "rgba({}, {}, {}, {})"
|
|
|
|
|
|
|
|
|
|
red = redFromArgb(argb)
|
|
|
|
|
green = greenFromArgb(argb)
|
|
|
|
|
blue = blueFromArgb(argb)
|
|
|
|
|
if not alpha:
|
|
|
|
|
alpha = alphaFromArgb(argb)
|
|
|
|
|
|
|
|
|
|
return base.format(red, green, blue, alpha)
|
|
|
|
|
|
2022-08-11 13:00:07 +00:00
|
|
|
|
def update_theme_from_monet(self, theme, tone, monet_theme):
|
2022-08-11 12:22:08 +00:00
|
|
|
|
palettes = theme["palettes"]
|
|
|
|
|
|
2022-08-11 16:39:24 +00:00
|
|
|
|
monet_theme = monet_theme.get_string().lower() # dark / light
|
2022-08-11 13:00:07 +00:00
|
|
|
|
|
2022-08-11 12:22:08 +00:00
|
|
|
|
palette = {}
|
|
|
|
|
i = 0
|
|
|
|
|
for color in palettes.values():
|
|
|
|
|
i += 1
|
2022-08-11 12:23:31 +00:00
|
|
|
|
palette[str(i)] = hexFromArgb(color.tone(int(tone.get_string())))
|
2022-08-11 12:24:16 +00:00
|
|
|
|
self.pref_palette_shades["monet"].update_shades(palette)
|
2022-08-15 18:06:44 +00:00
|
|
|
|
if monet_theme == "auto":
|
2022-08-11 14:37:03 +00:00
|
|
|
|
if self.style_manager.get_dark():
|
|
|
|
|
monet_theme = "dark"
|
|
|
|
|
else:
|
|
|
|
|
monet_theme = "light"
|
2022-08-11 16:39:24 +00:00
|
|
|
|
|
2022-08-11 13:39:31 +00:00
|
|
|
|
if monet_theme == "dark":
|
2022-08-11 16:39:24 +00:00
|
|
|
|
dark_theme = theme["schemes"]["dark"]
|
2022-08-11 13:41:46 +00:00
|
|
|
|
variable = {
|
2022-08-11 14:06:55 +00:00
|
|
|
|
"accent_color": self.rgba_from_argb(dark_theme.primary),
|
2022-09-23 11:14:21 +00:00
|
|
|
|
"accent_bg_color": self.rgba_from_argb(dark_theme.primaryContainer),
|
|
|
|
|
"accent_fg_color": self.rgba_from_argb(dark_theme.onPrimaryContainer),
|
2022-08-11 14:06:55 +00:00
|
|
|
|
"destructive_color": self.rgba_from_argb(dark_theme.error),
|
2022-09-23 11:14:21 +00:00
|
|
|
|
"destructive_bg_color": self.rgba_from_argb(dark_theme.errorContainer),
|
2022-09-15 20:05:38 +00:00
|
|
|
|
"destructive_fg_color": self.rgba_from_argb(
|
|
|
|
|
dark_theme.onErrorContainer
|
|
|
|
|
),
|
2022-08-11 14:06:55 +00:00
|
|
|
|
"success_color": self.rgba_from_argb(dark_theme.tertiary),
|
|
|
|
|
"success_bg_color": self.rgba_from_argb(dark_theme.onTertiary),
|
2022-09-23 11:14:21 +00:00
|
|
|
|
"success_fg_color": self.rgba_from_argb(dark_theme.onTertiaryContainer),
|
2022-09-15 18:48:01 +00:00
|
|
|
|
"warning_color": self.rgba_from_argb(dark_theme.secondary),
|
2022-09-23 11:14:21 +00:00
|
|
|
|
"warning_bg_color": self.rgba_from_argb(dark_theme.onSecondary),
|
|
|
|
|
"warning_fg_color": self.rgba_from_argb(dark_theme.primary, "0.8"),
|
2022-08-11 14:06:55 +00:00
|
|
|
|
"error_color": self.rgba_from_argb(dark_theme.error),
|
2022-09-23 11:14:21 +00:00
|
|
|
|
"error_bg_color": self.rgba_from_argb(dark_theme.errorContainer),
|
2022-08-11 14:06:55 +00:00
|
|
|
|
"error_fg_color": self.rgba_from_argb(dark_theme.onError),
|
|
|
|
|
"window_bg_color": self.rgba_from_argb(dark_theme.surface),
|
|
|
|
|
"window_fg_color": self.rgba_from_argb(dark_theme.onSurface),
|
|
|
|
|
"view_bg_color": self.rgba_from_argb(dark_theme.surface),
|
|
|
|
|
"view_fg_color": self.rgba_from_argb(dark_theme.onSurface),
|
|
|
|
|
"headerbar_bg_color": self.rgba_from_argb(dark_theme.surface),
|
2022-09-23 11:14:21 +00:00
|
|
|
|
"headerbar_fg_color": self.rgba_from_argb(dark_theme.onSurface),
|
2022-08-11 16:39:52 +00:00
|
|
|
|
"headerbar_border_color": self.rgba_from_argb(
|
|
|
|
|
dark_theme.primary, "0.8"
|
|
|
|
|
),
|
2022-09-30 19:12:32 +00:00
|
|
|
|
"headerbar_backdrop_color": "@headerbar_bg_color",
|
2022-09-23 11:14:21 +00:00
|
|
|
|
"headerbar_shade_color": self.rgba_from_argb(dark_theme.shadow),
|
|
|
|
|
"card_bg_color": self.rgba_from_argb(dark_theme.primary, "0.05"),
|
|
|
|
|
"card_fg_color": self.rgba_from_argb(dark_theme.onSecondaryContainer),
|
2022-08-11 14:06:55 +00:00
|
|
|
|
"card_shade_color": self.rgba_from_argb(dark_theme.shadow),
|
2022-09-23 11:14:21 +00:00
|
|
|
|
"dialog_bg_color": self.rgba_from_argb(dark_theme.secondaryContainer),
|
|
|
|
|
"dialog_fg_color": self.rgba_from_argb(dark_theme.onSecondaryContainer),
|
|
|
|
|
"popover_bg_color": self.rgba_from_argb(dark_theme.secondaryContainer),
|
2022-08-11 16:39:52 +00:00
|
|
|
|
"popover_fg_color": self.rgba_from_argb(
|
|
|
|
|
dark_theme.onSecondaryContainer
|
|
|
|
|
),
|
2022-08-11 14:06:55 +00:00
|
|
|
|
"shade_color": self.rgba_from_argb(dark_theme.shadow),
|
2022-09-23 11:14:21 +00:00
|
|
|
|
"scrollbar_outline_color": self.rgba_from_argb(dark_theme.outline),
|
2022-08-11 13:39:31 +00:00
|
|
|
|
}
|
2022-08-11 16:39:24 +00:00
|
|
|
|
else: # light
|
|
|
|
|
light_theme = theme["schemes"]["light"]
|
2022-08-11 13:41:46 +00:00
|
|
|
|
variable = {
|
2022-08-11 14:39:34 +00:00
|
|
|
|
"accent_color": self.rgba_from_argb(light_theme.primary),
|
2022-08-24 09:23:11 +00:00
|
|
|
|
"accent_bg_color": self.rgba_from_argb(light_theme.primary),
|
2022-09-15 20:05:03 +00:00
|
|
|
|
"accent_fg_color": self.rgba_from_argb(light_theme.onPrimary),
|
2022-08-11 14:39:34 +00:00
|
|
|
|
"destructive_color": self.rgba_from_argb(light_theme.error),
|
2022-09-23 11:14:21 +00:00
|
|
|
|
"destructive_bg_color": self.rgba_from_argb(light_theme.errorContainer),
|
2022-09-15 20:05:38 +00:00
|
|
|
|
"destructive_fg_color": self.rgba_from_argb(
|
|
|
|
|
light_theme.onErrorContainer
|
|
|
|
|
),
|
2022-08-11 14:39:34 +00:00
|
|
|
|
"success_color": self.rgba_from_argb(light_theme.tertiary),
|
2022-09-23 11:14:21 +00:00
|
|
|
|
"success_bg_color": self.rgba_from_argb(light_theme.tertiaryContainer),
|
2022-09-15 20:05:38 +00:00
|
|
|
|
"success_fg_color": self.rgba_from_argb(
|
|
|
|
|
light_theme.onTertiaryContainer
|
|
|
|
|
),
|
2022-09-15 18:48:01 +00:00
|
|
|
|
"warning_color": self.rgba_from_argb(light_theme.secondary),
|
2022-09-23 11:14:21 +00:00
|
|
|
|
"warning_bg_color": self.rgba_from_argb(light_theme.secondaryContainer),
|
2022-09-15 20:05:38 +00:00
|
|
|
|
"warning_fg_color": self.rgba_from_argb(
|
|
|
|
|
light_theme.onSecondaryContainer
|
|
|
|
|
),
|
2022-08-11 14:39:34 +00:00
|
|
|
|
"error_color": self.rgba_from_argb(light_theme.error),
|
2022-09-23 11:14:21 +00:00
|
|
|
|
"error_bg_color": self.rgba_from_argb(light_theme.errorContainer),
|
2022-08-11 14:39:34 +00:00
|
|
|
|
"error_fg_color": self.rgba_from_argb(light_theme.onError),
|
2022-09-23 11:14:21 +00:00
|
|
|
|
"window_bg_color": self.rgba_from_argb(light_theme.secondaryContainer),
|
2022-08-11 14:39:34 +00:00
|
|
|
|
"window_fg_color": self.rgba_from_argb(light_theme.onSurface),
|
2022-09-23 11:14:21 +00:00
|
|
|
|
"view_bg_color": self.rgba_from_argb(light_theme.secondaryContainer),
|
2022-08-11 14:39:34 +00:00
|
|
|
|
"view_fg_color": self.rgba_from_argb(light_theme.onSurface),
|
2022-09-07 15:52:50 +00:00
|
|
|
|
"headerbar_bg_color": self.rgba_from_argb(
|
|
|
|
|
light_theme.secondaryContainer
|
|
|
|
|
),
|
2022-09-23 11:14:21 +00:00
|
|
|
|
"headerbar_fg_color": self.rgba_from_argb(light_theme.onSurface),
|
2022-08-11 16:39:52 +00:00
|
|
|
|
"headerbar_border_color": self.rgba_from_argb(
|
|
|
|
|
light_theme.primary, "0.8"
|
|
|
|
|
),
|
2022-09-30 19:12:32 +00:00
|
|
|
|
"headerbar_backdrop_color": "@headerbar_bg_color",
|
2022-09-07 15:52:50 +00:00
|
|
|
|
"headerbar_shade_color": self.rgba_from_argb(
|
|
|
|
|
light_theme.secondaryContainer
|
|
|
|
|
),
|
2022-09-23 11:14:21 +00:00
|
|
|
|
"card_bg_color": self.rgba_from_argb(light_theme.primary, "0.05"),
|
|
|
|
|
"card_fg_color": self.rgba_from_argb(light_theme.onSecondaryContainer),
|
2022-08-11 14:39:34 +00:00
|
|
|
|
"card_shade_color": self.rgba_from_argb(light_theme.shadow),
|
2022-09-23 11:14:21 +00:00
|
|
|
|
"dialog_bg_color": self.rgba_from_argb(light_theme.secondaryContainer),
|
2022-08-11 16:39:52 +00:00
|
|
|
|
"dialog_fg_color": self.rgba_from_argb(
|
|
|
|
|
light_theme.onSecondaryContainer
|
|
|
|
|
),
|
2022-09-23 11:14:21 +00:00
|
|
|
|
"popover_bg_color": self.rgba_from_argb(light_theme.secondaryContainer),
|
2022-08-11 16:39:52 +00:00
|
|
|
|
"popover_fg_color": self.rgba_from_argb(
|
|
|
|
|
light_theme.onSecondaryContainer
|
|
|
|
|
),
|
2022-08-11 14:39:34 +00:00
|
|
|
|
"shade_color": self.rgba_from_argb(light_theme.shadow),
|
2022-09-23 11:14:21 +00:00
|
|
|
|
"scrollbar_outline_color": self.rgba_from_argb(light_theme.outline),
|
2022-08-11 13:39:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-09-07 15:59:10 +00:00
|
|
|
|
for key in variable:
|
2022-08-11 13:39:31 +00:00
|
|
|
|
if key in self.pref_variables:
|
2022-08-11 13:57:41 +00:00
|
|
|
|
self.pref_variables[key].update_value(variable[key])
|
2022-08-11 16:39:24 +00:00
|
|
|
|
|
2022-08-11 13:44:12 +00:00
|
|
|
|
self.reload_variables()
|
2022-08-11 13:00:07 +00:00
|
|
|
|
|
2022-07-24 17:46:37 +00:00
|
|
|
|
def generate_gtk_css(self, app_type):
|
2022-07-17 11:46:05 +00:00
|
|
|
|
final_css = ""
|
2022-07-24 17:46:37 +00:00
|
|
|
|
for key in self.variables.keys():
|
2022-07-29 12:04:18 +00:00
|
|
|
|
final_css += f"@define-color {key} {self.variables[key]};\n"
|
2022-07-24 17:46:37 +00:00
|
|
|
|
for prefix_key in self.palette.keys():
|
|
|
|
|
for key in self.palette[prefix_key].keys():
|
2022-07-29 12:04:18 +00:00
|
|
|
|
final_css += f"@define-color {prefix_key + key} {self.palette[prefix_key][key]};\n"
|
2022-07-24 17:46:37 +00:00
|
|
|
|
final_css += self.custom_css.get(app_type, "")
|
2022-07-17 11:46:05 +00:00
|
|
|
|
return final_css
|
|
|
|
|
|
2022-08-01 19:42:42 +00:00
|
|
|
|
def mark_as_dirty(self):
|
|
|
|
|
self.is_dirty = True
|
2022-08-10 13:05:54 +00:00
|
|
|
|
self.props.active_window.save_preset_button.get_child().set_icon_name(
|
2022-08-15 03:42:23 +00:00
|
|
|
|
"drive-unsaved-symbolic"
|
2022-08-10 13:05:54 +00:00
|
|
|
|
)
|
2022-08-15 12:52:06 +00:00
|
|
|
|
self.props.active_window.save_preset_button.add_css_class("warning")
|
|
|
|
|
|
2022-09-07 15:52:50 +00:00
|
|
|
|
self.props.active_window.save_preset_button.get_child().set_tooltip_text(
|
2022-09-29 18:06:42 +00:00
|
|
|
|
_("Unsaved Changes")
|
2022-09-07 15:52:50 +00:00
|
|
|
|
)
|
2022-08-01 19:42:42 +00:00
|
|
|
|
|
|
|
|
|
def clear_dirty(self):
|
|
|
|
|
self.is_dirty = False
|
2022-08-10 15:15:46 +00:00
|
|
|
|
self.props.active_window.save_preset_button.get_child().set_icon_name(
|
2022-08-15 03:42:23 +00:00
|
|
|
|
"drive-symbolic"
|
2022-08-10 15:15:46 +00:00
|
|
|
|
)
|
2022-08-15 12:52:06 +00:00
|
|
|
|
self.props.active_window.save_preset_button.remove_css_class("warning")
|
2022-08-01 19:42:42 +00:00
|
|
|
|
self.props.active_window.save_preset_button.get_child().set_label("")
|
2022-09-07 15:52:50 +00:00
|
|
|
|
self.props.active_window.save_preset_button.get_child().set_tooltip_text(
|
2022-09-29 18:06:42 +00:00
|
|
|
|
_("Save Changes")
|
2022-09-07 15:52:50 +00:00
|
|
|
|
)
|
2022-08-01 19:42:42 +00:00
|
|
|
|
|
2022-07-17 15:02:29 +00:00
|
|
|
|
def reload_variables(self):
|
2022-07-18 19:20:02 +00:00
|
|
|
|
parsing_errors = []
|
2022-07-24 17:46:37 +00:00
|
|
|
|
gtk_css = self.generate_gtk_css("gtk4")
|
2022-07-17 11:46:05 +00:00
|
|
|
|
css_provider = Gtk.CssProvider()
|
2022-08-10 08:46:52 +00:00
|
|
|
|
|
2022-07-24 18:43:32 +00:00
|
|
|
|
def on_error(_, section, error):
|
2022-07-18 19:20:02 +00:00
|
|
|
|
start_location = section.get_start_location().chars
|
|
|
|
|
end_location = section.get_end_location().chars
|
|
|
|
|
line_number = section.get_end_location().lines
|
2022-08-10 08:46:52 +00:00
|
|
|
|
parsing_errors.append(
|
|
|
|
|
{
|
|
|
|
|
"error": error.message,
|
|
|
|
|
"element": gtk_css[start_location:end_location].strip(),
|
|
|
|
|
"line": gtk_css.splitlines()[line_number]
|
|
|
|
|
if line_number < len(gtk_css.splitlines())
|
|
|
|
|
else "<last line>",
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
2022-07-21 19:03:18 +00:00
|
|
|
|
css_provider.connect("parsing-error", on_error)
|
2022-07-22 15:10:52 +00:00
|
|
|
|
css_provider.load_from_data(gtk_css.encode())
|
2022-08-17 21:35:59 +00:00
|
|
|
|
self.props.active_window.update_errors(
|
|
|
|
|
self.global_errors + parsing_errors)
|
2022-07-17 11:46:05 +00:00
|
|
|
|
# loading with the priority above user to override the applied config
|
2022-07-24 17:46:37 +00:00
|
|
|
|
if self.current_css_provider is not None:
|
2022-08-10 08:46:52 +00:00
|
|
|
|
Gtk.StyleContext.remove_provider_for_display(
|
|
|
|
|
Gdk.Display.get_default(), self.current_css_provider
|
|
|
|
|
)
|
|
|
|
|
Gtk.StyleContext.add_provider_for_display(
|
|
|
|
|
Gdk.Display.get_default(),
|
|
|
|
|
css_provider,
|
|
|
|
|
Gtk.STYLE_PROVIDER_PRIORITY_USER + 1,
|
|
|
|
|
)
|
2022-07-24 17:46:37 +00:00
|
|
|
|
self.current_css_provider = css_provider
|
2022-07-17 11:46:05 +00:00
|
|
|
|
|
2022-08-01 19:42:42 +00:00
|
|
|
|
self.is_ready = True
|
|
|
|
|
|
2022-07-25 14:35:40 +00:00
|
|
|
|
def load_preset_action(self, _unused, *args):
|
2022-07-18 08:10:00 +00:00
|
|
|
|
if args[0].get_string().startswith("custom-"):
|
2022-08-10 08:46:52 +00:00
|
|
|
|
self.load_preset_from_file(
|
|
|
|
|
os.path.join(
|
2022-09-07 15:52:50 +00:00
|
|
|
|
os.environ.get("XDG_CONFIG_HOME",
|
|
|
|
|
os.environ["HOME"] + "/.config"),
|
2022-08-10 08:46:52 +00:00
|
|
|
|
"presets",
|
2022-09-07 15:52:50 +00:00
|
|
|
|
args[0].get_string().replace("custom-", "", 1) + ".json",
|
|
|
|
|
)
|
|
|
|
|
)
|
2022-07-17 19:27:57 +00:00
|
|
|
|
else:
|
2022-08-10 08:46:52 +00:00
|
|
|
|
self.load_preset_from_resource(
|
2022-09-07 15:52:50 +00:00
|
|
|
|
f"{rootdir}/presets/" + args[0].get_string() + ".json"
|
2022-08-10 08:46:52 +00:00
|
|
|
|
)
|
2022-07-17 19:27:57 +00:00
|
|
|
|
Gio.SimpleAction.set_state(self.lookup_action("load_preset"), args[0])
|
2022-07-17 11:46:05 +00:00
|
|
|
|
|
2022-07-25 14:35:40 +00:00
|
|
|
|
def show_apply_color_scheme_dialog(self, *_args):
|
2022-08-19 19:14:05 +00:00
|
|
|
|
dialog = GradienceAppTypeDialog(
|
2022-09-29 18:06:42 +00:00
|
|
|
|
_("Apply This Color Scheme?"),
|
2022-09-07 15:52:50 +00:00
|
|
|
|
_(
|
2022-09-23 17:33:52 +00:00
|
|
|
|
"Warning: any custom CSS files for those app types will be "
|
2022-09-23 17:31:06 +00:00
|
|
|
|
"irreversibly overwritten!"
|
2022-09-07 15:52:50 +00:00
|
|
|
|
),
|
2022-08-10 08:46:52 +00:00
|
|
|
|
"apply",
|
|
|
|
|
_("Apply"),
|
|
|
|
|
Adw.ResponseAppearance.SUGGESTED,
|
|
|
|
|
transient_for=self.props.active_window,
|
|
|
|
|
)
|
2022-08-11 14:53:41 +00:00
|
|
|
|
|
2022-08-14 14:14:33 +00:00
|
|
|
|
dialog.connect("response", self.apply_color_scheme)
|
2022-07-17 16:24:07 +00:00
|
|
|
|
dialog.present()
|
|
|
|
|
|
2022-09-01 12:11:38 +00:00
|
|
|
|
def show_restore_color_scheme_dialog(self, *_args):
|
|
|
|
|
dialog = GradienceAppTypeDialog(
|
|
|
|
|
_("Restore applied color scheme?"),
|
|
|
|
|
_("Make sure you have the current settings saved as a preset."),
|
|
|
|
|
"restore",
|
|
|
|
|
_("Restore"),
|
|
|
|
|
Adw.ResponseAppearance.DESTRUCTIVE,
|
|
|
|
|
transient_for=self.props.active_window,
|
|
|
|
|
)
|
|
|
|
|
dialog.connect("response", self.restore_color_scheme)
|
|
|
|
|
dialog.present()
|
|
|
|
|
|
2022-07-25 14:35:40 +00:00
|
|
|
|
def show_reset_color_scheme_dialog(self, *_args):
|
2022-08-19 19:14:05 +00:00
|
|
|
|
dialog = GradienceAppTypeDialog(
|
2022-08-10 08:46:52 +00:00
|
|
|
|
_("Reset applied color scheme?"),
|
|
|
|
|
_("Make sure you have the current settings saved as a preset."),
|
|
|
|
|
"reset",
|
|
|
|
|
_("Reset"),
|
|
|
|
|
Adw.ResponseAppearance.DESTRUCTIVE,
|
|
|
|
|
transient_for=self.props.active_window,
|
|
|
|
|
)
|
2022-07-22 15:10:52 +00:00
|
|
|
|
dialog.connect("response", self.reset_color_scheme)
|
2022-07-17 16:24:07 +00:00
|
|
|
|
dialog.present()
|
|
|
|
|
|
2022-07-25 14:35:40 +00:00
|
|
|
|
def show_save_preset_dialog(self, *_args):
|
2022-08-10 08:46:52 +00:00
|
|
|
|
dialog = Adw.MessageDialog(
|
|
|
|
|
transient_for=self.props.active_window,
|
2022-09-29 18:46:14 +00:00
|
|
|
|
heading=_("Save preset as…"),
|
2022-08-10 08:46:52 +00:00
|
|
|
|
body=_(
|
2022-09-23 17:33:52 +00:00
|
|
|
|
"Saving preset to <tt>{0}</tt>. If that preset already "
|
2022-09-23 17:31:06 +00:00
|
|
|
|
"exists, it will be overwritten!"
|
2022-08-10 08:46:52 +00:00
|
|
|
|
).format(
|
|
|
|
|
os.path.join(
|
2022-08-20 01:46:35 +00:00
|
|
|
|
os.environ.get("XDG_CONFIG_HOME",
|
|
|
|
|
os.environ["HOME"] + "/.config"),
|
2022-08-10 08:46:52 +00:00
|
|
|
|
"presets",
|
2022-09-04 09:25:39 +00:00
|
|
|
|
"user",
|
2022-08-10 08:46:52 +00:00
|
|
|
|
to_slug_case(self.preset_name) + ".json",
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
body_use_markup=True,
|
|
|
|
|
)
|
2022-07-18 10:51:25 +00:00
|
|
|
|
|
2022-07-25 14:35:40 +00:00
|
|
|
|
dialog.add_response("cancel", _("Cancel"))
|
|
|
|
|
dialog.add_response("save", _("Save"))
|
2022-08-17 21:35:59 +00:00
|
|
|
|
dialog.set_response_appearance(
|
|
|
|
|
"save", Adw.ResponseAppearance.SUGGESTED)
|
2022-07-18 10:51:25 +00:00
|
|
|
|
dialog.set_default_response("cancel")
|
|
|
|
|
dialog.set_close_response("cancel")
|
|
|
|
|
|
|
|
|
|
preset_entry = Gtk.Entry(placeholder_text="Preset Name")
|
2022-08-01 17:09:45 +00:00
|
|
|
|
preset_entry.set_text(self.preset_name)
|
2022-08-10 08:46:52 +00:00
|
|
|
|
|
2022-07-25 14:35:40 +00:00
|
|
|
|
def on_preset_entry_change(*_args):
|
2022-07-18 10:51:25 +00:00
|
|
|
|
if len(preset_entry.get_text()) == 0:
|
2022-08-10 08:46:52 +00:00
|
|
|
|
dialog.set_body(
|
|
|
|
|
_(
|
2022-09-23 17:33:52 +00:00
|
|
|
|
"Saving preset to <tt>{0}</tt>. If that preset "
|
2022-09-23 17:31:06 +00:00
|
|
|
|
"already exists, it will be overwritten!"
|
2022-08-11 16:39:52 +00:00
|
|
|
|
).format(
|
|
|
|
|
os.path.join(
|
|
|
|
|
os.environ.get(
|
2022-08-20 01:46:35 +00:00
|
|
|
|
"XDG_CONFIG_HOME", os.environ["HOME"] +
|
|
|
|
|
"/.config"
|
2022-08-11 16:39:52 +00:00
|
|
|
|
),
|
|
|
|
|
"presets",
|
2022-09-04 09:25:39 +00:00
|
|
|
|
"user",
|
2022-08-11 16:39:52 +00:00
|
|
|
|
)
|
|
|
|
|
)
|
2022-08-10 08:46:52 +00:00
|
|
|
|
)
|
2022-07-18 10:51:25 +00:00
|
|
|
|
dialog.set_response_enabled("save", False)
|
|
|
|
|
else:
|
2022-08-10 08:46:52 +00:00
|
|
|
|
dialog.set_body(
|
|
|
|
|
_(
|
2022-09-23 17:33:52 +00:00
|
|
|
|
"Saving preset to <tt>{0}</tt>. If that preset "
|
2022-09-23 17:31:06 +00:00
|
|
|
|
"already exists, it will be overwritten!"
|
2022-08-10 08:46:52 +00:00
|
|
|
|
).format(
|
|
|
|
|
os.path.join(
|
2022-08-11 16:39:52 +00:00
|
|
|
|
os.environ.get(
|
2022-08-20 01:46:35 +00:00
|
|
|
|
"XDG_CONFIG_HOME", os.environ["HOME"] +
|
|
|
|
|
"/.config"
|
2022-08-11 16:39:52 +00:00
|
|
|
|
),
|
2022-08-10 08:46:52 +00:00
|
|
|
|
"presets",
|
2022-09-04 09:25:39 +00:00
|
|
|
|
"user",
|
2022-08-10 08:46:52 +00:00
|
|
|
|
to_slug_case(preset_entry.get_text()) + ".json",
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
)
|
2022-07-18 10:51:25 +00:00
|
|
|
|
dialog.set_response_enabled("save", True)
|
2022-08-10 08:46:52 +00:00
|
|
|
|
|
2022-07-18 10:51:25 +00:00
|
|
|
|
preset_entry.connect("changed", on_preset_entry_change)
|
|
|
|
|
dialog.set_extra_child(preset_entry)
|
|
|
|
|
|
|
|
|
|
dialog.connect("response", self.save_preset, preset_entry)
|
|
|
|
|
|
|
|
|
|
dialog.present()
|
|
|
|
|
|
2022-09-13 21:16:14 +00:00
|
|
|
|
def show_exit_dialog(self, *_args):
|
|
|
|
|
dialog = Adw.MessageDialog(
|
|
|
|
|
transient_for=self.props.active_window,
|
|
|
|
|
heading=_("You have unsaved changes!"),
|
|
|
|
|
body=_(
|
2022-09-23 17:33:52 +00:00
|
|
|
|
"Saving preset to <tt>{0}</tt>. If that preset already "
|
2022-09-23 17:31:06 +00:00
|
|
|
|
"exists, it will be overwritten!"
|
2022-09-13 21:16:14 +00:00
|
|
|
|
).format(
|
|
|
|
|
os.path.join(
|
|
|
|
|
os.environ.get("XDG_CONFIG_HOME",
|
|
|
|
|
os.environ["HOME"] + "/.config"),
|
|
|
|
|
"presets",
|
|
|
|
|
"user",
|
|
|
|
|
to_slug_case(self.preset_name) + ".json",
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
body_use_markup=True,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
dialog.add_response("cancel", _("Cancel"))
|
|
|
|
|
dialog.add_response("discard", _("Discard"))
|
|
|
|
|
dialog.add_response("save", _("Save"))
|
|
|
|
|
dialog.set_response_appearance(
|
|
|
|
|
"save", Adw.ResponseAppearance.SUGGESTED)
|
|
|
|
|
dialog.set_response_appearance(
|
|
|
|
|
"discard", Adw.ResponseAppearance.DESTRUCTIVE)
|
|
|
|
|
dialog.set_default_response("cancel")
|
|
|
|
|
dialog.set_close_response("cancel")
|
|
|
|
|
|
|
|
|
|
preset_entry = Gtk.Entry(placeholder_text="Preset Name")
|
|
|
|
|
preset_entry.set_text(self.preset_name)
|
|
|
|
|
|
|
|
|
|
def on_preset_entry_change(*_args):
|
|
|
|
|
if len(preset_entry.get_text()) == 0:
|
|
|
|
|
dialog.set_body(
|
|
|
|
|
_(
|
2022-09-23 17:33:52 +00:00
|
|
|
|
"Saving preset to <tt>{0}</tt>. If that preset "
|
2022-09-23 17:31:06 +00:00
|
|
|
|
"already exists, it will be overwritten!"
|
2022-09-13 21:16:14 +00:00
|
|
|
|
).format(
|
|
|
|
|
os.path.join(
|
|
|
|
|
os.environ.get(
|
|
|
|
|
"XDG_CONFIG_HOME", os.environ["HOME"] +
|
|
|
|
|
"/.config"
|
|
|
|
|
),
|
|
|
|
|
"presets",
|
|
|
|
|
"user",
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
dialog.set_response_enabled("save", False)
|
|
|
|
|
else:
|
|
|
|
|
dialog.set_body(
|
|
|
|
|
_(
|
2022-09-23 17:33:52 +00:00
|
|
|
|
"Saving preset to <tt>{0}</tt>. If that preset "
|
2022-09-23 17:31:06 +00:00
|
|
|
|
"already exists, it will be overwritten!"
|
2022-09-13 21:16:14 +00:00
|
|
|
|
).format(
|
|
|
|
|
os.path.join(
|
|
|
|
|
os.environ.get(
|
|
|
|
|
"XDG_CONFIG_HOME", os.environ["HOME"] +
|
|
|
|
|
"/.config"
|
|
|
|
|
),
|
|
|
|
|
"presets",
|
|
|
|
|
"user",
|
|
|
|
|
to_slug_case(preset_entry.get_text()) + ".json",
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
dialog.set_response_enabled("save", True)
|
|
|
|
|
|
|
|
|
|
preset_entry.connect("changed", on_preset_entry_change)
|
|
|
|
|
dialog.set_extra_child(preset_entry)
|
|
|
|
|
|
|
|
|
|
dialog.connect("response", self.save_preset, preset_entry)
|
|
|
|
|
|
|
|
|
|
dialog.present()
|
|
|
|
|
|
2022-07-25 14:35:40 +00:00
|
|
|
|
def save_preset(self, _unused, response, entry):
|
2022-07-18 10:51:25 +00:00
|
|
|
|
if response == "save":
|
2022-09-14 12:49:39 +00:00
|
|
|
|
self.preset.save_preset(entry.get_text(), self.plugins_list)
|
|
|
|
|
self.clear_dirty()
|
|
|
|
|
self.win.toast_overlay.add_toast(
|
|
|
|
|
Adw.Toast(title=_("Preset saved")))
|
2022-09-13 21:16:14 +00:00
|
|
|
|
elif response == "discard":
|
|
|
|
|
self.clear_dirty()
|
|
|
|
|
self.win.close()
|
2022-09-13 21:28:21 +00:00
|
|
|
|
|
2022-08-14 14:14:33 +00:00
|
|
|
|
def apply_color_scheme(self, widget, response):
|
2022-07-17 16:24:07 +00:00
|
|
|
|
if response == "apply":
|
2022-08-22 11:14:05 +00:00
|
|
|
|
if widget.get_app_types()["gtk4"]:
|
|
|
|
|
gtk4_dir = os.path.join(
|
2022-09-07 15:52:50 +00:00
|
|
|
|
os.environ.get("XDG_CONFIG_HOME",
|
|
|
|
|
os.environ["HOME"] + "/.config"),
|
2022-08-22 11:14:05 +00:00
|
|
|
|
"gtk-4.0",
|
|
|
|
|
)
|
|
|
|
|
if not os.path.exists(gtk4_dir):
|
|
|
|
|
os.makedirs(gtk4_dir)
|
|
|
|
|
gtk4_css = self.generate_gtk_css("gtk4")
|
2022-08-31 03:53:34 +00:00
|
|
|
|
contents = ""
|
2022-09-01 13:21:58 +00:00
|
|
|
|
try:
|
|
|
|
|
with open(
|
2022-09-07 15:52:50 +00:00
|
|
|
|
os.path.join(gtk4_dir, "gtk.css"), "r", encoding="utf-8"
|
2022-09-01 13:21:58 +00:00
|
|
|
|
) as file:
|
|
|
|
|
contents = file.read()
|
2022-09-01 13:22:24 +00:00
|
|
|
|
except FileNotFoundError: # first run
|
2022-09-01 13:21:58 +00:00
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
with open(
|
2022-09-23 11:14:21 +00:00
|
|
|
|
os.path.join(gtk4_dir, "gtk.css.bak"), "w", encoding="utf-8"
|
2022-09-01 13:21:58 +00:00
|
|
|
|
) as file:
|
2022-09-01 13:22:24 +00:00
|
|
|
|
file.write(contents)
|
2022-09-01 13:21:58 +00:00
|
|
|
|
finally:
|
|
|
|
|
with open(
|
2022-09-23 11:14:21 +00:00
|
|
|
|
os.path.join(gtk4_dir, "gtk.css"), "w", encoding="utf-8"
|
2022-09-01 13:21:58 +00:00
|
|
|
|
) as file:
|
|
|
|
|
file.write(gtk4_css)
|
2022-09-22 17:48:32 +00:00
|
|
|
|
|
2022-08-22 11:14:05 +00:00
|
|
|
|
if widget.get_app_types()["gtk3"]:
|
|
|
|
|
gtk3_dir = os.path.join(
|
2022-09-07 15:52:50 +00:00
|
|
|
|
os.environ.get("XDG_CONFIG_HOME",
|
|
|
|
|
os.environ["HOME"] + "/.config"),
|
2022-08-22 11:14:05 +00:00
|
|
|
|
"gtk-3.0",
|
|
|
|
|
)
|
|
|
|
|
if not os.path.exists(gtk3_dir):
|
|
|
|
|
os.makedirs(gtk3_dir)
|
|
|
|
|
gtk3_css = self.generate_gtk_css("gtk3")
|
2022-09-01 13:21:58 +00:00
|
|
|
|
contents = ""
|
|
|
|
|
try:
|
|
|
|
|
with open(
|
2022-09-23 11:14:21 +00:00
|
|
|
|
os.path.join(gtk3_dir, "gtk.css"), "r", encoding="utf-8"
|
2022-09-01 13:21:58 +00:00
|
|
|
|
) as file:
|
|
|
|
|
contents = file.read()
|
2022-09-01 13:22:24 +00:00
|
|
|
|
except FileNotFoundError: # first run
|
2022-09-01 13:21:58 +00:00
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
with open(
|
2022-09-23 11:14:21 +00:00
|
|
|
|
os.path.join(gtk3_dir, "gtk.css.bak"), "w", encoding="utf-8"
|
2022-09-01 13:21:58 +00:00
|
|
|
|
) as file:
|
2022-09-01 13:22:24 +00:00
|
|
|
|
file.write(contents)
|
2022-09-01 13:21:58 +00:00
|
|
|
|
finally:
|
|
|
|
|
with open(
|
2022-09-23 11:14:21 +00:00
|
|
|
|
os.path.join(gtk3_dir, "gtk.css"), "w", encoding="utf-8"
|
2022-09-01 13:21:58 +00:00
|
|
|
|
) as file:
|
|
|
|
|
file.write(gtk3_css)
|
2022-09-22 17:48:32 +00:00
|
|
|
|
|
2022-09-10 10:37:08 +00:00
|
|
|
|
self.reload_plugins()
|
2022-09-10 08:38:16 +00:00
|
|
|
|
self.plugins_list.apply()
|
2022-09-10 08:38:43 +00:00
|
|
|
|
|
2022-08-11 16:39:24 +00:00
|
|
|
|
self.win.toast_overlay.add_toast(
|
2022-08-25 13:28:38 +00:00
|
|
|
|
Adw.Toast(title=_("Preset set sucessfully"))
|
2022-08-11 16:39:52 +00:00
|
|
|
|
)
|
2022-07-17 16:24:07 +00:00
|
|
|
|
|
2022-10-02 19:52:30 +00:00
|
|
|
|
dialog = Adw.MessageDialog(
|
|
|
|
|
transient_for=self.props.active_window,
|
|
|
|
|
heading=_("Log out ?"),
|
|
|
|
|
body=_(
|
|
|
|
|
"For the changes to take effect, you need to log out. "
|
|
|
|
|
),
|
|
|
|
|
body_use_markup=True,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
dialog.add_response("cancel", _("Cancel"))
|
|
|
|
|
dialog.add_response("logout", _("Logout"))
|
|
|
|
|
dialog.set_response_appearance(
|
|
|
|
|
"logout", Adw.ResponseAppearance.DESTRUCTIVE)
|
|
|
|
|
dialog.set_default_response("cancel")
|
|
|
|
|
dialog.set_close_response("cancel")
|
|
|
|
|
|
|
|
|
|
dialog.connect('response', self.on_logout_dialog_response)
|
|
|
|
|
dialog.present()
|
|
|
|
|
|
|
|
|
|
def on_logout_dialog_response (self, dialog, response):
|
|
|
|
|
if response == "logout":
|
|
|
|
|
print("logout")
|
2022-10-05 12:30:28 +00:00
|
|
|
|
run_command(['gnome-session-quit', '--no-prompt'])
|
2022-10-02 19:52:30 +00:00
|
|
|
|
|
2022-09-01 12:11:38 +00:00
|
|
|
|
def restore_color_scheme(self, widget, response):
|
|
|
|
|
if response == "restore":
|
|
|
|
|
if widget.get_app_types()["gtk4"]:
|
|
|
|
|
file = Gio.File.new_for_path(
|
|
|
|
|
os.path.join(
|
|
|
|
|
os.environ.get(
|
|
|
|
|
"XDG_CONFIG_HOME", os.environ["HOME"] + "/.config"
|
|
|
|
|
),
|
|
|
|
|
"gtk-4.0/gtk.css.bak",
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
try:
|
|
|
|
|
backup = open(
|
|
|
|
|
os.path.join(
|
|
|
|
|
os.environ.get(
|
2022-09-07 15:52:50 +00:00
|
|
|
|
"XDG_CONFIG_HOME", os.environ["HOME"] +
|
|
|
|
|
"/.config"
|
|
|
|
|
),
|
2022-09-01 12:11:38 +00:00
|
|
|
|
"gtk-4.0/gtk.css.bak",
|
|
|
|
|
),
|
|
|
|
|
"r",
|
|
|
|
|
encoding="utf-8",
|
|
|
|
|
)
|
|
|
|
|
contents = backup.read()
|
|
|
|
|
backup.close()
|
|
|
|
|
gtk4css = open(
|
|
|
|
|
os.path.join(
|
|
|
|
|
os.environ.get(
|
2022-09-07 15:52:50 +00:00
|
|
|
|
"XDG_CONFIG_HOME", os.environ["HOME"] +
|
|
|
|
|
"/.config"
|
|
|
|
|
),
|
2022-09-01 12:11:38 +00:00
|
|
|
|
"gtk-4.0/gtk.css",
|
|
|
|
|
),
|
|
|
|
|
"w",
|
|
|
|
|
encoding="utf-8",
|
|
|
|
|
)
|
|
|
|
|
gtk4css.write(contents)
|
|
|
|
|
gtk4css.close()
|
|
|
|
|
except FileNotFoundError:
|
|
|
|
|
self.win.toast_overlay.add_toast(
|
2022-10-08 00:26:29 +00:00
|
|
|
|
Adw.Toast(title=_("Could not restore GTK 4 backup"))
|
2022-09-01 12:11:38 +00:00
|
|
|
|
)
|
|
|
|
|
|
2022-07-22 15:10:52 +00:00
|
|
|
|
def reset_color_scheme(self, widget, response):
|
2022-07-17 16:24:07 +00:00
|
|
|
|
if response == "reset":
|
2022-07-22 12:29:32 +00:00
|
|
|
|
if widget.get_app_types()["gtk4"]:
|
2022-08-10 08:46:52 +00:00
|
|
|
|
file = Gio.File.new_for_path(
|
|
|
|
|
os.path.join(
|
2022-08-11 16:39:52 +00:00
|
|
|
|
os.environ.get(
|
|
|
|
|
"XDG_CONFIG_HOME", os.environ["HOME"] + "/.config"
|
|
|
|
|
),
|
|
|
|
|
"gtk-4.0/gtk.css",
|
|
|
|
|
)
|
2022-08-10 08:46:52 +00:00
|
|
|
|
)
|
2022-07-22 12:29:32 +00:00
|
|
|
|
try:
|
|
|
|
|
file.delete()
|
2022-08-01 09:43:42 +00:00
|
|
|
|
except Exception:
|
2022-07-22 12:29:32 +00:00
|
|
|
|
pass
|
2022-08-11 16:39:24 +00:00
|
|
|
|
|
2022-07-22 12:29:32 +00:00
|
|
|
|
if widget.get_app_types()["gtk3"]:
|
2022-08-10 08:46:52 +00:00
|
|
|
|
file = Gio.File.new_for_path(
|
|
|
|
|
os.path.join(
|
2022-08-11 16:39:52 +00:00
|
|
|
|
os.environ.get(
|
|
|
|
|
"XDG_CONFIG_HOME", os.environ["HOME"] + "/.config"
|
|
|
|
|
),
|
|
|
|
|
"gtk-3.0/gtk.css",
|
|
|
|
|
)
|
2022-08-10 08:46:52 +00:00
|
|
|
|
)
|
2022-07-22 12:29:32 +00:00
|
|
|
|
try:
|
|
|
|
|
file.delete()
|
2022-08-01 09:43:42 +00:00
|
|
|
|
except Exception:
|
2022-07-22 12:29:32 +00:00
|
|
|
|
pass
|
2022-08-17 21:35:59 +00:00
|
|
|
|
self.win.toast_overlay.add_toast(
|
2022-08-25 13:28:38 +00:00
|
|
|
|
Adw.Toast(title=_("Preset reseted")))
|
2022-07-17 16:24:07 +00:00
|
|
|
|
|
2022-08-31 17:57:47 +00:00
|
|
|
|
def show_preferences(self, *_args):
|
|
|
|
|
prefs = GradiencePreferencesWindow(self.win)
|
|
|
|
|
prefs.set_transient_for(self.win)
|
|
|
|
|
prefs.present()
|
2022-09-01 16:19:45 +00:00
|
|
|
|
|
2022-07-25 14:35:40 +00:00
|
|
|
|
def show_about_window(self, *_args):
|
2022-08-10 08:46:52 +00:00
|
|
|
|
about = Adw.AboutWindow(
|
|
|
|
|
transient_for=self.props.active_window,
|
2022-08-15 23:19:03 +00:00
|
|
|
|
application_name=_("Gradience"),
|
2022-08-15 18:33:41 +00:00
|
|
|
|
application_icon=app_id,
|
2022-08-15 23:19:03 +00:00
|
|
|
|
developer_name=_("Gradience Team"),
|
2022-08-19 19:14:05 +00:00
|
|
|
|
website=project_url,
|
2022-08-19 19:18:08 +00:00
|
|
|
|
support_url=help_url,
|
2022-08-19 19:14:05 +00:00
|
|
|
|
issue_url=bugtracker_url,
|
2022-08-10 08:46:52 +00:00
|
|
|
|
developers=[
|
2022-10-04 19:14:18 +00:00
|
|
|
|
"0xMRTT https://github.com/0xMRTT",
|
2022-10-05 11:14:15 +00:00
|
|
|
|
"Artyom Fomin https://github.com/ArtyIF",
|
2022-09-28 12:45:17 +00:00
|
|
|
|
"Verantor https://github.com/Verantor",
|
2022-10-04 19:23:47 +00:00
|
|
|
|
"tfuxu https://github.com/tfuxu",
|
2022-10-04 18:39:53 +00:00
|
|
|
|
"u1F98E https://github.com/u1f98e",
|
2022-08-10 12:18:38 +00:00
|
|
|
|
],
|
2022-09-07 15:52:50 +00:00
|
|
|
|
artists=["David Lapshin https://github.com/daudix-UFO"],
|
|
|
|
|
designers=["David Lapshin https://github.com/daudix-UFO"],
|
2022-10-05 11:14:15 +00:00
|
|
|
|
documenters=[
|
|
|
|
|
"0xMRTT https://github.com/0xMRTT",
|
|
|
|
|
"David Lapshin https://github.com/daudix-UFO"
|
|
|
|
|
],
|
2022-09-22 21:57:25 +00:00
|
|
|
|
# Translators: This is a place to put your credits (formats:
|
2022-09-23 11:14:21 +00:00
|
|
|
|
# "Name https://example.com" or "Name <email@example.com>",
|
|
|
|
|
# no quotes) and is not meant to be translated literally.
|
2022-09-28 12:46:18 +00:00
|
|
|
|
translator_credits="""0xMRTT https://github.com/0xMRTT
|
2022-10-04 19:23:47 +00:00
|
|
|
|
엘련 (Jisu Kim) https://github.com/vbalien
|
2022-09-27 20:30:49 +00:00
|
|
|
|
Aggelos Tselios https://www.transifex.com/user/profile/AndroGR
|
2022-09-28 12:45:17 +00:00
|
|
|
|
BritishBenji https://github.com/BritishBenji
|
2022-08-25 21:51:49 +00:00
|
|
|
|
David Lapshin https://github.com/daudix-UFO
|
2022-09-28 12:45:17 +00:00
|
|
|
|
Davide Ferracin https://github.com/phaerrax
|
|
|
|
|
Ewout van Mansom https://github.com/emansom
|
|
|
|
|
FineFindus https://github.com/FineFindus
|
2022-10-05 19:20:19 +00:00
|
|
|
|
Gabriel Lemos https://github.com/gbrlgn
|
2022-09-27 20:30:49 +00:00
|
|
|
|
Juanjo Cillero https://www.transifex.com/user/profile/renux918
|
2022-10-05 10:27:42 +00:00
|
|
|
|
JungHee Lee https://github.com/MarongHappy
|
2022-09-28 12:45:17 +00:00
|
|
|
|
K.B.Dharun Krishna https://github.com/kbdharun
|
2022-10-04 19:23:47 +00:00
|
|
|
|
Karol Lademan https://www.transifex.com/user/profile/karlod
|
|
|
|
|
Luna Jernberg https://github.com/bittin
|
2022-09-28 12:45:17 +00:00
|
|
|
|
Maxime V https://www.transifex.com/user/profile/Adaoh
|
2022-10-05 19:23:35 +00:00
|
|
|
|
Michal S. <michal@getcryst.al>
|
2022-09-28 12:45:17 +00:00
|
|
|
|
Monty Monteusz https://www.transifex.com/user/profile/MontyQIQI
|
2022-10-04 19:23:47 +00:00
|
|
|
|
Philip Goto https://github.com/flipflop97
|
2022-09-28 12:45:17 +00:00
|
|
|
|
Renato Corrêa https://github.com/renatocrrs
|
|
|
|
|
Rene Coty https://github.com/rene-coty
|
2022-10-05 10:33:55 +00:00
|
|
|
|
Sabri Ünal https://github.com/libreajans
|
2022-09-28 12:40:19 +00:00
|
|
|
|
Taylan Tatlı https://www.transifex.com/user/profile/TaylanTatli34
|
2022-10-05 19:20:19 +00:00
|
|
|
|
bzizmza https://github.com/bzizmza
|
2022-10-04 18:39:53 +00:00
|
|
|
|
muzena https://github.com/muzena
|
2022-10-04 19:23:47 +00:00
|
|
|
|
renatocrrs https://github.com/renatocrrs
|
|
|
|
|
tfuxu https://github.com/tfuxu
|
2022-10-05 19:20:19 +00:00
|
|
|
|
yangyangdaji https://github.com/yangyangdaji
|
|
|
|
|
Óscar Fernández Díaz https://github.com/oscfdezdz""",
|
2022-08-15 23:19:03 +00:00
|
|
|
|
copyright="© 2022 Gradience Team",
|
2022-08-11 15:57:02 +00:00
|
|
|
|
license_type=Gtk.License.GPL_3_0,
|
2022-08-15 18:33:41 +00:00
|
|
|
|
version=version,
|
2022-08-23 17:23:27 +00:00
|
|
|
|
release_notes_version=rel_ver,
|
2022-09-07 15:52:50 +00:00
|
|
|
|
release_notes=_(
|
2022-09-30 16:18:27 +00:00
|
|
|
|
"""
|
|
|
|
|
<ul>
|
2022-10-07 17:00:12 +00:00
|
|
|
|
<li>Added ability to star preset to display it in Palette</li>
|
2022-10-07 16:47:03 +00:00
|
|
|
|
<li>Updated Firefox GNOME Theme plugin</li>
|
2022-10-07 17:00:12 +00:00
|
|
|
|
<li>Welcome screen have been improved</li>
|
|
|
|
|
<li>Margins in color info popovers are fixed</li>
|
|
|
|
|
<li>Added filter to search presets by repo</li>
|
|
|
|
|
<li>Added "No Preferences" window</li>
|
|
|
|
|
<li>Preset Manager window size have changed</li>
|
|
|
|
|
<li>"Offline" and "Nothing Found" pages have been added to Preset Manager</li>
|
|
|
|
|
<li>All text have been rewritten to follow GNOME Writing Guides</li>
|
|
|
|
|
<li>Switch from aiohttp to Libsoup3</li>
|
|
|
|
|
<li>Migrate to GNOME SDK 43</li>
|
|
|
|
|
<li>All contributors have been added to "About" window</li>
|
2022-10-07 17:14:55 +00:00
|
|
|
|
<li>Added "Log Out" dialog after preset apply</li>
|
2022-10-07 17:00:12 +00:00
|
|
|
|
<li>Some symbolics have changed, removed unnecessary hardcoded symbolics</li>
|
|
|
|
|
<li>Flatpak theme override now fixed</li>
|
|
|
|
|
<li>New and updated translations</li>
|
2022-09-30 16:18:27 +00:00
|
|
|
|
</ul>
|
|
|
|
|
"""
|
2022-09-07 15:52:50 +00:00
|
|
|
|
),
|
|
|
|
|
comments=_(
|
2022-09-30 16:18:27 +00:00
|
|
|
|
"""
|
2022-09-22 21:57:25 +00:00
|
|
|
|
Gradience is a tool for customizing Libadwaita applications and the adw-gtk3 \
|
|
|
|
|
theme.
|
2022-08-15 23:19:03 +00:00
|
|
|
|
With Gradience you can:
|
2022-08-17 21:35:59 +00:00
|
|
|
|
|
2022-08-23 11:01:17 +00:00
|
|
|
|
- Change any color of Adwaita theme
|
2022-10-04 13:19:36 +00:00
|
|
|
|
- Apply Material 3 colors from wallpaper
|
2022-08-23 11:01:17 +00:00
|
|
|
|
- Use other users presets
|
|
|
|
|
- Change advanced options with CSS
|
|
|
|
|
- Extend functionality using plugins
|
2022-08-17 21:35:59 +00:00
|
|
|
|
|
2022-10-08 00:26:29 +00:00
|
|
|
|
This app is written in Python and uses GTK 4 and Libadwaita.
|
2022-09-30 16:18:27 +00:00
|
|
|
|
"""
|
2022-09-07 15:52:50 +00:00
|
|
|
|
),
|
2022-08-10 08:46:52 +00:00
|
|
|
|
)
|
2022-09-28 12:46:35 +00:00
|
|
|
|
about.add_credit_section(
|
2022-10-04 21:04:56 +00:00
|
|
|
|
_("Plugins by"),
|
2022-09-28 12:46:35 +00:00
|
|
|
|
[
|
|
|
|
|
"0xMRTT https://github.com/0xMRTT",
|
2022-09-28 14:25:42 +00:00
|
|
|
|
"Apisu https://github.com/aspizu",
|
2022-09-28 12:46:35 +00:00
|
|
|
|
],
|
2022-09-28 12:40:19 +00:00
|
|
|
|
)
|
2022-10-04 19:11:42 +00:00
|
|
|
|
about.add_credit_section(
|
2022-10-04 21:04:56 +00:00
|
|
|
|
_("Presets by"),
|
2022-10-04 19:11:42 +00:00
|
|
|
|
[
|
|
|
|
|
"0xMRTT https://github.com/0xMRTT",
|
2022-10-05 11:14:15 +00:00
|
|
|
|
"Ben Mitchell https://github.com/crispyricepc",
|
2022-10-04 19:11:42 +00:00
|
|
|
|
"David Lapshin https://github.com/daudix-UFO",
|
2022-10-04 19:23:47 +00:00
|
|
|
|
"JoshM-Yoru https://github.com/JoshM-Yoru",
|
2022-10-05 11:14:15 +00:00
|
|
|
|
"José Hunter https://github.com/halfmexican",
|
|
|
|
|
"Kainoa Kanter https://github.com/ThatOneCalculator",
|
2022-10-04 19:23:47 +00:00
|
|
|
|
"Link Dupont https://github.com/subpop",
|
|
|
|
|
"Luis David López https://github.com/lopeztel",
|
|
|
|
|
"Mohammad Saleh Kamyab https://github.com/mskf1383",
|
2022-10-05 11:14:15 +00:00
|
|
|
|
"Sal Watson https://github.com/salarua",
|
2022-10-04 19:11:42 +00:00
|
|
|
|
"TeryVeneno https://github.com/TeryVeneno",
|
2022-10-05 11:14:15 +00:00
|
|
|
|
"arslee https://github.com/arslee07",
|
|
|
|
|
"badlydrawnface https://github.com/badlydrawnface",
|
2022-10-04 19:23:47 +00:00
|
|
|
|
"cmagnificent https://github.com/cmagnificent",
|
2022-10-04 19:11:42 +00:00
|
|
|
|
"hericiumvevo https://github.com/hericiumvevo",
|
2022-10-05 11:14:15 +00:00
|
|
|
|
"tfuxu https://github.com/tfuxu",
|
|
|
|
|
"zehkira https://github.com/zehkira",
|
2022-10-04 19:11:42 +00:00
|
|
|
|
],
|
|
|
|
|
)
|
2022-09-28 12:46:35 +00:00
|
|
|
|
about.add_credit_section(
|
2022-10-04 21:04:56 +00:00
|
|
|
|
_("Packages by"),
|
2022-09-28 12:46:35 +00:00
|
|
|
|
[
|
|
|
|
|
"0xMRTT https://github.com/0xMRTT",
|
|
|
|
|
"Lyes Saadi https://github.com/lyessaadi",
|
|
|
|
|
],
|
2022-09-28 12:40:19 +00:00
|
|
|
|
)
|
2022-10-04 18:39:53 +00:00
|
|
|
|
about.add_credit_section(
|
2022-10-04 21:04:56 +00:00
|
|
|
|
_("Fixes by"),
|
2022-10-04 18:39:53 +00:00
|
|
|
|
[
|
2022-10-04 20:59:36 +00:00
|
|
|
|
"Erick Howard https://github.com/DivineBicycle",
|
|
|
|
|
"Hari Rana https://github.com/TheEvilSkeleton",
|
2022-10-04 18:48:17 +00:00
|
|
|
|
"José Hunter https://github.com/halfmexican",
|
2022-10-05 11:14:15 +00:00
|
|
|
|
"Sabri Ünal https://github.com/libreajans",
|
2022-10-04 20:59:36 +00:00
|
|
|
|
"Sal Watson https://github.com/salarua",
|
2022-10-04 18:39:53 +00:00
|
|
|
|
],
|
|
|
|
|
)
|
2022-10-05 11:14:15 +00:00
|
|
|
|
about.add_acknowledgement_section(
|
|
|
|
|
_("Special thanks to"),
|
|
|
|
|
[
|
|
|
|
|
"Artyom Fomin https://github.com/ArtyIF",
|
|
|
|
|
"Weblate https://weblate.org",
|
|
|
|
|
],
|
|
|
|
|
)
|
2022-10-04 18:39:53 +00:00
|
|
|
|
|
2022-07-17 11:46:05 +00:00
|
|
|
|
about.present()
|
|
|
|
|
|
2022-07-24 17:46:37 +00:00
|
|
|
|
def update_custom_css_text(self, app_type, new_value):
|
|
|
|
|
self.custom_css[app_type] = new_value
|
|
|
|
|
self.reload_variables()
|
2022-07-17 11:46:05 +00:00
|
|
|
|
|
|
|
|
|
def create_action(self, name, callback, shortcuts=None):
|
|
|
|
|
"""Add an application action.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
name: the name of the action
|
|
|
|
|
callback: the function to be called when the action is
|
|
|
|
|
activated
|
|
|
|
|
shortcuts: an optional list of accelerators
|
|
|
|
|
"""
|
|
|
|
|
action = Gio.SimpleAction.new(name, None)
|
|
|
|
|
action.connect("activate", callback)
|
|
|
|
|
self.add_action(action)
|
|
|
|
|
if shortcuts:
|
|
|
|
|
self.set_accels_for_action(f"app.{name}", shortcuts)
|
|
|
|
|
|
2022-08-10 08:46:52 +00:00
|
|
|
|
def create_stateful_action(
|
|
|
|
|
self, name, parameter_type, initial_state, callback, shortcuts=None
|
|
|
|
|
):
|
|
|
|
|
"""Add a stateful application action."""
|
2022-08-17 21:35:59 +00:00
|
|
|
|
action = Gio.SimpleAction.new_stateful(
|
|
|
|
|
name, parameter_type, initial_state)
|
2022-07-17 19:27:57 +00:00
|
|
|
|
action.connect("activate", callback)
|
|
|
|
|
self.add_action(action)
|
|
|
|
|
if shortcuts:
|
|
|
|
|
self.set_accels_for_action(f"app.{name}", shortcuts)
|
|
|
|
|
|
2022-09-10 08:19:54 +00:00
|
|
|
|
def setup_plugins(self):
|
|
|
|
|
buglog("setup plugins")
|
|
|
|
|
self.plugins_group = self.plugins_list.to_group()
|
|
|
|
|
|
|
|
|
|
self.win.content_plugins.add(self.plugins_group)
|
|
|
|
|
self.plugins_group = self.plugins_group
|
|
|
|
|
|
|
|
|
|
self.custom_css_group = GradienceCustomCSSGroup()
|
|
|
|
|
for app_type in settings_schema["custom_css_app_types"]:
|
|
|
|
|
self.custom_css[app_type] = ""
|
|
|
|
|
self.custom_css_group.load_custom_css(self.custom_css)
|
|
|
|
|
self.win.content_plugins.add(self.custom_css_group)
|
|
|
|
|
self.custom_css_group = self.custom_css_group
|
|
|
|
|
|
|
|
|
|
plugins_errors = self.plugins_list.validate()
|
|
|
|
|
|
|
|
|
|
self.props.active_window.update_errors(
|
|
|
|
|
self.global_errors + plugins_errors)
|
2022-09-10 08:38:43 +00:00
|
|
|
|
|
2022-08-19 18:54:44 +00:00
|
|
|
|
def reload_plugins(self):
|
2022-09-10 13:39:54 +00:00
|
|
|
|
self.plugins_list.reload()
|
2022-08-23 17:38:09 +00:00
|
|
|
|
buglog("reload plugins")
|
2022-09-10 08:19:54 +00:00
|
|
|
|
self.win.content_plugins.remove(self.plugins_group)
|
|
|
|
|
self.win.content_plugins.remove(self.custom_css_group)
|
2022-09-10 08:38:43 +00:00
|
|
|
|
|
2022-09-04 09:08:32 +00:00
|
|
|
|
self.plugins_group = self.plugins_list.to_group()
|
|
|
|
|
|
|
|
|
|
self.win.content_plugins.add(self.plugins_group)
|
|
|
|
|
self.plugins_group = self.plugins_group
|
|
|
|
|
|
2022-09-10 08:19:54 +00:00
|
|
|
|
self.custom_css_group = GradienceCustomCSSGroup()
|
2022-09-04 09:08:32 +00:00
|
|
|
|
for app_type in settings_schema["custom_css_app_types"]:
|
|
|
|
|
self.custom_css[app_type] = ""
|
2022-09-10 08:19:54 +00:00
|
|
|
|
self.custom_css_group.load_custom_css(self.custom_css)
|
|
|
|
|
self.win.content_plugins.add(self.custom_css_group)
|
|
|
|
|
self.custom_css_group = self.custom_css_group
|
2022-09-04 09:44:19 +00:00
|
|
|
|
|
2022-09-04 09:43:52 +00:00
|
|
|
|
plugins_errors = self.plugins_list.validate()
|
2022-09-04 09:44:19 +00:00
|
|
|
|
|
2022-09-04 09:43:52 +00:00
|
|
|
|
self.props.active_window.update_errors(
|
|
|
|
|
self.global_errors + plugins_errors)
|
2022-07-17 11:46:05 +00:00
|
|
|
|
|
2022-09-07 15:57:00 +00:00
|
|
|
|
@staticmethod
|
|
|
|
|
def show_adwaita_demo(*_args):
|
2022-08-20 01:31:36 +00:00
|
|
|
|
GLib.spawn_command_line_async(
|
|
|
|
|
'sh -c "/bin/adwaita-1-demo > /dev/null 2>&1"')
|
|
|
|
|
|
2022-09-07 15:57:00 +00:00
|
|
|
|
@staticmethod
|
|
|
|
|
def show_gtk4_demo(*_args):
|
2022-08-20 01:43:47 +00:00
|
|
|
|
GLib.spawn_command_line_async(
|
|
|
|
|
'sh -c "/bin/gtk4-demo > /dev/null 2>&1"')
|
|
|
|
|
|
2022-09-07 15:57:00 +00:00
|
|
|
|
@staticmethod
|
|
|
|
|
def show_gtk4_widget_factory(*_args):
|
2022-08-20 01:43:47 +00:00
|
|
|
|
GLib.spawn_command_line_async(
|
2022-09-07 15:52:50 +00:00
|
|
|
|
'sh -c "/bin/gtk4-widget-factory > /dev/null 2>&1"'
|
|
|
|
|
)
|
2022-08-20 01:43:47 +00:00
|
|
|
|
|
2022-08-19 19:33:02 +00:00
|
|
|
|
|
2022-08-15 18:33:41 +00:00
|
|
|
|
def main():
|
2022-07-17 11:46:05 +00:00
|
|
|
|
"""The application's entry point."""
|
2022-08-19 19:14:05 +00:00
|
|
|
|
app = GradienceApplication()
|
2022-07-17 11:46:05 +00:00
|
|
|
|
return app.run(sys.argv)
|