fix: change cssutils defaults to fix issues in CSS validation

This commit is contained in:
tfuxu 2022-10-13 17:58:01 +02:00
parent a5c54d8fc1
commit 174486a4c9
3 changed files with 22 additions and 9 deletions

View file

@ -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")]
}
}

View file

@ -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()]

View file

@ -16,8 +16,11 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
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