Gradience/src/plugins_list.py

82 lines
2.7 KiB
Python
Raw Normal View History

2022-08-11 08:16:44 +00:00
# plugins_list.py
#
# Change the look of Adwaita, with ease
# Copyright (C) 2022 Gradience Team
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/>.
import sys
2022-08-10 16:24:28 +00:00
import os
import importlib
2022-08-13 16:30:41 +00:00
import pkgutil
2022-08-19 12:44:02 +00:00
from gi.repository import Gtk, Adw, Gio, Gdk
2022-09-04 09:08:32 +00:00
from yapsy.PluginManager import PluginManager
2022-08-11 16:39:52 +00:00
from pathlib import Path
from .modules.utils import buglog
from .plugin_row import GradiencePluginRow
2022-09-02 19:37:52 +00:00
from .plugins.hookspec import GradienceHooks
2022-09-02 19:57:59 +00:00
from .constants import app_id
2022-08-19 13:06:34 +00:00
2022-08-17 21:35:59 +00:00
2022-08-19 12:32:02 +00:00
class GradiencePluginsList:
2022-09-01 14:06:04 +00:00
def __init__(self, win):
self.win = win
2022-09-04 09:08:32 +00:00
self.pm = PluginManager()
self.pm.setPluginPlaces([os.path.join(
os.environ.get("XDG_CONFIG_HOME",
os.environ["HOME"] + "/.config"),
"gradience_plugins",
)])
self.pm.collectPlugins()
self.rows = {}
for pluginInfo in self.pm.getAllPlugins():
pluginInfo.plugin_object.activate()
2022-09-01 14:11:14 +00:00
2022-08-10 16:24:28 +00:00
2022-08-10 15:51:55 +00:00
def load_all_custom_settings(self, settings):
for plugin_id, plugin in self.plugins.items():
2022-08-13 16:30:41 +00:00
plugin.load_custom_settings(settings)
2022-08-10 15:51:55 +00:00
def get_all_custom_settings_for_preset(self):
custom_settings = {}
for plugin_id, plugin in self.plugins.items():
2022-08-11 16:39:52 +00:00
custom_settings[plugin_id] = plugin.get_custom_settings_for_preset()
2022-08-19 12:44:02 +00:00
def to_group(self):
group = Adw.PreferencesGroup()
group.set_title(_("Plugins"))
2022-08-19 12:45:50 +00:00
group.set_description(
_("Plugins add additional features to Gradience, plugins are made by Gradience community and can make issues."))
2022-09-04 09:08:32 +00:00
if self.pm:
for pluginInfo in self.pm.getAllPlugins():
row = GradiencePluginRow( pluginInfo.plugin_object)
self.rows[ pluginInfo.plugin_object.plugin_id] = row
2022-08-19 13:30:42 +00:00
group.add(row)
2022-08-19 12:44:02 +00:00
else:
row = Adw.ActionRow()
row.set_title(_("No plugins found"))
group.add(row)
return group
2022-09-04 09:08:32 +00:00
def save(self):
saved = {}
for pluginInfo in self.pm.getAllPlugins():
saved[pluginInfo.plugin_object.plugin_id] = pluginInfo.plugin_object.save()
return saved