mirror of
https://github.com/GradienceTeam/Gradience.git
synced 2024-08-29 18:32:32 +00:00
Format code with black and autopep8 (#350)
This commit is contained in:
commit
bb433ffa69
19 changed files with 388 additions and 355 deletions
|
@ -37,7 +37,7 @@ class GradienceAppTypeDialog(Adw.MessageDialog):
|
|||
ok_response_name,
|
||||
ok_response_label,
|
||||
ok_response_appearance,
|
||||
**kwargs
|
||||
**kwargs,
|
||||
):
|
||||
super().__init__(**kwargs)
|
||||
self.set_heading(heading)
|
||||
|
|
|
@ -32,6 +32,5 @@ class GradienceBuiltinPresetRow(Adw.ActionRow):
|
|||
buglog("apply")
|
||||
|
||||
self.app.load_preset_from_resource(
|
||||
f"{rootdir}/presets/"
|
||||
+ to_slug_case(self.name) + ".json"
|
||||
f"{rootdir}/presets/" + to_slug_case(self.name) + ".json"
|
||||
)
|
||||
|
|
|
@ -35,14 +35,16 @@ class GradienceCustomCSSGroup(Adw.PreferencesGroup):
|
|||
def load_custom_css(self, custom_css):
|
||||
self.custom_css = custom_css
|
||||
self.custom_css_text_view.get_buffer().set_text(
|
||||
list(self.custom_css.values())[self.app_type_dropdown.get_selected()]
|
||||
list(self.custom_css.values())[
|
||||
self.app_type_dropdown.get_selected()]
|
||||
)
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
def on_custom_css_changed(self, buffer):
|
||||
Gtk.Application.get_default().mark_as_dirty()
|
||||
Gtk.Application.get_default().update_custom_css_text(
|
||||
list(self.custom_css.keys())[self.app_type_dropdown.get_selected()],
|
||||
list(self.custom_css.keys())[
|
||||
self.app_type_dropdown.get_selected()],
|
||||
buffer.props.text,
|
||||
)
|
||||
|
||||
|
@ -50,5 +52,6 @@ class GradienceCustomCSSGroup(Adw.PreferencesGroup):
|
|||
def on_dropdown_notify(self, _unused, pspec):
|
||||
if pspec.name == "selected":
|
||||
self.custom_css_text_view.get_buffer().set_text(
|
||||
list(self.custom_css.values())[self.app_type_dropdown.get_selected()]
|
||||
list(self.custom_css.values())[
|
||||
self.app_type_dropdown.get_selected()]
|
||||
)
|
||||
|
|
|
@ -60,17 +60,18 @@ class GradienceExplorePresetRow(Adw.ActionRow):
|
|||
)
|
||||
buglog(exception)
|
||||
else:
|
||||
self.app.load_preset_from_file(os.path.join(
|
||||
os.environ.get("XDG_CONFIG_HOME",
|
||||
os.environ["HOME"] + "/.config"),
|
||||
"presets",
|
||||
self.prefix,
|
||||
to_slug_case(self.name) + ".json",
|
||||
))
|
||||
self.app.load_preset_from_file(
|
||||
os.path.join(
|
||||
os.environ.get("XDG_CONFIG_HOME",
|
||||
os.environ["HOME"] + "/.config"),
|
||||
"presets",
|
||||
self.prefix,
|
||||
to_slug_case(self.name) + ".json",
|
||||
)
|
||||
)
|
||||
|
||||
self.toast_overlay.add_toast(
|
||||
Adw.Toast(title=_("Preset downloaded"))
|
||||
)
|
||||
Adw.Toast(title=_("Preset downloaded")))
|
||||
self.win.reload_pref_group()
|
||||
|
||||
buglog("Apply and download compeleted")
|
||||
|
@ -86,7 +87,6 @@ class GradienceExplorePresetRow(Adw.ActionRow):
|
|||
buglog(exception)
|
||||
else:
|
||||
self.toast_overlay.add_toast(
|
||||
Adw.Toast(title=_("Preset downloaded"))
|
||||
)
|
||||
Adw.Toast(title=_("Preset downloaded")))
|
||||
self.win.reload_pref_group()
|
||||
buglog("Download compeleted")
|
||||
|
|
181
src/main.py
181
src/main.py
|
@ -31,7 +31,15 @@ from .palette_shades import GradiencePaletteShades
|
|||
from .option import GradienceOption
|
||||
from .app_type_dialog import GradienceAppTypeDialog
|
||||
from .custom_css_group import GradienceCustomCSSGroup
|
||||
from .constants import rootdir, app_id, rel_ver, version, bugtracker_url, help_url, project_url
|
||||
from .constants import (
|
||||
rootdir,
|
||||
app_id,
|
||||
rel_ver,
|
||||
version,
|
||||
bugtracker_url,
|
||||
help_url,
|
||||
project_url,
|
||||
)
|
||||
from .welcome import GradienceWelcomeWindow
|
||||
from .preferences import GradiencePreferencesWindow
|
||||
from .modules.utils import to_slug_case, buglog
|
||||
|
@ -40,15 +48,13 @@ from .plugins_list import GradiencePluginsList
|
|||
|
||||
class GradienceApplication(Adw.Application):
|
||||
"""The main application singleton class."""
|
||||
|
||||
__gtype_name__ = "GradienceApplication"
|
||||
|
||||
settings = Gio.Settings.new(app_id)
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(
|
||||
application_id=app_id,
|
||||
flags=Gio.ApplicationFlags.FLAGS_NONE
|
||||
)
|
||||
super().__init__(application_id=app_id, flags=Gio.ApplicationFlags.FLAGS_NONE)
|
||||
self.set_resource_base_path(rootdir)
|
||||
|
||||
self.portal = Xdp.Portal()
|
||||
|
@ -95,41 +101,31 @@ class GradienceApplication(Adw.Application):
|
|||
GLib.Variant("s", "adwaita"),
|
||||
self.load_preset_action,
|
||||
)
|
||||
self.create_action(
|
||||
"apply_color_scheme",
|
||||
self.show_apply_color_scheme_dialog)
|
||||
self.create_action("apply_color_scheme",
|
||||
self.show_apply_color_scheme_dialog)
|
||||
|
||||
self.create_action("show_adwaita_demo", self.show_adwaita_demo)
|
||||
|
||||
self.create_action("show_gtk4_widget_factory",
|
||||
self.show_gtk4_widget_factory)
|
||||
|
||||
self.create_action("show_gtk4_demo", self.show_gtk4_demo)
|
||||
|
||||
self.create_action(
|
||||
"show_adwaita_demo",
|
||||
self.show_adwaita_demo)
|
||||
"restore_color_scheme", self.show_restore_color_scheme_dialog
|
||||
)
|
||||
|
||||
self.create_action(
|
||||
"show_gtk4_widget_factory",
|
||||
self.show_gtk4_widget_factory)
|
||||
|
||||
self.create_action(
|
||||
"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)
|
||||
self.create_action("reset_color_scheme",
|
||||
self.show_reset_color_scheme_dialog)
|
||||
self.create_action("preferences", self.show_preferences)
|
||||
self.create_action("save_preset", self.show_save_preset_dialog)
|
||||
self.create_action("about", self.show_about_window)
|
||||
|
||||
if self.style_manager.get_dark():
|
||||
self.load_preset_from_resource(
|
||||
f"{rootdir}/presets/adwaita-dark.json"
|
||||
)
|
||||
f"{rootdir}/presets/adwaita-dark.json")
|
||||
else:
|
||||
self.load_preset_from_resource(
|
||||
f"{rootdir}/presets/adwaita.json"
|
||||
)
|
||||
self.load_preset_from_resource(f"{rootdir}/presets/adwaita.json")
|
||||
|
||||
if self.first_run:
|
||||
buglog("first run")
|
||||
|
@ -147,12 +143,10 @@ class GradienceApplication(Adw.Application):
|
|||
|
||||
self.portal.open_uri(
|
||||
parent,
|
||||
"file://" +
|
||||
os.path.join(
|
||||
os.environ.get(
|
||||
"XDG_CONFIG_HOME",
|
||||
os.environ["HOME"] +
|
||||
"/.config"),
|
||||
"file://"
|
||||
+ os.path.join(
|
||||
os.environ.get("XDG_CONFIG_HOME",
|
||||
os.environ["HOME"] + "/.config"),
|
||||
"presets",
|
||||
),
|
||||
Xdp.OpenUriFlags.NONE,
|
||||
|
@ -286,13 +280,17 @@ class GradienceApplication(Adw.Application):
|
|||
"window_fg_color": self.rgba_from_argb(light_theme.onSurface),
|
||||
"view_bg_color": self.rgba_from_argb(light_theme.secondaryContainer),
|
||||
"view_fg_color": self.rgba_from_argb(light_theme.onSurface),
|
||||
"headerbar_bg_color": self.rgba_from_argb(light_theme.secondaryContainer),
|
||||
"headerbar_bg_color": self.rgba_from_argb(
|
||||
light_theme.secondaryContainer
|
||||
),
|
||||
"headerbar_fg_color": self.rgba_from_argb(light_theme.onSurface),
|
||||
"headerbar_border_color": self.rgba_from_argb(
|
||||
light_theme.primary, "0.8"
|
||||
),
|
||||
"headerbar_backdrop_color": "@window_bg_color",
|
||||
"headerbar_shade_color": self.rgba_from_argb(light_theme.secondaryContainer),
|
||||
"headerbar_shade_color": self.rgba_from_argb(
|
||||
light_theme.secondaryContainer
|
||||
),
|
||||
"card_bg_color": self.rgba_from_argb(light_theme.primary, "0.05"),
|
||||
"card_fg_color": self.rgba_from_argb(light_theme.onSecondaryContainer),
|
||||
"card_shade_color": self.rgba_from_argb(light_theme.shadow),
|
||||
|
@ -331,8 +329,9 @@ class GradienceApplication(Adw.Application):
|
|||
)
|
||||
self.props.active_window.save_preset_button.add_css_class("warning")
|
||||
|
||||
self.props.active_window.save_preset_button.get_child(
|
||||
).set_tooltip_text(_("Unsaved changes"))
|
||||
self.props.active_window.save_preset_button.get_child().set_tooltip_text(
|
||||
_("Unsaved changes")
|
||||
)
|
||||
|
||||
def clear_dirty(self):
|
||||
self.is_dirty = False
|
||||
|
@ -341,8 +340,9 @@ class GradienceApplication(Adw.Application):
|
|||
)
|
||||
self.props.active_window.save_preset_button.remove_css_class("warning")
|
||||
self.props.active_window.save_preset_button.get_child().set_label("")
|
||||
self.props.active_window.save_preset_button.get_child(
|
||||
).set_tooltip_text(_("Save changes"))
|
||||
self.props.active_window.save_preset_button.get_child().set_tooltip_text(
|
||||
_("Save changes")
|
||||
)
|
||||
|
||||
def reload_variables(self):
|
||||
parsing_errors = []
|
||||
|
@ -385,29 +385,24 @@ class GradienceApplication(Adw.Application):
|
|||
if args[0].get_string().startswith("custom-"):
|
||||
self.load_preset_from_file(
|
||||
os.path.join(
|
||||
os.environ.get(
|
||||
"XDG_CONFIG_HOME",
|
||||
os.environ["HOME"] +
|
||||
"/.config"),
|
||||
os.environ.get("XDG_CONFIG_HOME",
|
||||
os.environ["HOME"] + "/.config"),
|
||||
"presets",
|
||||
args[0].get_string().replace(
|
||||
"custom-",
|
||||
"",
|
||||
1) +
|
||||
".json",
|
||||
))
|
||||
args[0].get_string().replace("custom-", "", 1) + ".json",
|
||||
)
|
||||
)
|
||||
else:
|
||||
self.load_preset_from_resource(
|
||||
f"{rootdir}/presets/"
|
||||
+ args[0].get_string()
|
||||
+ ".json"
|
||||
f"{rootdir}/presets/" + args[0].get_string() + ".json"
|
||||
)
|
||||
Gio.SimpleAction.set_state(self.lookup_action("load_preset"), args[0])
|
||||
|
||||
def show_apply_color_scheme_dialog(self, *_args):
|
||||
dialog = GradienceAppTypeDialog(
|
||||
_("Apply this color scheme?"),
|
||||
_("Warning: any custom CSS files for those app types will be irreversibly overwritten!"),
|
||||
_(
|
||||
"Warning: any custom CSS files for those app types will be irreversibly overwritten!"
|
||||
),
|
||||
"apply",
|
||||
_("Apply"),
|
||||
Adw.ResponseAppearance.SUGGESTED,
|
||||
|
@ -513,18 +508,23 @@ class GradienceApplication(Adw.Application):
|
|||
|
||||
def save_preset(self, _unused, response, entry):
|
||||
if response == "save":
|
||||
if not os.path.exists(os.path.join(
|
||||
os.environ.get("XDG_CONFIG_HOME",
|
||||
os.environ["HOME"] + "/.config"),
|
||||
"presets",
|
||||
"user",
|
||||
)):
|
||||
os.makedirs(os.path.join(
|
||||
if not os.path.exists(
|
||||
os.path.join(
|
||||
os.environ.get("XDG_CONFIG_HOME",
|
||||
os.environ["HOME"] + "/.config"),
|
||||
"presets",
|
||||
"user",
|
||||
))
|
||||
)
|
||||
):
|
||||
os.makedirs(
|
||||
os.path.join(
|
||||
os.environ.get(
|
||||
"XDG_CONFIG_HOME", os.environ["HOME"] + "/.config"
|
||||
),
|
||||
"presets",
|
||||
"user",
|
||||
)
|
||||
)
|
||||
|
||||
with open(
|
||||
os.path.join(
|
||||
|
@ -547,8 +547,7 @@ class GradienceApplication(Adw.Application):
|
|||
file.write(json.dumps(object_to_write, indent=4))
|
||||
self.clear_dirty()
|
||||
self.win.toast_overlay.add_toast(
|
||||
Adw.Toast(title=_("Preset saved"))
|
||||
)
|
||||
Adw.Toast(title=_("Preset saved")))
|
||||
|
||||
def apply_color_scheme(self, widget, response):
|
||||
if response == "apply":
|
||||
|
@ -584,9 +583,8 @@ class GradienceApplication(Adw.Application):
|
|||
# if widget.get_color_mode()["light"]:
|
||||
if widget.get_app_types()["gtk4"]:
|
||||
gtk4_dir = os.path.join(
|
||||
os.environ.get(
|
||||
"XDG_CONFIG_HOME", os.environ["HOME"] + "/.config"
|
||||
),
|
||||
os.environ.get("XDG_CONFIG_HOME",
|
||||
os.environ["HOME"] + "/.config"),
|
||||
"gtk-4.0",
|
||||
)
|
||||
if not os.path.exists(gtk4_dir):
|
||||
|
@ -595,14 +593,14 @@ class GradienceApplication(Adw.Application):
|
|||
contents = ""
|
||||
try:
|
||||
with open(
|
||||
os.path.join(gtk4_dir, "gtk.css"), "r", encoding="utf-8"
|
||||
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"
|
||||
os.path.join(gtk4_dir, "gtk.css.bak"), "w", encoding="utf-8"
|
||||
) as file:
|
||||
file.write(contents)
|
||||
finally:
|
||||
|
@ -612,9 +610,8 @@ class GradienceApplication(Adw.Application):
|
|||
file.write(gtk4_css)
|
||||
if widget.get_app_types()["gtk3"]:
|
||||
gtk3_dir = os.path.join(
|
||||
os.environ.get(
|
||||
"XDG_CONFIG_HOME", os.environ["HOME"] + "/.config"
|
||||
),
|
||||
os.environ.get("XDG_CONFIG_HOME",
|
||||
os.environ["HOME"] + "/.config"),
|
||||
"gtk-3.0",
|
||||
)
|
||||
if not os.path.exists(gtk3_dir):
|
||||
|
@ -623,14 +620,14 @@ class GradienceApplication(Adw.Application):
|
|||
contents = ""
|
||||
try:
|
||||
with open(
|
||||
os.path.join(gtk3_dir, "gtk.css"), "r", encoding="utf-8"
|
||||
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"
|
||||
os.path.join(gtk3_dir, "gtk.css.bak"), "w", encoding="utf-8"
|
||||
) as file:
|
||||
file.write(contents)
|
||||
finally:
|
||||
|
@ -657,9 +654,9 @@ class GradienceApplication(Adw.Application):
|
|||
backup = open(
|
||||
os.path.join(
|
||||
os.environ.get(
|
||||
"XDG_CONFIG_HOME",
|
||||
os.environ["HOME"] +
|
||||
"/.config"),
|
||||
"XDG_CONFIG_HOME", os.environ["HOME"] +
|
||||
"/.config"
|
||||
),
|
||||
"gtk-4.0/gtk.css.bak",
|
||||
),
|
||||
"r",
|
||||
|
@ -670,9 +667,9 @@ class GradienceApplication(Adw.Application):
|
|||
gtk4css = open(
|
||||
os.path.join(
|
||||
os.environ.get(
|
||||
"XDG_CONFIG_HOME",
|
||||
os.environ["HOME"] +
|
||||
"/.config"),
|
||||
"XDG_CONFIG_HOME", os.environ["HOME"] +
|
||||
"/.config"
|
||||
),
|
||||
"gtk-4.0/gtk.css",
|
||||
),
|
||||
"w",
|
||||
|
@ -737,9 +734,8 @@ class GradienceApplication(Adw.Application):
|
|||
"0xMRTT https://github.com/0xMRTT",
|
||||
"Verantor https://github.com/Verantor",
|
||||
],
|
||||
artists=['David Lapshin https://github.com/daudix-UFO'],
|
||||
designers=[
|
||||
'David Lapshin https://github.com/daudix-UFO'],
|
||||
artists=["David Lapshin https://github.com/daudix-UFO"],
|
||||
designers=["David Lapshin https://github.com/daudix-UFO"],
|
||||
# Translators: This is a place to put your credits (formats: "Name
|
||||
# https://example.com" or "Name <email@example.com>", no quotes)
|
||||
# and is not meant to be translated literally.
|
||||
|
@ -760,7 +756,8 @@ class GradienceApplication(Adw.Application):
|
|||
license_type=Gtk.License.GPL_3_0,
|
||||
version=version,
|
||||
release_notes_version=rel_ver,
|
||||
release_notes=_("""
|
||||
release_notes=_(
|
||||
"""
|
||||
<ul>
|
||||
<li>Add AdwViewSwitcher in the header bar.</li>
|
||||
<li>Move CSS to the "Advanced" tab</li>
|
||||
|
@ -777,8 +774,10 @@ class GradienceApplication(Adw.Application):
|
|||
<li>Added issue template for bug and feature request </li>
|
||||
<li>`Main` branch is now protected by GitHub branch protection. The development is done on `next` branch </li>
|
||||
</ul>
|
||||
"""),
|
||||
comments=_("""
|
||||
"""
|
||||
),
|
||||
comments=_(
|
||||
"""
|
||||
Gradience is a tool for customizing Libadwaita applications and the adw-gtk3 theme.
|
||||
With Gradience you can:
|
||||
|
||||
|
@ -789,7 +788,8 @@ With Gradience you can:
|
|||
- Extend functionality using plugins
|
||||
|
||||
This app is written in Python and uses GTK 4 and libadwaita.
|
||||
""")
|
||||
"""
|
||||
),
|
||||
)
|
||||
about.present()
|
||||
|
||||
|
@ -852,7 +852,8 @@ This app is written in Python and uses GTK 4 and libadwaita.
|
|||
|
||||
def show_gtk4_widget_factory(self, *_args):
|
||||
GLib.spawn_command_line_async(
|
||||
'sh -c "/bin/gtk4-widget-factory > /dev/null 2>&1"')
|
||||
'sh -c "/bin/gtk4-widget-factory > /dev/null 2>&1"'
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
|
|
|
@ -29,9 +29,7 @@ poolmgr = urllib3.PoolManager()
|
|||
|
||||
def fetch_presets(repo):
|
||||
try:
|
||||
http = poolmgr.request(
|
||||
"GET",
|
||||
repo)
|
||||
http = poolmgr.request("GET", repo)
|
||||
raw = json.loads(http.data)
|
||||
|
||||
preset_dict = {}
|
||||
|
@ -62,13 +60,16 @@ def download_preset(name, repo_name, url):
|
|||
|
||||
data = json.dumps(raw)
|
||||
|
||||
with open(os.path.join(
|
||||
with open(
|
||||
os.path.join(
|
||||
os.environ.get("XDG_CONFIG_HOME",
|
||||
os.environ["HOME"] + "/.config"),
|
||||
"presets",
|
||||
repo_name,
|
||||
to_slug_case(name) + ".json"),
|
||||
"w") as f:
|
||||
to_slug_case(name) + ".json",
|
||||
),
|
||||
"w",
|
||||
) as f:
|
||||
f.write(data)
|
||||
f.close()
|
||||
except Exception:
|
||||
|
|
|
@ -23,12 +23,16 @@ from gi.repository import GLib, Gio, Adw
|
|||
from .utils import buglog
|
||||
|
||||
|
||||
''' Custom exception class '''
|
||||
""" Custom exception class """
|
||||
|
||||
|
||||
class InvalidGTKVersion(Exception):
|
||||
pass
|
||||
|
||||
|
||||
''' Internal helper functions (shouldn't be used outside this file) '''
|
||||
""" Internal helper functions (shouldn't be used outside this file) """
|
||||
|
||||
|
||||
def get_system_flatpak_path():
|
||||
systemPath = GLib.getenv("FLATPAK_SYSTEM_DIR")
|
||||
buglog(f"systemPath: {systemPath}")
|
||||
|
@ -36,9 +40,7 @@ def get_system_flatpak_path():
|
|||
if systemPath:
|
||||
return systemPath
|
||||
|
||||
systemDataDir = GLib.build_filenamev([
|
||||
GLib.DIR_SEPARATOR_S, "var", "lib"
|
||||
])
|
||||
systemDataDir = GLib.build_filenamev([GLib.DIR_SEPARATOR_S, "var", "lib"])
|
||||
|
||||
return GLib.build_filenamev([systemDataDir, "flatpak"])
|
||||
|
||||
|
@ -50,19 +52,13 @@ def get_user_flatpak_path():
|
|||
if userPath:
|
||||
return userPath
|
||||
|
||||
userDataDir = GLib.build_filenamev([
|
||||
GLib.get_home_dir(), ".local", "share"
|
||||
])
|
||||
userDataDir = GLib.build_filenamev(
|
||||
[GLib.get_home_dir(), ".local", "share"])
|
||||
|
||||
return GLib.build_filenamev([userDataDir, "flatpak"])
|
||||
|
||||
|
||||
def user_save_keyfile(
|
||||
toast_overlay,
|
||||
settings,
|
||||
user_keyfile,
|
||||
filename,
|
||||
gtk_ver):
|
||||
def user_save_keyfile(toast_overlay, settings, user_keyfile, filename, gtk_ver):
|
||||
try:
|
||||
user_keyfile.save_to_file(filename)
|
||||
except Glib.GError as e:
|
||||
|
@ -72,19 +68,16 @@ def user_save_keyfile(
|
|||
if gtk_ver == "gtk4":
|
||||
settings.set_boolean("user-flatpak-theming-gtk4", True)
|
||||
buglog(
|
||||
f"user-flatpak-theming-gtk4: {settings.get_boolean('user-flatpak-theming-gtk4')}")
|
||||
f"user-flatpak-theming-gtk4: {settings.get_boolean('user-flatpak-theming-gtk4')}"
|
||||
)
|
||||
elif gtk_ver == "gtk3":
|
||||
settings.set_boolean("user-flatpak-theming-gtk3", True)
|
||||
buglog(
|
||||
f"user-flatpak-theming-gtk3: {settings.get_boolean('user-flatpak-theming-gtk3')}")
|
||||
f"user-flatpak-theming-gtk3: {settings.get_boolean('user-flatpak-theming-gtk3')}"
|
||||
)
|
||||
|
||||
|
||||
def global_save_keyfile(
|
||||
toast_overlay,
|
||||
settings,
|
||||
global_keyfile,
|
||||
filename,
|
||||
gtk_ver):
|
||||
def global_save_keyfile(toast_overlay, settings, global_keyfile, filename, gtk_ver):
|
||||
try:
|
||||
global_keyfile.save_to_file(filename)
|
||||
except Glib.GError as e:
|
||||
|
@ -94,23 +87,23 @@ def global_save_keyfile(
|
|||
if gtk_ver == "gtk4":
|
||||
settings.set_boolean("global-flatpak-theming-gtk4", True)
|
||||
buglog(
|
||||
f"global-flatpak-theming-gtk4: {settings.get_boolean('global-flatpak-theming-gtk4')}")
|
||||
f"global-flatpak-theming-gtk4: {settings.get_boolean('global-flatpak-theming-gtk4')}"
|
||||
)
|
||||
elif gtk_ver == "gtk3":
|
||||
settings.set_boolean("global-flatpak-theming-gtk3", True)
|
||||
buglog(
|
||||
f"global-flatpak-theming-gtk3: {settings.get_boolean('global-flatpak-theming-gtk3')}")
|
||||
f"global-flatpak-theming-gtk3: {settings.get_boolean('global-flatpak-theming-gtk3')}"
|
||||
)
|
||||
|
||||
|
||||
""" Main functions """
|
||||
|
||||
|
||||
''' Main functions '''
|
||||
def create_gtk_user_override(toast_overlay, settings, gtk_ver):
|
||||
override_dir = GLib.build_filenamev([
|
||||
get_user_flatpak_path(), "overrides"
|
||||
])
|
||||
override_dir = GLib.build_filenamev([get_user_flatpak_path(), "overrides"])
|
||||
print(f"override_dir: {override_dir}")
|
||||
|
||||
filename = GLib.build_filenamev([
|
||||
override_dir, "global"
|
||||
])
|
||||
filename = GLib.build_filenamev([override_dir, "global"])
|
||||
|
||||
user_keyfile = GLib.KeyFile.new()
|
||||
|
||||
|
@ -122,7 +115,8 @@ def create_gtk_user_override(toast_overlay, settings, gtk_ver):
|
|||
gtk_path = "xdg-config/gtk-3.0"
|
||||
else:
|
||||
raise InvalidGTKVersion(
|
||||
f"Invalid GTK version chosen: {gtk_ver}. Please choose between two options: gtk4, gtk3")
|
||||
f"Invalid GTK version chosen: {gtk_ver}. Please choose between two options: gtk4, gtk3"
|
||||
)
|
||||
|
||||
try:
|
||||
user_keyfile.load_from_file(filename, GLib.KeyFileFlags.NONE)
|
||||
|
@ -151,12 +145,12 @@ def create_gtk_user_override(toast_overlay, settings, gtk_ver):
|
|||
user_keyfile.load_from_file(filename, GLib.KeyFileFlags.NONE)
|
||||
user_keyfile.set_string("Context", "filesystems", gtk_path)
|
||||
|
||||
user_save_keyfile(
|
||||
toast_overlay, settings, user_keyfile, filename, gtk_ver)
|
||||
user_save_keyfile(toast_overlay, settings,
|
||||
user_keyfile, filename, gtk_ver)
|
||||
else:
|
||||
toast_overlay.add_toast(
|
||||
Adw.Toast(
|
||||
title=_("Unexpected file error occurred")))
|
||||
Adw.Toast(title=_("Unexpected file error occurred"))
|
||||
)
|
||||
buglog(f"Unhandled GLib.FileError error code. Exc: {e}")
|
||||
else:
|
||||
try:
|
||||
|
@ -164,14 +158,16 @@ def create_gtk_user_override(toast_overlay, settings, gtk_ver):
|
|||
"Context", "filesystems")
|
||||
except GLib.GError:
|
||||
user_keyfile.set_string("Context", "filesystems", gtk_path)
|
||||
user_save_keyfile(
|
||||
toast_overlay, settings, user_keyfile, filename, gtk_ver)
|
||||
user_save_keyfile(toast_overlay, settings,
|
||||
user_keyfile, filename, gtk_ver)
|
||||
else:
|
||||
if gtk_path not in filesys_list:
|
||||
user_keyfile.set_string_list(
|
||||
"Context", "filesystems", filesys_list + [gtk_path])
|
||||
"Context", "filesystems", filesys_list + [gtk_path]
|
||||
)
|
||||
user_save_keyfile(
|
||||
toast_overlay, settings, user_keyfile, filename, gtk_ver)
|
||||
toast_overlay, settings, user_keyfile, filename, gtk_ver
|
||||
)
|
||||
else:
|
||||
if is_gtk4:
|
||||
settings.set_boolean("user-flatpak-theming-gtk4", True)
|
||||
|
@ -181,14 +177,10 @@ def create_gtk_user_override(toast_overlay, settings, gtk_ver):
|
|||
|
||||
|
||||
def remove_gtk_user_override(toast_overlay, settings, gtk_ver):
|
||||
override_dir = GLib.build_filenamev([
|
||||
get_user_flatpak_path(), "overrides"
|
||||
])
|
||||
override_dir = GLib.build_filenamev([get_user_flatpak_path(), "overrides"])
|
||||
print(f"override_dir: {override_dir}")
|
||||
|
||||
filename = GLib.build_filenamev([
|
||||
override_dir, "global"
|
||||
])
|
||||
filename = GLib.build_filenamev([override_dir, "global"])
|
||||
|
||||
user_keyfile = GLib.KeyFile.new()
|
||||
|
||||
|
@ -200,7 +192,8 @@ def remove_gtk_user_override(toast_overlay, settings, gtk_ver):
|
|||
gtk_path = "xdg-config/gtk-3.0"
|
||||
else:
|
||||
raise InvalidGTKVersion(
|
||||
f"Invalid GTK version chosen: {gtk_ver}. Please choose between two options: gtk4, gtk3")
|
||||
f"Invalid GTK version chosen: {gtk_ver}. Please choose between two options: gtk4, gtk3"
|
||||
)
|
||||
|
||||
def set_theming():
|
||||
if is_gtk4:
|
||||
|
@ -216,8 +209,8 @@ def remove_gtk_user_override(toast_overlay, settings, gtk_ver):
|
|||
buglog("remove override: File doesn't exist")
|
||||
else:
|
||||
toast_overlay.add_toast(
|
||||
Adw.Toast(
|
||||
title=_("Unexpected file error occurred")))
|
||||
Adw.Toast(title=_("Unexpected file error occurred"))
|
||||
)
|
||||
buglog(f"Unhandled GLib.FileError error code. Exc: {e}")
|
||||
else:
|
||||
try:
|
||||
|
@ -235,24 +228,24 @@ def remove_gtk_user_override(toast_overlay, settings, gtk_ver):
|
|||
user_keyfile.set_string_list(
|
||||
"Context", "filesystems", filesys_list)
|
||||
user_save_keyfile(
|
||||
toast_overlay, settings, user_keyfile, filename, gtk_ver)
|
||||
toast_overlay, settings, user_keyfile, filename, gtk_ver
|
||||
)
|
||||
buglog("remove override: Value removed.")
|
||||
else:
|
||||
set_theming()
|
||||
buglog("remove override: Value not found.")
|
||||
|
||||
|
||||
''' Do not use this functions for now, as they are lacking authentication'''
|
||||
""" Do not use this functions for now, as they are lacking authentication"""
|
||||
# TODO: Implement user authentication using Polkit
|
||||
|
||||
|
||||
def create_gtk_global_override(toast_overlay, settings, gtk_ver):
|
||||
override_dir = GLib.build_filenamev([
|
||||
get_system_flatpak_path(), "overrides"
|
||||
])
|
||||
override_dir = GLib.build_filenamev(
|
||||
[get_system_flatpak_path(), "overrides"])
|
||||
print(f"override_dir: {override_dir}")
|
||||
|
||||
filename = GLib.build_filenamev([
|
||||
override_dir, "global"
|
||||
])
|
||||
filename = GLib.build_filenamev([override_dir, "global"])
|
||||
|
||||
global_keyfile = GLib.KeyFile.new()
|
||||
|
||||
|
@ -264,7 +257,8 @@ def create_gtk_global_override(toast_overlay, settings, gtk_ver):
|
|||
gtk_path = "xdg-config/gtk-3.0"
|
||||
else:
|
||||
raise InvalidGTKVersion(
|
||||
f"Invalid GTK version chosen: {gtk_ver}. Please choose between two options: gtk4, gtk3")
|
||||
f"Invalid GTK version chosen: {gtk_ver}. Please choose between two options: gtk4, gtk3"
|
||||
)
|
||||
|
||||
try:
|
||||
global_keyfile.load_from_file(filename, GLib.KeyFileFlags.NONE)
|
||||
|
@ -294,11 +288,12 @@ def create_gtk_global_override(toast_overlay, settings, gtk_ver):
|
|||
global_keyfile.set_string("Context", "filesystems", gtk_path)
|
||||
|
||||
global_save_keyfile(
|
||||
toast_overlay, settings, global_keyfile, filename, gtk_ver)
|
||||
toast_overlay, settings, global_keyfile, filename, gtk_ver
|
||||
)
|
||||
else:
|
||||
toast_overlay.add_toast(
|
||||
Adw.Toast(
|
||||
title=_("Unexpected file error occurred")))
|
||||
Adw.Toast(title=_("Unexpected file error occurred"))
|
||||
)
|
||||
buglog(f"Unhandled GLib.FileError error code. Exc: {e}")
|
||||
else:
|
||||
try:
|
||||
|
@ -307,13 +302,16 @@ def create_gtk_global_override(toast_overlay, settings, gtk_ver):
|
|||
except GLib.GError:
|
||||
global_keyfile.set_string("Context", "filesystems", gtk_path)
|
||||
global_save_keyfile(
|
||||
toast_overlay, settings, global_keyfile, filename, gtk_ver)
|
||||
toast_overlay, settings, global_keyfile, filename, gtk_ver
|
||||
)
|
||||
else:
|
||||
if gtk_path not in filesys_list:
|
||||
global_keyfile.set_string_list(
|
||||
"Context", "filesystems", filesys_list + [gtk_path])
|
||||
"Context", "filesystems", filesys_list + [gtk_path]
|
||||
)
|
||||
global_save_keyfile(
|
||||
toast_overlay, settings, global_keyfile, filename, gtk_ver)
|
||||
toast_overlay, settings, global_keyfile, filename, gtk_ver
|
||||
)
|
||||
else:
|
||||
if is_gtk4:
|
||||
settings.set_boolean("global-flatpak-theming-gtk4", True)
|
||||
|
@ -323,14 +321,11 @@ def create_gtk_global_override(toast_overlay, settings, gtk_ver):
|
|||
|
||||
|
||||
def remove_gtk_global_override(toast_overlay, settings, gtk_ver):
|
||||
override_dir = GLib.build_filenamev([
|
||||
get_system_flatpak_path(), "overrides"
|
||||
])
|
||||
override_dir = GLib.build_filenamev(
|
||||
[get_system_flatpak_path(), "overrides"])
|
||||
print(f"override_dir: {override_dir}")
|
||||
|
||||
filename = GLib.build_filenamev([
|
||||
override_dir, "global"
|
||||
])
|
||||
filename = GLib.build_filenamev([override_dir, "global"])
|
||||
|
||||
global_keyfile = GLib.KeyFile.new()
|
||||
|
||||
|
@ -342,7 +337,8 @@ def remove_gtk_global_override(toast_overlay, settings, gtk_ver):
|
|||
gtk_path = "xdg-config/gtk-3.0"
|
||||
else:
|
||||
raise InvalidGTKVersion(
|
||||
f"Invalid GTK version chosen: {gtk_ver}. Please choose between two options: gtk4, gtk3")
|
||||
f"Invalid GTK version chosen: {gtk_ver}. Please choose between two options: gtk4, gtk3"
|
||||
)
|
||||
|
||||
def set_theming():
|
||||
if is_gtk4:
|
||||
|
@ -358,8 +354,8 @@ def remove_gtk_global_override(toast_overlay, settings, gtk_ver):
|
|||
buglog("remove override: File doesn't exist")
|
||||
else:
|
||||
toast_overlay.add_toast(
|
||||
Adw.Toast(
|
||||
title=_("Unexpected file error occurred")))
|
||||
Adw.Toast(title=_("Unexpected file error occurred"))
|
||||
)
|
||||
buglog(f"Unhandled GLib.FileError error code. Exc: {e}")
|
||||
else:
|
||||
try:
|
||||
|
@ -377,7 +373,8 @@ def remove_gtk_global_override(toast_overlay, settings, gtk_ver):
|
|||
global_keyfile.set_string_list(
|
||||
"Context", "filesystems", filesys_list)
|
||||
global_save_keyfile(
|
||||
toast_overlay, settings, global_keyfile, filename, gtk_ver)
|
||||
toast_overlay, settings, global_keyfile, filename, gtk_ver
|
||||
)
|
||||
buglog("remove override: Value removed.")
|
||||
else:
|
||||
set_theming()
|
||||
|
|
|
@ -31,6 +31,7 @@ else:
|
|||
def to_slug_case(non_slug):
|
||||
return re.sub(r"[^0-9a-z]+", "-", anyascii(non_slug).lower()).strip("-")
|
||||
|
||||
|
||||
# Use it instead of print(), so there isn't any output in stdout if
|
||||
# Gradience was build in release mode
|
||||
|
||||
|
|
|
@ -34,13 +34,7 @@ class GradienceOption(Adw.ActionRow):
|
|||
explanation_button = Gtk.Template.Child("explanation-button")
|
||||
explanation_label = Gtk.Template.Child("explanation-label")
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
name,
|
||||
title,
|
||||
explanation,
|
||||
adw_gtk3_support="yes",
|
||||
**kwargs):
|
||||
def __init__(self, name, title, explanation, adw_gtk3_support="yes", **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
|
||||
self.set_name(name)
|
||||
|
@ -52,7 +46,8 @@ class GradienceOption(Adw.ActionRow):
|
|||
elif adw_gtk3_support == "partial":
|
||||
self.warning_button.add_css_class("warning")
|
||||
self.warning_label.set_label(
|
||||
_("This option is only partially supported by the adw-gtk3 theme."))
|
||||
_("This option is only partially supported by the adw-gtk3 theme.")
|
||||
)
|
||||
elif adw_gtk3_support == "no":
|
||||
self.warning_button.add_css_class("error")
|
||||
self.warning_label.set_label(
|
||||
|
|
|
@ -59,8 +59,9 @@ class GradiencePaletteShades(Adw.ActionRow):
|
|||
Gtk.Application.get_default().is_ready
|
||||
and kwargs.get("update_from") == "color_value"
|
||||
):
|
||||
Gtk.Application.get_default(
|
||||
).palette[self.prefix][str(i)] = shades[str(i)]
|
||||
Gtk.Application.get_default().palette[self.prefix][str(i)] = shades[
|
||||
str(i)
|
||||
]
|
||||
|
||||
if (
|
||||
Gtk.Application.get_default().is_ready
|
||||
|
|
|
@ -16,9 +16,10 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#from .setting import GradienceSetting
|
||||
# from .setting import GradienceSetting
|
||||
|
||||
class GradiencePluginCore():
|
||||
|
||||
class GradiencePluginCore:
|
||||
def __init__(self):
|
||||
self.title = None
|
||||
self.author = None
|
||||
|
|
|
@ -36,11 +36,15 @@ class GradiencePluginsList:
|
|||
self.win = win
|
||||
|
||||
self.pm = PluginManager()
|
||||
self.pm.setPluginPlaces([os.path.join(
|
||||
os.environ.get("XDG_CONFIG_HOME",
|
||||
os.environ["HOME"] + "/.config"),
|
||||
"gradience_plugins",
|
||||
)])
|
||||
self.pm.setPluginPlaces(
|
||||
[
|
||||
os.path.join(
|
||||
os.environ.get("XDG_CONFIG_HOME",
|
||||
os.environ["HOME"] + "/.config"),
|
||||
"gradience_plugins",
|
||||
)
|
||||
]
|
||||
)
|
||||
self.pm.collectPlugins()
|
||||
self.rows = {}
|
||||
|
||||
|
@ -60,7 +64,10 @@ class GradiencePluginsList:
|
|||
group = Adw.PreferencesGroup()
|
||||
group.set_title(_("Plugins"))
|
||||
group.set_description(
|
||||
_("Plugins add additional features to Gradience, plugins are made by Gradience community and can make issues."))
|
||||
_(
|
||||
"Plugins add additional features to Gradience, plugins are made by Gradience community and can make issues."
|
||||
)
|
||||
)
|
||||
if self.pm:
|
||||
for pluginInfo in self.pm.getAllPlugins():
|
||||
row = GradiencePluginRow(pluginInfo.plugin_object)
|
||||
|
@ -83,7 +90,5 @@ class GradiencePluginsList:
|
|||
for pluginInfo in self.pm.getAllPlugins():
|
||||
error, detail = pluginInfo.plugin_object.validate()
|
||||
if error:
|
||||
errors.append(
|
||||
detail
|
||||
)
|
||||
errors.append(detail)
|
||||
return errors
|
||||
|
|
|
@ -21,8 +21,14 @@ import os
|
|||
from gi.repository import GLib, Gio, Gtk, Adw
|
||||
|
||||
from .constants import rootdir, app_id
|
||||
from .modules.flatpak_overrides import create_gtk_user_override, remove_gtk_user_override
|
||||
from .modules.flatpak_overrides import create_gtk_global_override, remove_gtk_global_override
|
||||
from .modules.flatpak_overrides import (
|
||||
create_gtk_user_override,
|
||||
remove_gtk_user_override,
|
||||
)
|
||||
from .modules.flatpak_overrides import (
|
||||
create_gtk_global_override,
|
||||
remove_gtk_global_override,
|
||||
)
|
||||
from .modules.utils import buglog
|
||||
|
||||
|
||||
|
@ -51,12 +57,14 @@ class GradiencePreferencesWindow(Adw.PreferencesWindow):
|
|||
|
||||
def setup_flatpak_group(self):
|
||||
user_flatpak_theming_gtk4 = self.settings.get_boolean(
|
||||
"user-flatpak-theming-gtk4")
|
||||
"user-flatpak-theming-gtk4"
|
||||
)
|
||||
# global_flatpak_theming_gtk4 = self.settings.get_boolean(
|
||||
# "global-flatpak-theming-gtk4")
|
||||
|
||||
user_flatpak_theming_gtk3 = self.settings.get_boolean(
|
||||
"user-flatpak-theming-gtk3")
|
||||
"user-flatpak-theming-gtk3"
|
||||
)
|
||||
# global_flatpak_theming_gtk3 = self.settings.get_boolean(
|
||||
# "global-flatpak-theming-gtk3")
|
||||
|
||||
|
@ -69,12 +77,14 @@ class GradiencePreferencesWindow(Adw.PreferencesWindow):
|
|||
# self.allow_gtk3_flatpak_theming_global.set_state(global_flatpak_theming_gtk3)
|
||||
|
||||
self.allow_gtk4_flatpak_theming_user.connect(
|
||||
"state-set", self.on_allow_gtk4_flatpak_theming_user_toggled)
|
||||
"state-set", self.on_allow_gtk4_flatpak_theming_user_toggled
|
||||
)
|
||||
# self.allow_gtk4_flatpak_theming_global.connect(
|
||||
# "state-set", self.on_allow_gtk4_flatpak_theming_global_toggled)
|
||||
|
||||
self.allow_gtk3_flatpak_theming_user.connect(
|
||||
"state-set", self.on_allow_gtk3_flatpak_theming_user_toggled)
|
||||
"state-set", self.on_allow_gtk3_flatpak_theming_user_toggled
|
||||
)
|
||||
# self.allow_gtk3_flatpak_theming_global.connect(
|
||||
# "state-set", self.on_allow_gtk3_flatpak_theming_global_toggled)
|
||||
|
||||
|
@ -87,7 +97,8 @@ class GradiencePreferencesWindow(Adw.PreferencesWindow):
|
|||
remove_gtk_user_override(self, self.settings, "gtk4")
|
||||
|
||||
buglog(
|
||||
f"user-flatpak-theming-gtk4: {self.settings.get_boolean('user-flatpak-theming-gtk4')}")
|
||||
f"user-flatpak-theming-gtk4: {self.settings.get_boolean('user-flatpak-theming-gtk4')}"
|
||||
)
|
||||
|
||||
def on_allow_gtk3_flatpak_theming_user_toggled(self, *args):
|
||||
state = self.allow_gtk3_flatpak_theming_user.props.state
|
||||
|
@ -98,7 +109,8 @@ class GradiencePreferencesWindow(Adw.PreferencesWindow):
|
|||
remove_gtk_user_override(self, self.settings, "gtk3")
|
||||
|
||||
buglog(
|
||||
f"user-flatpak-theming-gtk3: {self.settings.get_boolean('user-flatpak-theming-gtk3')}")
|
||||
f"user-flatpak-theming-gtk3: {self.settings.get_boolean('user-flatpak-theming-gtk3')}"
|
||||
)
|
||||
|
||||
def on_allow_gtk4_flatpak_theming_global_toggled(self, *args):
|
||||
state = self.allow_gtk4_flatpak_theming_global.props.state
|
||||
|
@ -109,7 +121,8 @@ class GradiencePreferencesWindow(Adw.PreferencesWindow):
|
|||
remove_gtk_global_override(self, self.settings, "gtk4")
|
||||
|
||||
buglog(
|
||||
f"global-flatpak-theming-gtk4: {self.settings.get_boolean('global-flatpak-theming-gtk4')}")
|
||||
f"global-flatpak-theming-gtk4: {self.settings.get_boolean('global-flatpak-theming-gtk4')}"
|
||||
)
|
||||
|
||||
def on_allow_gtk3_flatpak_theming_global_toggled(self, *args):
|
||||
state = self.allow_gtk3_flatpak_theming_global.props.state
|
||||
|
@ -120,4 +133,5 @@ class GradiencePreferencesWindow(Adw.PreferencesWindow):
|
|||
remove_gtk_global_override(self, self.settings, "gtk3")
|
||||
|
||||
buglog(
|
||||
f"global-flatpak-theming-gtk3: {self.settings.get_boolean('global-flatpak-theming-gtk3')}")
|
||||
f"global-flatpak-theming-gtk3: {self.settings.get_boolean('global-flatpak-theming-gtk3')}"
|
||||
)
|
||||
|
|
|
@ -59,13 +59,15 @@ class GradiencePresetRow(Adw.ActionRow):
|
|||
def on_apply_button_clicked(self, *_args):
|
||||
buglog("apply")
|
||||
|
||||
self.app.load_preset_from_file(os.path.join(
|
||||
os.environ.get("XDG_CONFIG_HOME",
|
||||
os.environ["HOME"] + "/.config"),
|
||||
"presets",
|
||||
self.prefix,
|
||||
to_slug_case(self.name) + ".json",
|
||||
))
|
||||
self.app.load_preset_from_file(
|
||||
os.path.join(
|
||||
os.environ.get("XDG_CONFIG_HOME",
|
||||
os.environ["HOME"] + "/.config"),
|
||||
"presets",
|
||||
self.prefix,
|
||||
to_slug_case(self.name) + ".json",
|
||||
)
|
||||
)
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
def on_name_entry_changed(self, *_args):
|
||||
|
@ -89,12 +91,9 @@ class GradiencePresetRow(Adw.ActionRow):
|
|||
self.delete_toast.set_button_label(_("Undo"))
|
||||
self.delete_toast.connect("dismissed", self.on_delete_toast_dismissed)
|
||||
self.delete_toast.connect(
|
||||
"button-clicked",
|
||||
self.on_undo_button_clicked)
|
||||
"button-clicked", self.on_undo_button_clicked)
|
||||
|
||||
self.toast_overlay.add_toast(
|
||||
self.delete_toast
|
||||
)
|
||||
self.toast_overlay.add_toast(self.delete_toast)
|
||||
|
||||
self.win.old_name = self.name
|
||||
|
||||
|
@ -103,13 +102,15 @@ class GradiencePresetRow(Adw.ActionRow):
|
|||
self.win.reload_pref_group()
|
||||
|
||||
def update_value(self):
|
||||
os.remove(os.path.join(
|
||||
os.environ.get("XDG_CONFIG_HOME",
|
||||
os.environ["HOME"] + "/.config"),
|
||||
"presets",
|
||||
self.prefix,
|
||||
to_slug_case(self.old_name) + ".json",
|
||||
))
|
||||
os.remove(
|
||||
os.path.join(
|
||||
os.environ.get("XDG_CONFIG_HOME",
|
||||
os.environ["HOME"] + "/.config"),
|
||||
"presets",
|
||||
self.prefix,
|
||||
to_slug_case(self.old_name) + ".json",
|
||||
)
|
||||
)
|
||||
with open(
|
||||
os.path.join(
|
||||
os.environ.get("XDG_CONFIG_HOME",
|
||||
|
@ -129,27 +130,30 @@ class GradiencePresetRow(Adw.ActionRow):
|
|||
}
|
||||
file.write(json.dumps(object_to_write, indent=4))
|
||||
self.app.clear_dirty()
|
||||
self.toast_overlay.add_toast(
|
||||
Adw.Toast(title=_("Preset renamed"))
|
||||
)
|
||||
self.toast_overlay.add_toast(Adw.Toast(title=_("Preset renamed")))
|
||||
self.old_name = self.name
|
||||
|
||||
def do_delete_preset(self):
|
||||
if self.delete_preset:
|
||||
try:
|
||||
os.rename(os.path.join(
|
||||
os.environ.get("XDG_CONFIG_HOME",
|
||||
os.environ["HOME"] + "/.config"),
|
||||
"presets",
|
||||
self.prefix,
|
||||
to_slug_case(self.old_name) + ".json",
|
||||
), os.path.join(
|
||||
os.environ.get("XDG_CONFIG_HOME",
|
||||
os.environ["HOME"] + "/.config"),
|
||||
"presets",
|
||||
self.prefix,
|
||||
to_slug_case(self.old_name) + ".json.to_delete",
|
||||
))
|
||||
os.rename(
|
||||
os.path.join(
|
||||
os.environ.get(
|
||||
"XDG_CONFIG_HOME", os.environ["HOME"] + "/.config"
|
||||
),
|
||||
"presets",
|
||||
self.prefix,
|
||||
to_slug_case(self.old_name) + ".json",
|
||||
),
|
||||
os.path.join(
|
||||
os.environ.get(
|
||||
"XDG_CONFIG_HOME", os.environ["HOME"] + "/.config"
|
||||
),
|
||||
"presets",
|
||||
self.prefix,
|
||||
to_slug_case(self.old_name) + ".json.to_delete",
|
||||
),
|
||||
)
|
||||
except Exception as exception:
|
||||
print(exception.with_traceback())
|
||||
finally:
|
||||
|
@ -160,13 +164,16 @@ class GradiencePresetRow(Adw.ActionRow):
|
|||
def on_delete_toast_dismissed(self, widget):
|
||||
if self.delete_preset:
|
||||
try:
|
||||
os.remove(os.path.join(
|
||||
os.environ.get("XDG_CONFIG_HOME",
|
||||
os.environ["HOME"] + "/.config"),
|
||||
"presets",
|
||||
self.prefix,
|
||||
to_slug_case(self.old_name) + ".json.to_delete",
|
||||
))
|
||||
os.remove(
|
||||
os.path.join(
|
||||
os.environ.get(
|
||||
"XDG_CONFIG_HOME", os.environ["HOME"] + "/.config"
|
||||
),
|
||||
"presets",
|
||||
self.prefix,
|
||||
to_slug_case(self.old_name) + ".json.to_delete",
|
||||
)
|
||||
)
|
||||
except Exception as exception:
|
||||
print(exception.with_traceback())
|
||||
self.toast_overlay.add_toast(
|
||||
|
@ -174,25 +181,29 @@ class GradiencePresetRow(Adw.ActionRow):
|
|||
)
|
||||
else:
|
||||
self.toast_overlay.add_toast(
|
||||
Adw.Toast(title=_("Preset removed"))
|
||||
)
|
||||
Adw.Toast(title=_("Preset removed")))
|
||||
finally:
|
||||
self.win.reload_pref_group()
|
||||
else:
|
||||
try:
|
||||
os.rename(os.path.join(
|
||||
os.environ.get("XDG_CONFIG_HOME",
|
||||
os.environ["HOME"] + "/.config"),
|
||||
"presets",
|
||||
self.prefix,
|
||||
to_slug_case(self.old_name) + ".json.to_delete",
|
||||
), os.path.join(
|
||||
os.environ.get("XDG_CONFIG_HOME",
|
||||
os.environ["HOME"] + "/.config"),
|
||||
"presets",
|
||||
self.prefix,
|
||||
to_slug_case(self.old_name) + ".json",
|
||||
))
|
||||
os.rename(
|
||||
os.path.join(
|
||||
os.environ.get(
|
||||
"XDG_CONFIG_HOME", os.environ["HOME"] + "/.config"
|
||||
),
|
||||
"presets",
|
||||
self.prefix,
|
||||
to_slug_case(self.old_name) + ".json.to_delete",
|
||||
),
|
||||
os.path.join(
|
||||
os.environ.get(
|
||||
"XDG_CONFIG_HOME", os.environ["HOME"] + "/.config"
|
||||
),
|
||||
"presets",
|
||||
self.prefix,
|
||||
to_slug_case(self.old_name) + ".json",
|
||||
),
|
||||
)
|
||||
except Exception as exception:
|
||||
print(exception.with_traceback())
|
||||
finally:
|
||||
|
|
|
@ -31,6 +31,7 @@ from .modules.custom_presets import fetch_presets
|
|||
from .constants import rootdir, build_type
|
||||
from .modules.utils import to_slug_case
|
||||
from .repo_row import GradienceRepoRow
|
||||
|
||||
PRESETS_LIST_URL = "https://github.com/GradienceTeam/Community/raw/main/presets.json"
|
||||
|
||||
|
||||
|
@ -55,7 +56,8 @@ class GradiencePresetWindow(Adw.Window):
|
|||
custom_presets = {}
|
||||
|
||||
official_repositories = {
|
||||
"Official": "https://github.com/GradienceTeam/Community/raw/main/presets.json"}
|
||||
"Official": "https://github.com/GradienceTeam/Community/raw/main/presets.json"
|
||||
}
|
||||
|
||||
search_results_list = []
|
||||
|
||||
|
@ -90,9 +92,8 @@ class GradiencePresetWindow(Adw.Window):
|
|||
self.save_repos()
|
||||
|
||||
def save_repos(self):
|
||||
self.settings.set_value(
|
||||
"repos", GLib.Variant(
|
||||
"a{sv}", self.user_repositories))
|
||||
self.settings.set_value("repos", GLib.Variant(
|
||||
"a{sv}", self.user_repositories))
|
||||
self.reload_repos_group()
|
||||
self.setup_explore()
|
||||
|
||||
|
@ -131,16 +132,13 @@ class GradiencePresetWindow(Adw.Window):
|
|||
dialog = Adw.MessageDialog(
|
||||
transient_for=self,
|
||||
heading=_("Add new repository"),
|
||||
body=_(
|
||||
"Add a repository to install additional presets"
|
||||
),
|
||||
body=_("Add a repository to install additional presets"),
|
||||
body_use_markup=True,
|
||||
)
|
||||
|
||||
dialog.add_response("cancel", _("Cancel"))
|
||||
dialog.add_response("add", _("Add"))
|
||||
dialog.set_response_appearance(
|
||||
"add", Adw.ResponseAppearance.SUGGESTED)
|
||||
dialog.set_response_appearance("add", Adw.ResponseAppearance.SUGGESTED)
|
||||
dialog.set_default_response("cancel")
|
||||
dialog.set_close_response("cancel")
|
||||
|
||||
|
@ -191,9 +189,11 @@ class GradiencePresetWindow(Adw.Window):
|
|||
self.search_spinner.props.visible = False
|
||||
|
||||
for (preset, preset_name), preset_url in zip(
|
||||
self.explore_presets.items(), urls):
|
||||
self.explore_presets.items(), urls
|
||||
):
|
||||
row = GradienceExplorePresetRow(
|
||||
preset_name, preset_url, self, repo_name)
|
||||
preset_name, preset_url, self, repo_name
|
||||
)
|
||||
self.search_results.append(row)
|
||||
self.search_results_list.append(row)
|
||||
if not_offline:
|
||||
|
@ -205,8 +205,7 @@ class GradiencePresetWindow(Adw.Window):
|
|||
self.file_chooser_dialog.set_transient_for(self)
|
||||
|
||||
self.file_chooser_dialog.connect(
|
||||
"response", self.on_file_chooser_response
|
||||
)
|
||||
"response", self.on_file_chooser_response)
|
||||
|
||||
def connect_signals(self):
|
||||
self.search_entry.connect("search-changed", self.on_search_changed)
|
||||
|
@ -240,18 +239,23 @@ class GradiencePresetWindow(Adw.Window):
|
|||
Adw.Toast(title=_("Preset already exists"))
|
||||
)
|
||||
else:
|
||||
shutil.copy(self.preset_path.get_path(), os.path.join(
|
||||
os.environ.get("XDG_CONFIG_HOME",
|
||||
os.environ["HOME"] + "/.config"),
|
||||
"presets",
|
||||
preset_file
|
||||
))
|
||||
self.toast_overlay.add_toast(
|
||||
Adw.Toast(title=_("Preset imported"))
|
||||
shutil.copy(
|
||||
self.preset_path.get_path(),
|
||||
os.path.join(
|
||||
os.environ.get(
|
||||
"XDG_CONFIG_HOME", os.environ["HOME"] +
|
||||
"/.config"
|
||||
),
|
||||
"presets",
|
||||
preset_file,
|
||||
),
|
||||
)
|
||||
self.toast_overlay.add_toast(
|
||||
Adw.Toast(title=_("Preset imported")))
|
||||
else:
|
||||
self.toast_overlay.add_toast(Adw.Toast(
|
||||
title=_("Unsupported file format, must be .json")))
|
||||
self.toast_overlay.add_toast(
|
||||
Adw.Toast(title=_("Unsupported file format, must be .json"))
|
||||
)
|
||||
|
||||
self.reload_pref_group()
|
||||
|
||||
|
@ -277,7 +281,9 @@ class GradiencePresetWindow(Adw.Window):
|
|||
if file_name.endswith(".json"):
|
||||
try:
|
||||
with open(
|
||||
os.path.join(preset_directory, file_name), "r", encoding="utf-8"
|
||||
os.path.join(preset_directory, file_name),
|
||||
"r",
|
||||
encoding="utf-8",
|
||||
) as file:
|
||||
preset_text = file.read()
|
||||
preset = json.loads(preset_text)
|
||||
|
@ -285,8 +291,9 @@ class GradiencePresetWindow(Adw.Window):
|
|||
raise KeyError("variables")
|
||||
if preset.get("palette") is None:
|
||||
raise KeyError("palette")
|
||||
presets_list[file_name.replace(
|
||||
".json", "")] = preset["name"]
|
||||
presets_list[file_name.replace(".json", "")] = preset[
|
||||
"name"
|
||||
]
|
||||
except Exception:
|
||||
self.toast_overlay.add_toast(
|
||||
Adw.Toast(title=_("Failed to load preset"))
|
||||
|
@ -301,7 +308,9 @@ class GradiencePresetWindow(Adw.Window):
|
|||
|
||||
try:
|
||||
with open(
|
||||
os.path.join(preset_directory, "user", repo), "r", encoding="utf-8"
|
||||
os.path.join(preset_directory, "user", repo),
|
||||
"r",
|
||||
encoding="utf-8",
|
||||
) as file:
|
||||
preset_text = file.read()
|
||||
preset = json.loads(preset_text)
|
||||
|
@ -309,8 +318,9 @@ class GradiencePresetWindow(Adw.Window):
|
|||
raise KeyError("variables")
|
||||
if preset.get("palette") is None:
|
||||
raise KeyError("palette")
|
||||
presets_list["user"][file_name.replace(
|
||||
".json", "")] = preset["name"]
|
||||
presets_list["user"][file_name.replace(".json", "")] = preset[
|
||||
"name"
|
||||
]
|
||||
except Exception:
|
||||
self.toast_overlay.add_toast(
|
||||
Adw.Toast(title=_("Failed to load preset"))
|
||||
|
@ -329,7 +339,10 @@ class GradiencePresetWindow(Adw.Window):
|
|||
self.preset_list = Adw.PreferencesGroup()
|
||||
self.preset_list.set_title(_("User Presets"))
|
||||
self.preset_list.set_description(
|
||||
_("See <a href=\"https://github.com/GradienceTeam/Community\">GradienceTeam/Community</a> on Github for more presets"))
|
||||
_(
|
||||
'See <a href="https://github.com/GradienceTeam/Community">GradienceTeam/Community</a> on Github for more presets'
|
||||
)
|
||||
)
|
||||
|
||||
if self.custom_presets:
|
||||
for repo, presets in self.custom_presets.items():
|
||||
|
@ -340,6 +353,9 @@ class GradiencePresetWindow(Adw.Window):
|
|||
else:
|
||||
self.preset_empty = Adw.ActionRow()
|
||||
self.preset_empty.set_title(
|
||||
_("No preset found! Use the import button to import one or search one on the Explore tab"))
|
||||
_(
|
||||
"No preset found! Use the import button to import one or search one on the Explore tab"
|
||||
)
|
||||
)
|
||||
self.preset_list.add(self.preset_empty)
|
||||
self.installed.add(self.preset_list)
|
||||
|
|
|
@ -48,10 +48,9 @@ class GradienceRepoRow(Adw.ActionRow):
|
|||
self.remove_button.set_visible(False)
|
||||
|
||||
self.path = os.path.join(
|
||||
os.environ.get("XDG_CONFIG_HOME",
|
||||
os.environ["HOME"] + "/.config"),
|
||||
os.environ.get("XDG_CONFIG_HOME", os.environ["HOME"] + "/.config"),
|
||||
"presets",
|
||||
to_slug_case(repo_name)
|
||||
to_slug_case(repo_name),
|
||||
)
|
||||
|
||||
if not os.path.exists(self.path):
|
||||
|
@ -59,9 +58,7 @@ class GradienceRepoRow(Adw.ActionRow):
|
|||
|
||||
@Gtk.Template.Callback()
|
||||
def on_remove_button_clicked(self, *_args):
|
||||
self.toast_overlay.add_toast(
|
||||
Adw.Toast(title=_("Repository removed"))
|
||||
)
|
||||
self.toast_overlay.add_toast(Adw.Toast(title=_("Repository removed")))
|
||||
|
||||
self.win.remove_repo(self.name)
|
||||
|
||||
|
|
|
@ -51,13 +51,15 @@ class RunAsync(threading.Thread):
|
|||
try:
|
||||
result = self.task_func(*args, **kwargs)
|
||||
except Exception as exception:
|
||||
buglog("Error while running async job: "
|
||||
f"{self.task_func}\nException: {exception}")
|
||||
buglog(
|
||||
"Error while running async job: "
|
||||
f"{self.task_func}\nException: {exception}"
|
||||
)
|
||||
|
||||
error = exception
|
||||
_ex_type, _ex_value, trace = sys.exc_info()
|
||||
traceback.print_tb(trace)
|
||||
traceback_info = '\n'.join(traceback.format_tb(trace))
|
||||
traceback_info = "\n".join(traceback.format_tb(trace))
|
||||
|
||||
buglog([str(exception), traceback_info])
|
||||
self.source_id = GLib.idle_add(self.callback, result, error)
|
||||
|
|
|
@ -18,13 +18,7 @@
|
|||
|
||||
|
||||
class GradienceSetting:
|
||||
def __init__(
|
||||
self,
|
||||
name,
|
||||
title,
|
||||
value_type,
|
||||
explanation=None,
|
||||
default_value=None):
|
||||
def __init__(self, name, title, value_type, explanation=None, default_value=None):
|
||||
# TODO supported types:
|
||||
# text
|
||||
# integer
|
||||
|
|
|
@ -64,27 +64,19 @@ class GradienceMainWindow(Adw.ApplicationWindow):
|
|||
self.settings = Gio.Settings(app_id)
|
||||
|
||||
self.settings.bind(
|
||||
"window-width",
|
||||
self,
|
||||
"default-width",
|
||||
Gio.SettingsBindFlags.DEFAULT)
|
||||
"window-width", self, "default-width", Gio.SettingsBindFlags.DEFAULT
|
||||
)
|
||||
|
||||
self.settings.bind(
|
||||
"window-height",
|
||||
self,
|
||||
"default-height",
|
||||
Gio.SettingsBindFlags.DEFAULT)
|
||||
"window-height", self, "default-height", Gio.SettingsBindFlags.DEFAULT
|
||||
)
|
||||
self.settings.bind(
|
||||
"window-maximized",
|
||||
self,
|
||||
"maximized",
|
||||
Gio.SettingsBindFlags.DEFAULT)
|
||||
"window-maximized", self, "maximized", Gio.SettingsBindFlags.DEFAULT
|
||||
)
|
||||
|
||||
self.settings.bind(
|
||||
"window-fullscreen",
|
||||
self,
|
||||
"fullscreened",
|
||||
Gio.SettingsBindFlags.DEFAULT)
|
||||
"window-fullscreen", self, "fullscreened", Gio.SettingsBindFlags.DEFAULT
|
||||
)
|
||||
|
||||
self.connect("close-request", self.__close_window)
|
||||
self.style_manager = self.get_application().style_manager
|
||||
|
@ -97,11 +89,9 @@ class GradienceMainWindow(Adw.ApplicationWindow):
|
|||
def get_default_wallpaper(self):
|
||||
background_settings = Gio.Settings("org.gnome.desktop.background")
|
||||
if self.style_manager.get_dark():
|
||||
picture_uri = background_settings.get_string(
|
||||
"picture-uri-dark")
|
||||
picture_uri = background_settings.get_string("picture-uri-dark")
|
||||
else:
|
||||
picture_uri = background_settings.get_string(
|
||||
"picture-uri")
|
||||
picture_uri = background_settings.get_string("picture-uri")
|
||||
buglog(picture_uri)
|
||||
if picture_uri.startswith("file://"):
|
||||
self.monet_image_file = Gio.File.new_for_uri(picture_uri)
|
||||
|
@ -128,8 +118,7 @@ class GradienceMainWindow(Adw.ApplicationWindow):
|
|||
self.monet_image_file = self.monet_file_chooser_dialog.get_file()
|
||||
image_basename = self.monet_image_file.get_basename()
|
||||
self.monet_file_chooser_button.set_label(image_basename)
|
||||
self.monet_file_chooser_button.set_tooltip_text(
|
||||
image_basename)
|
||||
self.monet_file_chooser_button.set_tooltip_text(image_basename)
|
||||
self.monet_file_chooser_dialog.hide()
|
||||
|
||||
if response == Gtk.ResponseType.ACCEPT:
|
||||
|
@ -142,7 +131,10 @@ class GradienceMainWindow(Adw.ApplicationWindow):
|
|||
self.monet_pref_group.set_name("monet")
|
||||
self.monet_pref_group.set_title(_("Monet Engine"))
|
||||
self.monet_pref_group.set_description(
|
||||
_("Monet is an engine that generates a Material Design 3 palette from an image's color."))
|
||||
_(
|
||||
"Monet is an engine that generates a Material Design 3 palette from an image's color."
|
||||
)
|
||||
)
|
||||
|
||||
self.apply_button = Gtk.Button()
|
||||
self.apply_button.set_label(_("Apply"))
|
||||
|
@ -158,7 +150,7 @@ class GradienceMainWindow(Adw.ApplicationWindow):
|
|||
|
||||
self.monet_file_chooser_button = Gtk.Button()
|
||||
self.monet_file_chooser_button.set_valign(Gtk.Align.CENTER)
|
||||
#self.monet_file_chooser_button.set_label(_("Choose a file"))
|
||||
# self.monet_file_chooser_button.set_label(_("Choose a file"))
|
||||
# self.monet_file_chooser_button.set_icon_name("folder-pictures-symbolic")
|
||||
|
||||
child_button = Gtk.Box()
|
||||
|
@ -221,8 +213,9 @@ class GradienceMainWindow(Adw.ApplicationWindow):
|
|||
if self.monet_image_file.endswith(".svg"):
|
||||
drawing = svg2rlg(self.monet_image_file)
|
||||
self.monet_image_file = os.path.join(
|
||||
os.environ.get("XDG_RUNTIME_DIR"), "gradience_bg.png")
|
||||
renderPM.drawToFile(drawing, self.monet_image_file, fmt='PNG')
|
||||
os.environ.get("XDG_RUNTIME_DIR"), "gradience_bg.png"
|
||||
)
|
||||
renderPM.drawToFile(drawing, self.monet_image_file, fmt="PNG")
|
||||
|
||||
if self.monet_image_file.endswith(".xml"):
|
||||
buglog("XML WIP")
|
||||
|
@ -235,10 +228,11 @@ class GradienceMainWindow(Adw.ApplicationWindow):
|
|||
)
|
||||
else:
|
||||
basewidth = 64
|
||||
wpercent = (basewidth / float(self.monet_img.size[0]))
|
||||
wpercent = basewidth / float(self.monet_img.size[0])
|
||||
hsize = int((float(self.monet_img.size[1]) * float(wpercent)))
|
||||
self.monet_img = self.monet_img.resize(
|
||||
(basewidth, hsize), Image.Resampling.LANCZOS)
|
||||
(basewidth, hsize), Image.Resampling.LANCZOS
|
||||
)
|
||||
self.theme = themeFromImage(self.monet_img)
|
||||
self.tone = self.tone_row.get_selected_item()
|
||||
self.monet_theme = self.monet_theme_row.get_selected_item()
|
||||
|
@ -278,7 +272,10 @@ class GradienceMainWindow(Adw.ApplicationWindow):
|
|||
palette_pref_group.set_name("palette_colors")
|
||||
palette_pref_group.set_title(_("Palette Colors"))
|
||||
palette_pref_group.set_description(
|
||||
_('Named palette colors used by some applications. Default colors follow the <a href="https://developer.gnome.org/hig/reference/palette.html">GNOME Human Interface Guidelines</a>.'))
|
||||
_(
|
||||
'Named palette colors used by some applications. Default colors follow the <a href="https://developer.gnome.org/hig/reference/palette.html">GNOME Human Interface Guidelines</a>.'
|
||||
)
|
||||
)
|
||||
for color in settings_schema["palette"]:
|
||||
palette_shades = GradiencePaletteShades(
|
||||
color["prefix"], color["title"], color["n_shades"]
|
||||
|
@ -296,10 +293,8 @@ class GradienceMainWindow(Adw.ApplicationWindow):
|
|||
self.errors_button.set_visible(len(errors) > 0)
|
||||
for error in errors:
|
||||
self.errors_list.append(
|
||||
GradienceError(
|
||||
error["error"],
|
||||
error["element"],
|
||||
error["line"]))
|
||||
GradienceError(error["error"], error["element"], error["line"])
|
||||
)
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
def on_presets_button_clicked(self, *args):
|
||||
|
|
Loading…
Reference in a new issue