Merge branch 'main' into prefs-window

This commit is contained in:
tfuxu 2022-09-01 16:03:27 +00:00 committed by GitHub
commit 1541f60064
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 276 additions and 38 deletions

View file

@ -5,8 +5,13 @@ Fork this repository, then create a push request when you're done adding feature
### Localisation
We use Weblate for Gradience
[![Translations](https://hosted.weblate.org/widgets/GradienceTeam/-/multi-auto.svg)](https://hosted.weblate.org/engage/GradienceTeam)
And we use Crowdin for the website
[![Crowdin](https://badges.crowdin.net/gradience/localized.svg)](https://crowdin.com/project/gradience)
## Contributors ✨

View file

@ -16,7 +16,7 @@
<key name="first-run" type="b">
<default>true</default>
</key>
<key name="disabled-plugins" type="as">
<key name="enabled-plugins" type="as">
<default>[]</default>
</key>
<key name="user-flatpak-theming" type="b">

View file

@ -118,6 +118,10 @@ template GradienceMainWindow : Adw.ApplicationWindow {
menu main-menu {
section {
item {
label: _("Restore Applied Color Scheme");
action: "app.restore_color_scheme";
}
item {
label: _("Reset Applied Color Scheme");
action: "app.reset_color_scheme";

View file

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-09-01 00:42+0000\n"
"POT-Creation-Date: 2022-09-01 12:15+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -234,7 +234,7 @@ msgid ""
msgstr ""
#: data/ui/welcome.blp:79
msgid "Configure themes"
msgid "Configure Themes"
msgstr ""
#: data/ui/welcome.blp:80
@ -245,43 +245,43 @@ msgstr ""
msgid "adw-gtk3 theme"
msgstr ""
#: data/ui/welcome.blp:89 data/ui/welcome.blp:99
#: data/ui/welcome.blp:90 data/ui/welcome.blp:101
msgid "Allow installation"
msgstr ""
#: data/ui/welcome.blp:94
msgid "System configuration"
#: data/ui/welcome.blp:95
msgid "System Configuration"
msgstr ""
#: data/ui/welcome.blp:109
msgid "Installing themes"
#: data/ui/welcome.blp:111
msgid "Installing Themes"
msgstr ""
#: data/ui/welcome.blp:110
msgid "Please wait until themes will be installed. "
#: data/ui/welcome.blp:112
msgid "Please wait until themes will be installed."
msgstr ""
#: data/ui/welcome.blp:116
#: data/ui/welcome.blp:118
msgid "Continue"
msgstr ""
#: data/ui/welcome.blp:135
#: data/ui/welcome.blp:137
msgid "Done"
msgstr ""
#: data/ui/welcome.blp:136
#: data/ui/welcome.blp:138
msgid "Now you can make your own presets, or download some online."
msgstr ""
#: data/ui/welcome.blp:141
#: data/ui/welcome.blp:143
msgid "Please Finish the setup first"
msgstr ""
#: data/ui/welcome.blp:149
#: data/ui/welcome.blp:151
msgid "Start using Gradience"
msgstr ""
#: data/ui/welcome.blp:166
#: data/ui/welcome.blp:168
msgid "Next"
msgstr ""

View file

@ -4,6 +4,7 @@ de
en_US
es
fr
hr
it
nl
oc
@ -13,4 +14,3 @@ ru
sv
tr
zh_Hans
hr

117
pypi-dependencies.json Normal file
View file

@ -0,0 +1,117 @@
{
"name": "pypi-dependencies",
"buildsystem": "simple",
"build-commands": [],
"modules": [
{
"name": "python3-anyascii",
"buildsystem": "simple",
"build-commands": [
"pip3 install --verbose --exists-action=i --no-index --find-links=\"file://${PWD}\" --prefix=${FLATPAK_DEST} \"anyascii~=0.3\" --no-build-isolation"
],
"sources": [
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/39/f6/7c1e3a2a54f18b67c5bd092c25ac7327083d4b3b15731b98a9c193df2db9/anyascii-0.3.1-py3-none-any.whl",
"sha256": "8707d3185017435933360462a65e2c70a4818490745804f38a5ca55e59eb56a0"
}
]
},
{
"name": "python3-material-color-utilities-python",
"buildsystem": "simple",
"build-commands": [
"pip3 install --verbose --exists-action=i --no-index --find-links=\"file://${PWD}\" --prefix=${FLATPAK_DEST} \"material-color-utilities-python\" --no-build-isolation"
],
"sources": [
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/f7/e1/8b46ff54516faea4ea9469c4f5b50f2e9e73131f54d19e6827141698a822/regex-2022.8.17.tar.gz",
"sha256": "5c77eab46f3a2b2cd8bbe06467df783543bf7396df431eb4a144cc4b89e9fb3c"
},
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/8c/92/2975b464d9926dc667020ed1abfa6276e68c3571dcb77e43347e15ee9eed/Pillow-9.2.0.tar.gz",
"sha256": "75e636fd3e0fb872693f23ccb8a5ff2cd578801251f3a4f6854c6a5d437d3c04"
},
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/31/65/a8e0f3e2bad0d4eabeb1931b22cdae08344a955f28022dc83420a128683c/material_color_utilities_python-0.1.5-py2.py3-none-any.whl",
"sha256": "48abd8695a1355ab3ad43fe314ca8664c66282a86fbf94a717571273bf422bdf"
}
]
},
{
"name": "python3-urllib3",
"buildsystem": "simple",
"build-commands": [
"pip3 install --verbose --exists-action=i --no-index --find-links=\"file://${PWD}\" --prefix=${FLATPAK_DEST} \"urllib3\" --no-build-isolation"
],
"sources": [
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/6f/de/5be2e3eed8426f871b170663333a0f627fc2924cc386cd41be065e7ea870/urllib3-1.26.12-py2.py3-none-any.whl",
"sha256": "b930dd878d5a8afb066a637fbb35144fe7901e3b209d1cd4f524bd0e9deee997"
}
]
},
{
"name": "python3-svglib",
"buildsystem": "simple",
"build-commands": [
"pip3 install --verbose --exists-action=i --no-index --find-links=\"file://${PWD}\" --prefix=${FLATPAK_DEST} \"svglib\" --no-build-isolation"
],
"sources": [
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/f4/24/2a3e3df732393fed8b3ebf2ec078f05546de641fe1b667ee316ec1dcf3b7/webencodings-0.5.1-py2.py3-none-any.whl",
"sha256": "a0af1213f3c2226497a97e2b3aa01a7e4bee4f403f95be16fc9acd2947514a78"
},
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/8c/92/2975b464d9926dc667020ed1abfa6276e68c3571dcb77e43347e15ee9eed/Pillow-9.2.0.tar.gz",
"sha256": "75e636fd3e0fb872693f23ccb8a5ff2cd578801251f3a4f6854c6a5d437d3c04"
},
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/a6/d0/bdee3e8a7ba5f2dc8bacea10f4fdd1264b1dd9e53d96d318773180634a00/reportlab-3.6.11.tar.gz",
"sha256": "04fc4420f0548815d0623e031c86a1f7f3f3003e699d9af7148742e2d72b024a"
},
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/70/bb/7a2c7b4f8f434aa1ee801704bf08f1e53d7b5feba3d5313ab17003477808/lxml-4.9.1.tar.gz",
"sha256": "fe749b052bb7233fe5d072fcb549221a8cb1a16725c47c37e42b0b9cb3ff2c3f"
},
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/53/7b/5dba39bf0572f1f28e2844f08f74a73482a381de1d1feac3bbc6b808051e/tinycss2-1.1.1-py3-none-any.whl",
"sha256": "fe794ceaadfe3cf3e686b22155d0da5780dd0e273471a51846d0a02bc204fec8"
},
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/e4/40/98fcfdf1a190aa0aeddf2fd0a432a4997c2c1f826f3f7b00fe42fc72c8ce/cssselect2-0.6.0-py3-none-any.whl",
"sha256": "3a83b2a68370c69c9cd3fcb88bbfaebe9d22edeef2c22d1ff3e1ed9c7fa45ed8"
},
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/ee/cd/8b19f6299541862deea19b26a9efe269ff843fa15a9fd833ff0fec2ac22c/svglib-1.4.1.tar.gz",
"sha256": "48c24706c23bb4262173b6fa49eabb10afa15b8412f14283120549517ccfa314"
}
]
},
{
"name": "python3-pluggy",
"buildsystem": "simple",
"build-commands": [
"pip3 install --verbose --exists-action=i --no-index --find-links=\"file://${PWD}\" --prefix=${FLATPAK_DEST} \"pluggy\" --no-build-isolation"
],
"sources": [
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/9e/01/f38e2ff29715251cf25532b9082a1589ab7e4f571ced434f98d0139336dc/pluggy-1.0.0-py2.py3-none-any.whl",
"sha256": "74134bbf457f031a36d68416e1509f34bd5ccc019f0bcc952c7b909d06b37bd3"
}
]
}
]
}

View file

@ -26,3 +26,4 @@ anyascii~=0.3
material-color-utilities-python
urllib3
svglib
pluggy

View file

@ -113,6 +113,10 @@ class GradienceApplication(Adw.Application):
"show_gtk4_demo",
self.show_gtk4_demo)
self.create_action(
"restore_color_scheme",
self.show_restore_color_scheme_dialog)
self.create_action(
"reset_color_scheme",
self.show_reset_color_scheme_dialog)
@ -415,6 +419,18 @@ class GradienceApplication(Adw.Application):
dialog.connect("response", self.apply_color_scheme)
dialog.present()
def show_restore_color_scheme_dialog(self, *_args):
dialog = GradienceAppTypeDialog(
_("Restore applied color scheme?"),
_("Make sure you have the current settings saved as a preset."),
"restore",
_("Restore"),
Adw.ResponseAppearance.DESTRUCTIVE,
transient_for=self.props.active_window,
)
dialog.connect("response", self.restore_color_scheme)
dialog.present()
def show_reset_color_scheme_dialog(self, *_args):
dialog = GradienceAppTypeDialog(
_("Reset applied color scheme?"),
@ -560,10 +576,24 @@ class GradienceApplication(Adw.Application):
if not os.path.exists(gtk4_dir):
os.makedirs(gtk4_dir)
gtk4_css = self.generate_gtk_css("gtk4")
with open(
os.path.join(gtk4_dir, "gtk.css"), "w", encoding="utf-8"
) as file:
file.write(gtk4_css)
contents = ""
try:
with open(
os.path.join(gtk4_dir, "gtk.css"), "r", encoding="utf-8"
) as file:
contents = file.read()
except FileNotFoundError: # first run
pass
else:
with open(
os.path.join(gtk4_dir, "gtk.css.bak"), "w", encoding="utf-8"
) as file:
file.write(contents)
finally:
with open(
os.path.join(gtk4_dir, "gtk.css"), "w", encoding="utf-8"
) as file:
file.write(gtk4_css)
if widget.get_app_types()["gtk3"]:
gtk3_dir = os.path.join(
os.environ.get(
@ -574,14 +604,72 @@ class GradienceApplication(Adw.Application):
if not os.path.exists(gtk3_dir):
os.makedirs(gtk3_dir)
gtk3_css = self.generate_gtk_css("gtk3")
with open(
os.path.join(gtk3_dir, "gtk.css"), "w", encoding="utf-8"
) as file:
file.write(gtk3_css)
contents = ""
try:
with open(
os.path.join(gtk3_dir, "gtk.css"), "r", encoding="utf-8"
) as file:
contents = file.read()
except FileNotFoundError: # first run
pass
else:
with open(
os.path.join(gtk3_dir, "gtk.css.bak"), "w", encoding="utf-8"
) as file:
file.write(contents)
finally:
with open(
os.path.join(gtk3_dir, "gtk.css"), "w", encoding="utf-8"
) as file:
file.write(gtk3_css)
self.win.toast_overlay.add_toast(
Adw.Toast(title=_("Preset set sucessfully"))
)
def restore_color_scheme(self, widget, response):
if response == "restore":
if widget.get_app_types()["gtk4"]:
file = Gio.File.new_for_path(
os.path.join(
os.environ.get(
"XDG_CONFIG_HOME", os.environ["HOME"] + "/.config"
),
"gtk-4.0/gtk.css.bak",
)
)
try:
backup = open(
os.path.join(
os.environ.get(
"XDG_CONFIG_HOME",
os.environ["HOME"] +
"/.config"),
"gtk-4.0/gtk.css.bak",
),
"r",
encoding="utf-8",
)
contents = backup.read()
backup.close()
gtk4css = open(
os.path.join(
os.environ.get(
"XDG_CONFIG_HOME",
os.environ["HOME"] +
"/.config"),
"gtk-4.0/gtk.css",
),
"w",
encoding="utf-8",
)
gtk4css.write(contents)
gtk4css.close()
except FileNotFoundError:
self.win.toast_overlay.add_toast(
Adw.Toast(title=_("Could not restore GTK4 backup"))
)
pass
def reset_color_scheme(self, widget, response):
if response == "reset":
if widget.get_app_types()["gtk4"]:

View file

@ -65,3 +65,10 @@ gradience_modules = [
]
PY_INSTALLDIR.install_sources(gradience_modules, subdir: 'gradience/modules')
gradience_plugins = [
'plugins/hookspec.py',
'plugins/__init__.py',
]
PY_INSTALLDIR.install_sources(gradience_plugins, subdir: 'gradience/plugins')

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

20
src/plugins/hookspec.py Normal file
View file

@ -0,0 +1,20 @@
import pluggy
hookspec = pluggy.HookspecMarker("gradience")
class GradienceHooks:
@hookspec
def validate(msg):
"validate hook"
pass
@hookspec
def apply(msg):
"apply hook"
pass
@hookspec
def save(msg):
"save hook"
pass

View file

@ -22,29 +22,25 @@ import importlib
import pkgutil
from gi.repository import Gtk, Adw, Gio, Gdk
import pluggy
from pathlib import Path
from .modules.utils import buglog
from .plugin_row import GradiencePluginRow
from plugins.hookspec import GradienceHooks
class GradiencePluginsList:
def __init__(self):
def __init__(self, win):
self.discoverd_plugins = {
name: importlib.import_module(name)
for finder, name, ispkg
in pkgutil.iter_modules()
if name.startswith('gradience_')
}
self.rows = {}
self.plugins = {}
for plugin_id, plugin in self.discoverd_plugins.items():
self.plugins[plugin_id] = plugin.GradiencePlugin()
self.win = win
self.plugins = win.settings.get_list("plugins-enabled")
buglog(self.plugins)
self.pm = pluggy.PluginManager("gradience")
self.pm.add_hookspecs(GradienceHooks)
def load_all_custom_settings(self, settings):
for plugin_id, plugin in self.plugins.items():
plugin.load_custom_settings(settings)

View file

@ -253,7 +253,7 @@ class GradienceMainWindow(Adw.ApplicationWindow):
)
def setup_plugins_page(self):
self.plugins_list = GradiencePluginsList()
self.plugins_list = GradiencePluginsList(self)
self.plugins_group = self.plugins_list.to_group()
self.content_plugins.add(self.plugins_group)