mirror of
https://github.com/GradienceTeam/Gradience.git
synced 2024-06-26 06:29:57 +00:00
Merge branch 'main' into presets-improvs
This commit is contained in:
commit
921a1ad7e6
|
@ -16,7 +16,11 @@ template GradienceCustomCSSGroup : Adw.PreferencesGroup {
|
|||
min-content-height: 500;
|
||||
max-content-height: 500;
|
||||
TextView custom-css-text-view {
|
||||
styles ["custom-css-view", "card"]
|
||||
styles ["card"]
|
||||
left-margin: 10;
|
||||
right-margin: 10;
|
||||
top-margin: 10;
|
||||
bottom-margin: 10;
|
||||
monospace: true;
|
||||
buffer: TextBuffer {
|
||||
changed => on_custom_css_changed();
|
||||
|
|
|
@ -811,6 +811,7 @@ This app is written in Python and uses GTK 4 and libadwaita.
|
|||
self.global_errors + plugins_errors)
|
||||
|
||||
def reload_plugins(self):
|
||||
self.plugins_list.reload()
|
||||
buglog("reload plugins")
|
||||
self.win.content_plugins.remove(self.plugins_group)
|
||||
self.win.content_plugins.remove(self.custom_css_group)
|
||||
|
|
|
@ -20,23 +20,39 @@ from gi.repository import Gtk, Adw
|
|||
|
||||
from .modules.utils import buglog
|
||||
from .constants import rootdir
|
||||
from pathlib import Path
|
||||
import os
|
||||
|
||||
USER_PLUGIN_DIR = Path(
|
||||
os.path.join(
|
||||
os.environ.get("XDG_DATA_HOME", os.environ["HOME"] + "/.local/share"),
|
||||
"gradience",
|
||||
"plugins",
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@Gtk.Template(resource_path=f"{rootdir}/ui/plugin_row.ui")
|
||||
class GradiencePluginRow(Adw.ActionRow):
|
||||
__gtype_name__ = "GradiencePluginRow"
|
||||
|
||||
def __init__(self, plugin_object, preset, **kwargs):
|
||||
switch = Gtk.Template.Child("switch")
|
||||
settings_button = Gtk.Template.Child("settings-button")
|
||||
remove_button = Gtk.Template.Child("remove-button")
|
||||
|
||||
def __init__(self, plugin_object, preset, plugins_list, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
|
||||
self.plugins_list = plugins_list
|
||||
|
||||
self.plugin_object = plugin_object
|
||||
self.set_name(plugin_object.plugin_id)
|
||||
self.set_title(plugin_object.title)
|
||||
self.set_subtitle("@" + plugin_object.plugin_id)
|
||||
|
||||
switch = Gtk.Template.Child("switch")
|
||||
settings_button = Gtk.Template.Child("settings-button")
|
||||
remove_button = Gtk.Template.Child("remove-button")
|
||||
self.enabled_plugins = self.plugins_list.enabled_plugins
|
||||
if self.plugin_object.plugin_id in self.enabled_plugins:
|
||||
self.switch.set_active(True)
|
||||
|
||||
self.give_preset_settings(preset)
|
||||
|
||||
|
@ -46,12 +62,19 @@ class GradiencePluginRow(Adw.ActionRow):
|
|||
|
||||
@Gtk.Template.Callback()
|
||||
def on_remove_plugin_clicked(self, *_args):
|
||||
print("delete")
|
||||
plugin_yapsy_file = (
|
||||
USER_PLUGIN_DIR / f"{self.plugin_object.plugin_id}.yapsy-plugin"
|
||||
)
|
||||
buglog("remove", plugin_yapsy_file)
|
||||
os.remove(plugin_yapsy_file)
|
||||
Gtk.Application.get_default().reload_plugins()
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
def on_switch_toggled(self, *_args):
|
||||
buglog("toggled")
|
||||
if self.switch.get_active():
|
||||
self.plugins_list.enable_plugin(self.plugin_object.plugin_id)
|
||||
else:
|
||||
self.plugins_list.disable_plugin(self.plugin_object.plugin_id)
|
||||
|
||||
def give_preset_settings(self, preset_settings):
|
||||
self.preset_settings = preset_settings
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
import os
|
||||
|
||||
from gi.repository import Adw
|
||||
from gi.repository import Adw, GLib
|
||||
from yapsy.PluginManager import PluginManager
|
||||
from .plugin_row import GradiencePluginRow
|
||||
|
||||
|
@ -39,20 +39,42 @@ class GradiencePluginsList:
|
|||
|
||||
self.check_if_plugin_dir_exists()
|
||||
|
||||
self.pm = PluginManager()
|
||||
self.app = self.win.get_application()
|
||||
self.enabled_plugins = set(
|
||||
self.app.settings.get_value("enabled-plugins").unpack()
|
||||
)
|
||||
self.rows = {}
|
||||
|
||||
self.reload()
|
||||
|
||||
def reload(self):
|
||||
self.pm = PluginManager()
|
||||
self.pm.setPluginPlaces(
|
||||
[
|
||||
USER_PLUGIN_DIR,
|
||||
]
|
||||
)
|
||||
self.pm.collectPlugins()
|
||||
self.rows = {}
|
||||
|
||||
for pluginInfo in self.pm.getAllPlugins():
|
||||
pluginInfo.plugin_object.activate()
|
||||
|
||||
self.app = self.win.get_application()
|
||||
self.enabled_plugins = set(
|
||||
self.app.settings.get_value("enabled-plugins").unpack()
|
||||
)
|
||||
|
||||
def save_enabled_plugins(self):
|
||||
self.app.settings.set_value(
|
||||
"enabled-plugins", GLib.Variant("as", list(self.enabled_plugins))
|
||||
)
|
||||
|
||||
def enable_plugin(self, plugin_id):
|
||||
self.enabled_plugins.add(plugin_id)
|
||||
self.save_enabled_plugins()
|
||||
|
||||
def disable_plugin(self, plugin_id):
|
||||
self.enabled_plugins.remove(plugin_id)
|
||||
self.save_enabled_plugins()
|
||||
|
||||
@staticmethod
|
||||
def check_if_plugin_dir_exists():
|
||||
|
@ -77,7 +99,8 @@ class GradiencePluginsList:
|
|||
)
|
||||
if self.pm:
|
||||
for pluginInfo in self.pm.getAllPlugins():
|
||||
row = GradiencePluginRow(pluginInfo.plugin_object, preset)
|
||||
row = GradiencePluginRow(
|
||||
pluginInfo.plugin_object, preset, self)
|
||||
self.rows[pluginInfo.plugin_object.plugin_id] = row
|
||||
group.add(row)
|
||||
else:
|
||||
|
@ -102,4 +125,5 @@ class GradiencePluginsList:
|
|||
|
||||
def apply(self):
|
||||
for pluginInfo in self.pm.getAllPlugins():
|
||||
pluginInfo.plugin_object.apply()
|
||||
if pluginInfo.plugin_object.plugin_id in self.enabled_plugins:
|
||||
pluginInfo.plugin_object.apply()
|
||||
|
|
Loading…
Reference in a new issue