mirror of
https://github.com/GradienceTeam/Gradience.git
synced 2024-08-29 18:32:32 +00:00
Merge branch 'main' into deepsource-fix-8a63f812
Signed-off-by: 0xMRTT <0xMRTT@tuta.io>
This commit is contained in:
commit
4ec7de2589
14 changed files with 190 additions and 177 deletions
|
@ -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")
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -16,13 +16,17 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import sys
|
||||
import time
|
||||
|
||||
from gi.repository import Gtk, Adw, Gio, Gdk
|
||||
|
||||
from .run_async import RunAsync
|
||||
from .modules.utils import buglog
|
||||
from .modules.flatpak_overrides import create_gtk_user_override, remove_gtk_user_override
|
||||
from .modules.flatpak_overrides import (
|
||||
create_gtk_user_override,
|
||||
remove_gtk_user_override,
|
||||
)
|
||||
from .constants import rootdir, app_id
|
||||
|
||||
|
||||
|
@ -46,13 +50,8 @@ class GradienceWelcomeWindow(Adw.Window):
|
|||
img_welcome = Gtk.Template.Child()
|
||||
label_skip = Gtk.Template.Child()
|
||||
|
||||
carousel_pages = [
|
||||
"welcome",
|
||||
"gradience",
|
||||
"configure",
|
||||
"download",
|
||||
"finish"
|
||||
]
|
||||
carousel_pages = ["welcome", "gradience",
|
||||
"configure", "download", "finish"]
|
||||
images = [
|
||||
f"{rootdir}/images/welcome.svg",
|
||||
f"{rootdir}/images/welcome-dark.svg",
|
||||
|
@ -69,14 +68,14 @@ class GradienceWelcomeWindow(Adw.Window):
|
|||
|
||||
# connect signals
|
||||
self.connect("close-request", self.quit)
|
||||
self.carousel.connect('page-changed', self.page_changed)
|
||||
self.carousel.connect("page-changed", self.page_changed)
|
||||
self.btn_close.connect("clicked", self.close_window)
|
||||
self.btn_back.connect("clicked", self.previous_page)
|
||||
self.btn_next.connect("clicked", self.next_page)
|
||||
self.btn_install.connect("clicked", self.install_runner)
|
||||
self.settings.connect(
|
||||
"notify::gtk-application-prefer-dark-theme",
|
||||
self.theme_changed)
|
||||
"notify::gtk-application-prefer-dark-theme", self.theme_changed
|
||||
)
|
||||
|
||||
self.btn_close.set_sensitive(False)
|
||||
|
||||
|
@ -87,7 +86,9 @@ class GradienceWelcomeWindow(Adw.Window):
|
|||
|
||||
def theme_changed(self, settings, key):
|
||||
self.img_welcome.set_from_resource(
|
||||
self.images[settings.get_property("gtk-application-prefer-dark-theme")])
|
||||
self.images[settings.get_property(
|
||||
"gtk-application-prefer-dark-theme")]
|
||||
)
|
||||
|
||||
def get_page(self, index):
|
||||
return self.carousel_pages[index]
|
||||
|
@ -116,7 +117,7 @@ class GradienceWelcomeWindow(Adw.Window):
|
|||
|
||||
@staticmethod
|
||||
def quit(widget=False):
|
||||
quit()
|
||||
sys.exit()
|
||||
|
||||
# TODO: Add adw-gtk3 check
|
||||
def check_adw_gtk3(self):
|
||||
|
@ -134,7 +135,8 @@ class GradienceWelcomeWindow(Adw.Window):
|
|||
def allow_flatpak_theming_user_toggled(self, *args):
|
||||
create_gtk_user_override(self, self.gio_settings, "gtk4")
|
||||
buglog(
|
||||
f"user-flatpak-theming: {self.gio_settings.get_boolean('user-flatpak-theming')}")
|
||||
f"user-flatpak-theming: {self.gio_settings.get_boolean('user-flatpak-theming')}"
|
||||
)
|
||||
|
||||
def install_runner(self, widget):
|
||||
def set_completed(result, error=False):
|
||||
|
@ -179,7 +181,7 @@ class GradienceWelcomeWindow(Adw.Window):
|
|||
def pulse(self):
|
||||
# This function update the progress bar every 1s.
|
||||
while True:
|
||||
time.sleep(.5)
|
||||
time.sleep(0.5)
|
||||
self.progressbar.pulse()
|
||||
|
||||
def close_window(self, widget):
|
||||
|
|
Loading…
Reference in a new issue