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
|
2022-08-15 23:22:24 +00:00
|
|
|
# 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-12-02 21:52:47 +00:00
|
|
|
from gradience.backend.constants import rootdir
|
2022-08-11 16:39:52 +00:00
|
|
|
|
2022-12-03 23:00:18 +00:00
|
|
|
from gradience.backend.logger import Logger
|
|
|
|
|
|
|
|
logging = Logger()
|
|
|
|
|
2022-08-13 10:24:16 +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
|
|
|
|
2022-10-13 15:58:01 +00:00
|
|
|
app_type_dropdown = Gtk.Template.Child("app_type_dropdown")
|
|
|
|
custom_css_text_view = Gtk.Template.Child("custom_css_text_view")
|
2022-07-24 17:46:37 +00:00
|
|
|
|
2023-02-02 01:11:32 +00:00
|
|
|
def __init__(self, parent, **kwargs):
|
2022-07-24 17:46:37 +00:00
|
|
|
super().__init__(**kwargs)
|
2023-02-02 01:11:32 +00:00
|
|
|
|
|
|
|
self.parent = parent
|
|
|
|
self.app = self.parent.get_application()
|
|
|
|
|
2022-07-24 17:46:37 +00:00
|
|
|
self.custom_css = {}
|
|
|
|
|
|
|
|
def load_custom_css(self, custom_css):
|
|
|
|
self.custom_css = custom_css
|
2023-05-04 13:24:18 +00:00
|
|
|
|
2022-08-11 16:39:52 +00:00
|
|
|
self.custom_css_text_view.get_buffer().set_text(
|
2022-09-07 15:51:36 +00:00
|
|
|
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
|
|
|
|
2023-02-02 01:11:32 +00:00
|
|
|
def reset_buffer(self):
|
|
|
|
self.app.update_custom_css_text("gtk3", "")
|
|
|
|
self.app.update_custom_css_text("gtk4", "")
|
|
|
|
|
|
|
|
self.custom_css_text_view.get_buffer().set_text("")
|
|
|
|
|
2022-07-24 17:46:37 +00:00
|
|
|
@Gtk.Template.Callback()
|
|
|
|
def on_custom_css_changed(self, buffer):
|
2023-02-02 01:11:32 +00:00
|
|
|
self.app.mark_as_dirty()
|
|
|
|
self.app.update_custom_css_text(
|
2022-09-07 15:51:36 +00:00
|
|
|
list(self.custom_css.keys())[
|
|
|
|
self.app_type_dropdown.get_selected()],
|
2023-02-02 01:11:32 +00:00
|
|
|
buffer.props.text
|
2022-08-11 16:39:52 +00:00
|
|
|
)
|
2022-07-24 17:46:37 +00:00
|
|
|
|
|
|
|
@Gtk.Template.Callback()
|
2022-07-25 14:35:40 +00:00
|
|
|
def on_dropdown_notify(self, _unused, pspec):
|
2022-07-24 17:46:37 +00:00
|
|
|
if pspec.name == "selected":
|
2022-12-03 23:00:18 +00:00
|
|
|
logging.debug(f"Custom CSS values: {self.custom_css.values()}")
|
|
|
|
logging.debug(f"Selected app type in dropdown: {self.app_type_dropdown.get_selected()}")
|
2022-08-11 16:39:52 +00:00
|
|
|
self.custom_css_text_view.get_buffer().set_text(
|
2022-09-07 15:51:36 +00:00
|
|
|
list(self.custom_css.values())[
|
|
|
|
self.app_type_dropdown.get_selected()]
|
2022-08-11 16:39:52 +00:00
|
|
|
)
|