Gradience/gradience/custom_css_group.py

58 lines
2 KiB
Python
Raw Normal View History

2022-07-24 17:46:37 +00:00
# custom_css_group.py
#
2022-08-11 08:16:44 +00:00
# Change the look of Adwaita, with ease
# Copyright (C) 2022 Gradience Team
2022-07-24 17:46:37 +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:52 +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:52 +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-24 17:46:37 +00:00
2022-07-24 18:43:32 +00:00
from gi.repository import Gtk, Adw
2022-07-24 17:46:37 +00:00
2022-08-13 10:27:59 +00:00
from .constants import rootdir
2022-08-11 16:39:52 +00:00
@Gtk.Template(resource_path=f"{rootdir}/ui/custom_css_group.ui")
2022-08-19 19:14:05 +00:00
class GradienceCustomCSSGroup(Adw.PreferencesGroup):
__gtype_name__ = "GradienceCustomCSSGroup"
2022-07-24 17:46:37 +00:00
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)
self.custom_css = {}
def load_custom_css(self, custom_css):
self.custom_css = custom_css
2022-08-11 16:39:52 +00:00
self.custom_css_text_view.get_buffer().set_text(
list(self.custom_css.values())[
self.app_type_dropdown.get_selected()]
2022-08-11 16:39:52 +00:00
)
2022-07-24 17:46:37 +00:00
@Gtk.Template.Callback()
def on_custom_css_changed(self, buffer):
2022-08-01 19:42:42 +00:00
Gtk.Application.get_default().mark_as_dirty()
2022-08-11 16:39:52 +00:00
Gtk.Application.get_default().update_custom_css_text(
list(self.custom_css.keys())[
self.app_type_dropdown.get_selected()],
2022-08-11 16:39:52 +00:00
buffer.props.text,
)
2022-07-24 17:46:37 +00:00
@Gtk.Template.Callback()
def on_dropdown_notify(self, _unused, pspec):
2022-07-24 17:46:37 +00:00
if pspec.name == "selected":
2022-08-11 16:39:52 +00:00
self.custom_css_text_view.get_buffer().set_text(
list(self.custom_css.values())[
self.app_type_dropdown.get_selected()]
2022-08-11 16:39:52 +00:00
)