mirror of
https://github.com/GradienceTeam/Gradience.git
synced 2024-08-26 09:22:32 +00:00
Add multi-threading to presets manager (#504)
This commit is contained in:
commit
3387ef2c66
7 changed files with 46 additions and 176 deletions
|
@ -48,105 +48,14 @@
|
||||||
margin: 0 2px;
|
margin: 0 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.badge-blue {
|
|
||||||
background-color: #3584e4;
|
|
||||||
}
|
|
||||||
.badge-green {
|
|
||||||
background-color: #33d17a;
|
|
||||||
}
|
|
||||||
|
|
||||||
.badge-red {
|
|
||||||
background-color: #e01b24;
|
|
||||||
}
|
|
||||||
.badge-black {
|
.badge-black {
|
||||||
background-color: #3d3846;
|
background-color: #3d3846;
|
||||||
color: #deddda;
|
color: #deddda;
|
||||||
}
|
}
|
||||||
.badge-orange {
|
|
||||||
background-color: #ff7800;
|
|
||||||
}
|
|
||||||
.badge-yellow {
|
|
||||||
background-color: #f6d32d;
|
|
||||||
color: #3d3846;
|
|
||||||
}
|
|
||||||
.badge-white {
|
.badge-white {
|
||||||
background-color: #deddda;
|
background-color: #deddda;
|
||||||
color: #3d3846;
|
color: #3d3846;
|
||||||
}
|
}
|
||||||
.badge-brown {
|
|
||||||
background-color: #a47e3c;
|
|
||||||
}
|
|
||||||
.badge-purple {
|
|
||||||
background-color: #a47e3c;
|
|
||||||
}
|
|
||||||
.badge-pink {
|
|
||||||
background-color: #e01b24;
|
|
||||||
}
|
|
||||||
.badge-gray {
|
|
||||||
background-color: #deddda;
|
|
||||||
color: #3d3846;
|
|
||||||
}
|
|
||||||
.badge-silver {
|
|
||||||
background-color: #deddda;
|
|
||||||
color: #3d3846;
|
|
||||||
}
|
|
||||||
.badge-gold {
|
|
||||||
background-color: #f6d32d;
|
|
||||||
}
|
|
||||||
.badge-copper {
|
|
||||||
background-color: #a47e3c;
|
|
||||||
}
|
|
||||||
.badge-bronze {
|
|
||||||
background-color: #a47e3c;
|
|
||||||
}
|
|
||||||
.badge-iron {
|
|
||||||
background-color: #3d3846;
|
|
||||||
color: #deddda;
|
|
||||||
}
|
|
||||||
.badge-steel {
|
|
||||||
background-color: #3d3846;
|
|
||||||
color: #deddda;
|
|
||||||
}
|
|
||||||
.badge-tin {
|
|
||||||
background-color: #deddda;
|
|
||||||
color: #3d3846;
|
|
||||||
}
|
|
||||||
.badge-aluminum {
|
|
||||||
background-color: #deddda;
|
|
||||||
color: #3d3846;
|
|
||||||
}
|
|
||||||
.badge-cobalt {
|
|
||||||
background-color: #3584e4;
|
|
||||||
}
|
|
||||||
.badge-titanium {
|
|
||||||
background-color: #3d3846;
|
|
||||||
color: #deddda;
|
|
||||||
}
|
|
||||||
.badge-platinum {
|
|
||||||
background-color: #deddda;
|
|
||||||
color: #3d3846;
|
|
||||||
}
|
|
||||||
.badge-lead {
|
|
||||||
background-color: #3d3846;
|
|
||||||
color: #deddda;
|
|
||||||
}
|
|
||||||
.badge-mercury {
|
|
||||||
background-color: #deddda;
|
|
||||||
color: #3d3846;
|
|
||||||
}
|
|
||||||
.badge-uranium {
|
|
||||||
background-color: #33d17a;
|
|
||||||
color: #3d3846;
|
|
||||||
}
|
|
||||||
.badge-antimony {
|
|
||||||
background-color: #a47e3c;
|
|
||||||
}
|
|
||||||
.badge-arsenic {
|
|
||||||
background-color: #a47e3c;
|
|
||||||
}
|
|
||||||
.badge-bismuth {
|
|
||||||
background-color: #a47e3c;
|
|
||||||
}
|
|
||||||
|
|
||||||
.row-content {
|
.row-content {
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
|
|
|
@ -18,42 +18,15 @@
|
||||||
|
|
||||||
|
|
||||||
rootdir = '/com/github/GradienceTeam/Gradience'
|
rootdir = '/com/github/GradienceTeam/Gradience'
|
||||||
|
pkgdatadir = '@PKGDATA_DIR@'
|
||||||
|
localedir = '@LOCALE_DIR@'
|
||||||
|
|
||||||
app_id = '@APP_ID@'
|
app_id = '@APP_ID@'
|
||||||
rel_ver = '@RELEASE_VER@'
|
rel_ver = '@RELEASE_VER@'
|
||||||
version = '@VERSION@'
|
version = '@VERSION@'
|
||||||
build_type = '@BUILD_TYPE@'
|
build_type = '@BUILD_TYPE@'
|
||||||
|
|
||||||
project_url = '@PROJECT_URL@'
|
project_url = '@PROJECT_URL@'
|
||||||
bugtracker_url = '@BUGTRACKER_URL@'
|
bugtracker_url = '@BUGTRACKER_URL@'
|
||||||
help_url = '@HELP_URL@'
|
help_url = '@HELP_URL@'
|
||||||
translate_url = '@TRANSLATE_URL@'
|
translate_url = '@TRANSLATE_URL@'
|
||||||
pkgdatadir = '@PKGDATA_DIR@'
|
|
||||||
localedir = '@LOCALE_DIR@'
|
|
||||||
BADGE_COLORS = [
|
|
||||||
"blue",
|
|
||||||
"green",
|
|
||||||
"orange",
|
|
||||||
"purple",
|
|
||||||
"red",
|
|
||||||
"yellow",
|
|
||||||
"black",
|
|
||||||
"white",
|
|
||||||
"brown",
|
|
||||||
"pink",
|
|
||||||
"gray",
|
|
||||||
"silver",
|
|
||||||
"gold",
|
|
||||||
"copper",
|
|
||||||
"bronze",
|
|
||||||
"iron",
|
|
||||||
"steel",
|
|
||||||
"tin",
|
|
||||||
"aluminium",
|
|
||||||
"cobalt",
|
|
||||||
"titanium",
|
|
||||||
"platinium",
|
|
||||||
"lead",
|
|
||||||
"mercury",
|
|
||||||
"uranium",
|
|
||||||
"antimony",
|
|
||||||
"arsenic",
|
|
||||||
]
|
|
||||||
|
|
|
@ -19,9 +19,13 @@
|
||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
from gi.repository import Gtk, Gdk, Gio, Adw, GLib, Xdp, XdpGtk4
|
import threading
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
from material_color_utilities_python import *
|
from material_color_utilities_python import *
|
||||||
|
|
||||||
|
from gi.repository import Gtk, Gdk, Gio, Adw, GLib, Xdp, XdpGtk4
|
||||||
|
|
||||||
from .settings_schema import settings_schema
|
from .settings_schema import settings_schema
|
||||||
from .window import GradienceMainWindow
|
from .window import GradienceMainWindow
|
||||||
from .app_type_dialog import GradienceAppTypeDialog
|
from .app_type_dialog import GradienceAppTypeDialog
|
||||||
|
@ -41,8 +45,6 @@ from .preferences import GradiencePreferencesWindow
|
||||||
from .modules.utils import to_slug_case, buglog
|
from .modules.utils import to_slug_case, buglog
|
||||||
from .plugins_list import GradiencePluginsList
|
from .plugins_list import GradiencePluginsList
|
||||||
from .presets_manager_window import GradiencePresetWindow
|
from .presets_manager_window import GradiencePresetWindow
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
from .modules.preset import Preset
|
from .modules.preset import Preset
|
||||||
|
|
||||||
|
|
||||||
|
@ -130,7 +132,7 @@ class GradienceApplication(Adw.Application):
|
||||||
self.create_action(
|
self.create_action(
|
||||||
"restore_color_scheme", self.show_restore_color_scheme_dialog
|
"restore_color_scheme", self.show_restore_color_scheme_dialog
|
||||||
)
|
)
|
||||||
self.create_action("manage_presets", self.manage_presets)
|
self.create_action("manage_presets", self.show_presets_manager)
|
||||||
|
|
||||||
self.create_action("reset_color_scheme",
|
self.create_action("reset_color_scheme",
|
||||||
self.show_reset_color_scheme_dialog)
|
self.show_reset_color_scheme_dialog)
|
||||||
|
@ -260,12 +262,15 @@ class GradienceApplication(Adw.Application):
|
||||||
_("Installed Presets"), custom_menu_section
|
_("Installed Presets"), custom_menu_section
|
||||||
)
|
)
|
||||||
|
|
||||||
def manage_presets(self, *args):
|
def show_presets_manager(self, *args):
|
||||||
presets = GradiencePresetWindow(self)
|
presets = GradiencePresetWindow(self)
|
||||||
presets.set_transient_for(self.win)
|
presets.set_transient_for(self.win)
|
||||||
presets.set_modal(True)
|
presets.set_modal(True)
|
||||||
presets.present()
|
presets.present()
|
||||||
|
|
||||||
|
add_rows_thread = threading.Thread(target=presets.add_explore_rows)
|
||||||
|
add_rows_thread.start()
|
||||||
|
|
||||||
def load_preset_from_css(self):
|
def load_preset_from_css(self):
|
||||||
try:
|
try:
|
||||||
variables, palette, custom_css = load_preset_from_css(
|
variables, palette, custom_css = load_preset_from_css(
|
||||||
|
|
|
@ -18,14 +18,12 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
|
import asyncio
|
||||||
|
import aiohttp
|
||||||
|
|
||||||
from .utils import to_slug_case, buglog
|
from .utils import to_slug_case, buglog
|
||||||
|
|
||||||
|
|
||||||
import aiohttp
|
|
||||||
import asyncio
|
|
||||||
|
|
||||||
|
|
||||||
PRESET_DIR = os.path.join(
|
PRESET_DIR = os.path.join(
|
||||||
os.environ.get("XDG_CONFIG_HOME", os.environ["HOME"] + "/.config"),
|
os.environ.get("XDG_CONFIG_HOME", os.environ["HOME"] + "/.config"),
|
||||||
"presets",
|
"presets",
|
||||||
|
@ -64,9 +62,6 @@ async def main(repo):
|
||||||
return preset_dict, url_list
|
return preset_dict, url_list
|
||||||
|
|
||||||
|
|
||||||
# TODO: Modify functions to be asynchronous
|
|
||||||
|
|
||||||
|
|
||||||
def fetch_presets(repo) -> [dict, list]:
|
def fetch_presets(repo) -> [dict, list]:
|
||||||
return asyncio.run(main(repo))
|
return asyncio.run(main(repo))
|
||||||
|
|
||||||
|
@ -86,14 +81,6 @@ async def _download_preset(name, repo_name, url) -> None:
|
||||||
|
|
||||||
data = json.dumps(raw)
|
data = json.dumps(raw)
|
||||||
|
|
||||||
print(
|
|
||||||
os.path.join(
|
|
||||||
PRESET_DIR,
|
|
||||||
repo_name,
|
|
||||||
to_slug_case(name) + ".json",
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(
|
with open(
|
||||||
os.path.join(
|
os.path.join(
|
||||||
|
@ -105,6 +92,7 @@ async def _download_preset(name, repo_name, url) -> None:
|
||||||
encoding="utf-8",
|
encoding="utf-8",
|
||||||
) as f:
|
) as f:
|
||||||
f.write(data)
|
f.write(data)
|
||||||
|
f.close()
|
||||||
except OSError as error:
|
except OSError as error:
|
||||||
buglog(f"Failed to write data to a file. Exc: {error}")
|
buglog(f"Failed to write data to a file. Exc: {error}")
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,7 @@ def global_save_keyfile(toast_overlay, settings, global_keyfile, filename, gtk_v
|
||||||
|
|
||||||
def create_gtk_user_override(toast_overlay, settings, gtk_ver):
|
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}")
|
buglog(f"override_dir: {override_dir}")
|
||||||
|
|
||||||
filename = GLib.build_filenamev([override_dir, "global"])
|
filename = GLib.build_filenamev([override_dir, "global"])
|
||||||
|
|
||||||
|
@ -178,7 +178,7 @@ def create_gtk_user_override(toast_overlay, settings, gtk_ver):
|
||||||
|
|
||||||
def remove_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}")
|
buglog(f"override_dir: {override_dir}")
|
||||||
|
|
||||||
filename = GLib.build_filenamev([override_dir, "global"])
|
filename = GLib.build_filenamev([override_dir, "global"])
|
||||||
|
|
||||||
|
@ -243,7 +243,7 @@ def remove_gtk_user_override(toast_overlay, settings, gtk_ver):
|
||||||
def create_gtk_global_override(toast_overlay, settings, gtk_ver):
|
def create_gtk_global_override(toast_overlay, settings, gtk_ver):
|
||||||
override_dir = GLib.build_filenamev(
|
override_dir = GLib.build_filenamev(
|
||||||
[get_system_flatpak_path(), "overrides"])
|
[get_system_flatpak_path(), "overrides"])
|
||||||
print(f"override_dir: {override_dir}")
|
buglog(f"override_dir: {override_dir}")
|
||||||
|
|
||||||
filename = GLib.build_filenamev([override_dir, "global"])
|
filename = GLib.build_filenamev([override_dir, "global"])
|
||||||
|
|
||||||
|
@ -323,7 +323,7 @@ def create_gtk_global_override(toast_overlay, settings, gtk_ver):
|
||||||
def remove_gtk_global_override(toast_overlay, settings, gtk_ver):
|
def remove_gtk_global_override(toast_overlay, settings, gtk_ver):
|
||||||
override_dir = GLib.build_filenamev(
|
override_dir = GLib.build_filenamev(
|
||||||
[get_system_flatpak_path(), "overrides"])
|
[get_system_flatpak_path(), "overrides"])
|
||||||
print(f"override_dir: {override_dir}")
|
buglog(f"override_dir: {override_dir}")
|
||||||
|
|
||||||
filename = GLib.build_filenamev([override_dir, "global"])
|
filename = GLib.build_filenamev([override_dir, "global"])
|
||||||
|
|
||||||
|
|
|
@ -40,9 +40,6 @@ class Preset:
|
||||||
self.preset_path = preset_path
|
self.preset_path = preset_path
|
||||||
self.load_preset()
|
self.load_preset()
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
|
||||||
return f"Preset <{self.name}> with {self.variables}\n {self.palette}\n {self.custom_css}"
|
|
||||||
|
|
||||||
def load_preset(self, text=None, preset=None):
|
def load_preset(self, text=None, preset=None):
|
||||||
try:
|
try:
|
||||||
if not preset:
|
if not preset:
|
||||||
|
@ -118,5 +115,5 @@ class Preset:
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
p = Preset("test", "user")
|
p = Preset("test", "user")
|
||||||
print(p.variables)
|
buglog(p.variables)
|
||||||
print(p.palette)
|
buglog(p.palette)
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from random import choice
|
|
||||||
import shutil
|
import shutil
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
@ -31,7 +30,7 @@ from .explore_preset_row import GradienceExplorePresetRow
|
||||||
from .modules.custom_presets import fetch_presets
|
from .modules.custom_presets import fetch_presets
|
||||||
from .repo_row import GradienceRepoRow
|
from .repo_row import GradienceRepoRow
|
||||||
from .modules.utils import buglog
|
from .modules.utils import buglog
|
||||||
from .constants import rootdir, BADGE_COLORS
|
from .constants import rootdir
|
||||||
|
|
||||||
|
|
||||||
@Gtk.Template(resource_path=f"{rootdir}/ui/presets_manager_window.ui")
|
@Gtk.Template(resource_path=f"{rootdir}/ui/presets_manager_window.ui")
|
||||||
|
@ -68,6 +67,8 @@ class GradiencePresetWindow(Adw.Window):
|
||||||
|
|
||||||
search_results_list = []
|
search_results_list = []
|
||||||
|
|
||||||
|
offline = False
|
||||||
|
|
||||||
def __init__(self, parent, **kwargs):
|
def __init__(self, parent, **kwargs):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
|
@ -121,11 +122,24 @@ class GradiencePresetWindow(Adw.Window):
|
||||||
|
|
||||||
def setup_explore(self):
|
def setup_explore(self):
|
||||||
self.search_results_list.clear()
|
self.search_results_list.clear()
|
||||||
buglog("Preset list cleared")
|
|
||||||
|
|
||||||
offline = False
|
if self.offline:
|
||||||
|
self.search_spinner.props.visible = False
|
||||||
|
self.search_stack.set_visible_child_name("page_offline")
|
||||||
|
|
||||||
|
def add_explore_rows(self):
|
||||||
|
buglog(self._repos)
|
||||||
|
|
||||||
|
for repo_name, repo in self._repos.items():
|
||||||
|
self.search_string_list.append(repo_name)
|
||||||
|
|
||||||
|
if repo_name == "Official":
|
||||||
|
badge = "black"
|
||||||
|
elif repo_name == "Curated":
|
||||||
|
badge = "white"
|
||||||
|
else:
|
||||||
|
badge = "white"
|
||||||
|
|
||||||
def fetch(repo_name, repo, badge):
|
|
||||||
explore_presets, urls = fetch_presets(repo)
|
explore_presets, urls = fetch_presets(repo)
|
||||||
|
|
||||||
if explore_presets:
|
if explore_presets:
|
||||||
|
@ -140,20 +154,9 @@ class GradiencePresetWindow(Adw.Window):
|
||||||
self.search_results.append(row)
|
self.search_results.append(row)
|
||||||
self.search_results_list.append(row)
|
self.search_results_list.append(row)
|
||||||
else:
|
else:
|
||||||
offline = True
|
self.offline = True
|
||||||
|
self.search_spinner.props.visible = False
|
||||||
print(self._repos)
|
self.search_stack.set_visible_child_name("page_offline")
|
||||||
for repo_name, repo in self._repos.items():
|
|
||||||
self.search_string_list.append(repo_name)
|
|
||||||
badge_color = choice(BADGE_COLORS)
|
|
||||||
buglog(
|
|
||||||
f"Selected badge color: {badge_color} if it's look bad, please report it"
|
|
||||||
)
|
|
||||||
fetch(repo_name=repo_name, repo=repo, badge=badge_color)
|
|
||||||
|
|
||||||
if offline:
|
|
||||||
self.search_spinner.props.visible = False
|
|
||||||
self.search_stack.set_visible_child_name("page_offline")
|
|
||||||
|
|
||||||
def add_repo(self, _unused, response, name_entry, url_entry):
|
def add_repo(self, _unused, response, name_entry, url_entry):
|
||||||
if response == "add":
|
if response == "add":
|
||||||
|
@ -295,7 +298,7 @@ class GradiencePresetWindow(Adw.Window):
|
||||||
self.reload_pref_group()
|
self.reload_pref_group()
|
||||||
|
|
||||||
def reload_pref_group(self):
|
def reload_pref_group(self):
|
||||||
print("reload")
|
buglog("reload")
|
||||||
preset_directory = os.path.join(
|
preset_directory = os.path.join(
|
||||||
os.environ.get("XDG_CONFIG_HOME", os.environ["HOME"] + "/.config"),
|
os.environ.get("XDG_CONFIG_HOME", os.environ["HOME"] + "/.config"),
|
||||||
"presets",
|
"presets",
|
||||||
|
@ -368,8 +371,6 @@ class GradiencePresetWindow(Adw.Window):
|
||||||
self.installed.remove(self.preset_list)
|
self.installed.remove(self.preset_list)
|
||||||
self.installed.remove(self.builtin_preset_list)
|
self.installed.remove(self.builtin_preset_list)
|
||||||
|
|
||||||
print("reload 2")
|
|
||||||
|
|
||||||
self.builtin_preset_list = Adw.PreferencesGroup()
|
self.builtin_preset_list = Adw.PreferencesGroup()
|
||||||
self.builtin_preset_list.set_title(_("Built-in Presets"))
|
self.builtin_preset_list.set_title(_("Built-in Presets"))
|
||||||
for preset, preset_name in self.builtin_presets.items():
|
for preset, preset_name in self.builtin_presets.items():
|
||||||
|
@ -396,8 +397,6 @@ class GradiencePresetWindow(Adw.Window):
|
||||||
)
|
)
|
||||||
buglog(f"preset_check: {presets_check}")
|
buglog(f"preset_check: {presets_check}")
|
||||||
|
|
||||||
print("reload 3")
|
|
||||||
|
|
||||||
if presets_check:
|
if presets_check:
|
||||||
for repo, presets in self.custom_presets.items():
|
for repo, presets in self.custom_presets.items():
|
||||||
for preset, preset_name in presets.items():
|
for preset, preset_name in presets.items():
|
||||||
|
@ -414,7 +413,6 @@ class GradiencePresetWindow(Adw.Window):
|
||||||
)
|
)
|
||||||
self.preset_list.add(self.preset_empty)
|
self.preset_list.add(self.preset_empty)
|
||||||
self.installed.add(self.preset_list)
|
self.installed.add(self.preset_list)
|
||||||
print("reload end")
|
|
||||||
|
|
||||||
def reload_repos_group(self):
|
def reload_repos_group(self):
|
||||||
self.repos.remove(self.repos_list)
|
self.repos.remove(self.repos_list)
|
||||||
|
|
Loading…
Reference in a new issue