mirror of
https://github.com/GradienceTeam/Gradience.git
synced 2024-09-29 06:57:53 +00:00
Fix issues with CSS parser (partially) (#634)
This fix resolves issue #631, by overriding defaults in `cssutils` preferences class (specifically `minimizeColorHash`, `indentClosingBrace`, `omitLastSemicolon`).
This commit is contained in:
commit
901dada916
3 changed files with 22 additions and 9 deletions
|
@ -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")]
|
||||
}
|
|
@ -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()]
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue