add plugin class

This commit is contained in:
0xMRTT 2022-08-10 17:51:55 +02:00
parent 188b810d32
commit 720c93c9f7
No known key found for this signature in database
GPG key ID: AC9E06BF3DECB6FB
7 changed files with 91 additions and 1 deletions

View file

@ -43,7 +43,7 @@ from .palette_shades import AdwcustomizerPaletteShades
from .option import AdwcustomizerOption
from .app_type_dialog import AdwcustomizerAppTypeDialog
from .custom_css_group import AdwcustomizerCustomCSSGroup
from .plugins_list import AdwcustomizerPluginsList
def to_slug_case(non_slug):
return re.sub(r"[^0-9a-z]+", "-", anyascii(non_slug).lower()).strip("-")

View file

@ -1,5 +1,6 @@
pkgdatadir = join_paths(get_option('prefix'), get_option('datadir'), meson.project_name())
moduledir = join_paths(pkgdatadir, 'adwcustomizer')
pluginsdir = join_paths(pkgdatadir, 'adwcustomizer', 'plugins')
gnome = import('gnome')
blueprints = custom_target('blueprints',
@ -45,10 +46,19 @@ adwcustomizer_sources = [
'main.py',
'error.py',
'palette_shades.py',
'plugin.py',
'plugins_list.py',
'setting.py',
'option.py',
'window.py',
'app_type_dialog.py',
'custom_css_group.py',
]
plugins_sources = [
'plugins/__init__.py',
'plugins/gtk4.py'
]
install_data(adwcustomizer_sources, install_dir: moduledir)
install_data(plugins_sources, install_dir: pluginsdir)

41
src/plugin.py Normal file
View file

@ -0,0 +1,41 @@
from .setting import AdwcustomizerSetting
class AdwcustomizerPlugin:
def __init__(self):
self.title = None
self.colors = None
self.palette = None
# Custom settings shown on a separate view
self.custom_settings = {}
# A dict to alias parameters to different names
# Key is the alias name, value is the parameter name
# Parameter can be any key in colors, palette or custom settings
self.alias_dict = {}
def update_builtin_parameters(self, colors, palette):
self.colors = colors
self.palette = palette
def load_custom_settings(self, settings):
for setting_key, setting in self.custom_settings:
self.custom_settings[setting_key].set_value(settings[setting_key])
def get_custom_settings_for_preset(self):
setting_dict = {}
for setting_key, setting in self.custom_settings:
setting_dict[setting_key] = setting.value
return setting_list
def get_alias_values(self):
alias_values = {}
for key, value in self.alias_dict.items():
alias_values[key] = self.colors.get(value, self.palette.get(value, self.custom_settings.get(value)))
return alias_values
def validate(self):
pass
def apply(self):
pass

0
src/plugins/__init__.py Normal file
View file

4
src/plugins/gtk4.py Normal file
View file

@ -0,0 +1,4 @@
from adwcustomizer.plugin import AdwcustomizerPlugin
class AdwcustomizerGtk4Plugin(AdwcustomizerPlugin):
pass

16
src/plugins_list.py Normal file
View file

@ -0,0 +1,16 @@
from .plugins.gtk4 import AdwcustomizerGtk4Plugin
class AdwcustomizerPluginsList:
def __init__(self):
self.plugins = {
"gtk4": AdwcustomizerGtk4Plugin()
}
def load_all_custom_settings(self, settings):
for plugin_id, plugin in self.plugins.items():
plugin.load_custom_settings(settings[plugin_id])
def get_all_custom_settings_for_preset(self):
custom_settings = {}
for plugin_id, plugin in self.plugins.items():
custom_settings[plugin_id] = plugin.get_custom_settings_for_preset()

19
src/setting.py Normal file
View file

@ -0,0 +1,19 @@
class AdwcustomizerSetting:
def __init__(self, name, title, value_type, explanation=None, default_value=None):
# TODO supported types:
# text
# integer
# float
# color only
# color shades
# color and text
# code field
self.name = name
self.title = title
self.value_type = value_type
self.explanation = explanation
self.value = default_value
def set_value(self, new_value):
# TODO checks
self.value = new_value