Gradience/src/plugins_list.py

70 lines
2.3 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/>.
2022-08-10 16:24:28 +00:00
import os
from pathlib import Path
import importlib
2022-08-13 16:30:41 +00:00
import pkgutil
2022-08-19 12:44:02 +00:00
from .plugin_row import GradiencePluginRow
from gi.repository import Gtk, Adw, Gio, Gdk
2022-08-11 16:39:52 +00:00
2022-08-19 13:06:34 +00:00
import sys
2022-08-17 21:35:59 +00:00
2022-08-19 12:32:02 +00:00
class GradiencePluginsList:
2022-08-10 15:51:55 +00:00
def __init__(self):
2022-08-19 13:30:42 +00:00
2022-08-17 21:35:59 +00:00
self.discoverd_plugins = {
2022-08-13 16:30:41 +00:00
name: importlib.import_module(name)
for finder, name, ispkg
in pkgutil.iter_modules()
2022-08-19 12:32:02 +00:00
if name.startswith('gradience_')
2022-08-13 16:30:41 +00:00
}
2022-08-19 18:49:02 +00:00
self.rows = {}
2022-08-19 13:30:42 +00:00
self.plugins = {}
for plugin_id, plugin in self.discoverd_plugins.items():
2022-08-19 12:32:02 +00:00
self.plugins[plugin_id] = plugin.GradiencePlugin()
2022-08-10 16:24:28 +00:00
2022-08-13 16:30:41 +00:00
print(self.plugins)
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-08-19 13:30:42 +00:00
if self.plugins:
for plugin_id, plugin in self.plugins.items():
row = GradiencePluginRow(plugin.title, plugin_id)
2022-08-19 18:49:02 +00:00
self.rows[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