mirror of
https://github.com/GradienceTeam/Gradience.git
synced 2024-07-08 03:57:48 +00:00
add plugin class
This commit is contained in:
parent
188b810d32
commit
720c93c9f7
|
@ -43,7 +43,7 @@ from .palette_shades import AdwcustomizerPaletteShades
|
||||||
from .option import AdwcustomizerOption
|
from .option import AdwcustomizerOption
|
||||||
from .app_type_dialog import AdwcustomizerAppTypeDialog
|
from .app_type_dialog import AdwcustomizerAppTypeDialog
|
||||||
from .custom_css_group import AdwcustomizerCustomCSSGroup
|
from .custom_css_group import AdwcustomizerCustomCSSGroup
|
||||||
|
from .plugins_list import AdwcustomizerPluginsList
|
||||||
|
|
||||||
def to_slug_case(non_slug):
|
def to_slug_case(non_slug):
|
||||||
return re.sub(r"[^0-9a-z]+", "-", anyascii(non_slug).lower()).strip("-")
|
return re.sub(r"[^0-9a-z]+", "-", anyascii(non_slug).lower()).strip("-")
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
pkgdatadir = join_paths(get_option('prefix'), get_option('datadir'), meson.project_name())
|
pkgdatadir = join_paths(get_option('prefix'), get_option('datadir'), meson.project_name())
|
||||||
moduledir = join_paths(pkgdatadir, 'adwcustomizer')
|
moduledir = join_paths(pkgdatadir, 'adwcustomizer')
|
||||||
|
pluginsdir = join_paths(pkgdatadir, 'adwcustomizer', 'plugins')
|
||||||
gnome = import('gnome')
|
gnome = import('gnome')
|
||||||
|
|
||||||
blueprints = custom_target('blueprints',
|
blueprints = custom_target('blueprints',
|
||||||
|
@ -45,10 +46,19 @@ adwcustomizer_sources = [
|
||||||
'main.py',
|
'main.py',
|
||||||
'error.py',
|
'error.py',
|
||||||
'palette_shades.py',
|
'palette_shades.py',
|
||||||
|
'plugin.py',
|
||||||
|
'plugins_list.py',
|
||||||
|
'setting.py',
|
||||||
'option.py',
|
'option.py',
|
||||||
'window.py',
|
'window.py',
|
||||||
'app_type_dialog.py',
|
'app_type_dialog.py',
|
||||||
'custom_css_group.py',
|
'custom_css_group.py',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
plugins_sources = [
|
||||||
|
'plugins/__init__.py',
|
||||||
|
'plugins/gtk4.py'
|
||||||
|
]
|
||||||
|
|
||||||
install_data(adwcustomizer_sources, install_dir: moduledir)
|
install_data(adwcustomizer_sources, install_dir: moduledir)
|
||||||
|
install_data(plugins_sources, install_dir: pluginsdir)
|
41
src/plugin.py
Normal file
41
src/plugin.py
Normal 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
0
src/plugins/__init__.py
Normal file
4
src/plugins/gtk4.py
Normal file
4
src/plugins/gtk4.py
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
from adwcustomizer.plugin import AdwcustomizerPlugin
|
||||||
|
|
||||||
|
class AdwcustomizerGtk4Plugin(AdwcustomizerPlugin):
|
||||||
|
pass
|
16
src/plugins_list.py
Normal file
16
src/plugins_list.py
Normal 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
19
src/setting.py
Normal 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
|
Loading…
Reference in a new issue