From 174486a4c9d2131abd8b527adc06c6e6a9fd6fe1 Mon Sep 17 00:00:00 2001 From: tfuxu <73042332+tfuxu@users.noreply.github.com> Date: Thu, 13 Oct 2022 17:58:01 +0200 Subject: [PATCH] fix: change cssutils defaults to fix issues in CSS validation --- data/ui/custom_css_group.blp | 12 ++++++------ gradience/ui/custom_css_group.py | 7 +++++-- gradience/utils/css.py | 12 +++++++++++- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/data/ui/custom_css_group.blp b/data/ui/custom_css_group.blp index 015513c8..f7dda7f6 100644 --- a/data/ui/custom_css_group.blp +++ b/data/ui/custom_css_group.blp @@ -3,19 +3,19 @@ using Adw 1; template GradienceCustomCSSGroup : Adw.PreferencesGroup { title: _("Custom CSS"); - description: _("Changing this may break some programs. Keep in mind that Libadwaita was made so that applications could hardcode values like paddings and margins. Only GTK 4 CSS will be previewed here."); + description: _("Changing this may break some programs. Keep in mind that Libadwaita was made so that applications could hardcode values like paddings and margins."); [header-suffix] - DropDown app-type-dropdown { + DropDown app_type_dropdown { valign: start; - model: app-type-list; + model: app_type_list; notify => on_dropdown_notify(); } ScrolledWindow { min-content-height: 500; max-content-height: 500; - TextView custom-css-text-view { + TextView custom_css_text_view { styles ["card"] left-margin: 10; right-margin: 10; @@ -29,6 +29,6 @@ template GradienceCustomCSSGroup : Adw.PreferencesGroup { } } -StringList app-type-list { +StringList app_type_list { strings [_("GTK 4"), _("GTK 3")] -} \ No newline at end of file +} diff --git a/gradience/ui/custom_css_group.py b/gradience/ui/custom_css_group.py index d43a4ab9..4da23800 100644 --- a/gradience/ui/custom_css_group.py +++ b/gradience/ui/custom_css_group.py @@ -18,6 +18,7 @@ from gi.repository import Gtk, Adw +from gradience.utils.utils import buglog from gradience.constants import rootdir @@ -25,8 +26,8 @@ from gradience.constants import rootdir class GradienceCustomCSSGroup(Adw.PreferencesGroup): __gtype_name__ = "GradienceCustomCSSGroup" - app_type_dropdown = Gtk.Template.Child("app-type-dropdown") - custom_css_text_view = Gtk.Template.Child("custom-css-text-view") + app_type_dropdown = Gtk.Template.Child("app_type_dropdown") + custom_css_text_view = Gtk.Template.Child("custom_css_text_view") def __init__(self, **kwargs): super().__init__(**kwargs) @@ -51,6 +52,8 @@ class GradienceCustomCSSGroup(Adw.PreferencesGroup): @Gtk.Template.Callback() def on_dropdown_notify(self, _unused, pspec): if pspec.name == "selected": + buglog(f"Custom CSS values: {self.custom_css.values()}") + buglog(f"Selected app type in dropdown: {self.app_type_dropdown.get_selected()}") self.custom_css_text_view.get_buffer().set_text( list(self.custom_css.values())[ self.app_type_dropdown.get_selected()] diff --git a/gradience/utils/css.py b/gradience/utils/css.py index 052555fc..0922e8af 100644 --- a/gradience/utils/css.py +++ b/gradience/utils/css.py @@ -16,8 +16,11 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import logging + import cssutils +# Adwaita palette color name dict COLORS = [ "blue_", "green_", @@ -30,6 +33,13 @@ COLORS = [ "dark_", ] +# Override cssutils preferences +cssutils.ser.prefs.minimizeColorHash = False +cssutils.ser.prefs.indentClosingBrace = False +cssutils.ser.prefs.omitLastSemicolon = False + +# Set cssutils module logging to level FATAL +cssutils.log.setLevel(logging.FATAL) def load_preset_from_css(path): css = "" @@ -53,5 +63,5 @@ def load_preset_from_css(path): else: variables[name] = color[:-1] elif rule.type == rule.STYLE_RULE: - css += f"\n{rule.cssText}" + css += f"\n{rule.cssText}\n" return variables, palette, css