mirror of
https://github.com/GradienceTeam/Gradience.git
synced 2024-08-23 07:52:32 +00:00
fix: window freez when delete
This commit is contained in:
parent
94e7111c4e
commit
06b848a1c3
6 changed files with 151 additions and 121 deletions
|
@ -8,7 +8,7 @@ template GradiencePluginRow : Adw.ActionRow {
|
||||||
tooltip-text: _("Enable plugin");
|
tooltip-text: _("Enable plugin");
|
||||||
state-set => on_switch_toggled();
|
state-set => on_switch_toggled();
|
||||||
}
|
}
|
||||||
|
|
||||||
[suffix]
|
[suffix]
|
||||||
Button settings-button {
|
Button settings-button {
|
||||||
valign: center;
|
valign: center;
|
||||||
|
@ -26,4 +26,4 @@ template GradiencePluginRow : Adw.ActionRow {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,41 +1,98 @@
|
||||||
using Gtk 4.0;
|
using Gtk 4.0;
|
||||||
using Adw 1;
|
using Adw 1;
|
||||||
|
|
||||||
|
Popover pop_actions {
|
||||||
|
styles [
|
||||||
|
"menu",
|
||||||
|
]
|
||||||
|
|
||||||
|
Box {
|
||||||
|
orientation: vertical;
|
||||||
|
margin-top: 6;
|
||||||
|
margin-bottom: 6;
|
||||||
|
margin-start: 6;
|
||||||
|
margin-end: 6;
|
||||||
|
|
||||||
|
|
||||||
|
Button remove_button {
|
||||||
|
valign: center;
|
||||||
|
label: _("Remove preset");
|
||||||
|
tooltip-text: _("Remove preset");
|
||||||
|
clicked => on_remove_button_clicked();
|
||||||
|
}
|
||||||
|
|
||||||
|
Separator {
|
||||||
|
}
|
||||||
|
|
||||||
|
.GtkModelButton btn_report {
|
||||||
|
text: _("Report a Bug…");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template GradiencePresetRow : Adw.ActionRow {
|
template GradiencePresetRow : Adw.ActionRow {
|
||||||
[suffix]
|
Box {
|
||||||
Stack value_stack {
|
spacing: 6;
|
||||||
valign: center;
|
|
||||||
hhomogeneous: false;
|
|
||||||
interpolate-size: true;
|
|
||||||
transition-type: crossfade;
|
|
||||||
|
|
||||||
Button apply_button {
|
Label label_grade {
|
||||||
valign: center;
|
valign: center;
|
||||||
icon-name: "checkmark-small-symbolic";
|
label: _("Unknown");
|
||||||
tooltip-text: _("Apply preset");
|
|
||||||
clicked => on_apply_button_clicked();
|
styles [
|
||||||
|
"tag",
|
||||||
|
"caption",
|
||||||
|
]
|
||||||
}
|
}
|
||||||
Entry name_entry {
|
|
||||||
text: "Name";
|
Separator {
|
||||||
changed => on_name_entry_changed();
|
margin-top: 12;
|
||||||
|
margin-bottom: 12;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
[suffix]
|
Stack value_stack {
|
||||||
ToggleButton name_entry_toggle {
|
valign: center;
|
||||||
valign: center;
|
hhomogeneous: false;
|
||||||
icon-name: "document-edit-symbolic";
|
interpolate-size: true;
|
||||||
tooltip-text: _("Edit preset name");
|
transition-type: crossfade;
|
||||||
|
|
||||||
|
Button apply_button {
|
||||||
|
valign: center;
|
||||||
|
icon-name: "checkmark-small-symbolic";
|
||||||
|
tooltip-text: _("Apply preset");
|
||||||
|
clicked => on_apply_button_clicked();
|
||||||
|
styles [
|
||||||
|
"flat",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
Entry name_entry {
|
||||||
|
text: "Name";
|
||||||
|
changed => on_name_entry_changed();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ToggleButton name_entry_toggle {
|
||||||
|
valign: center;
|
||||||
|
icon-name: "document-edit-symbolic";
|
||||||
|
tooltip-text: _("Edit preset name");
|
||||||
|
|
||||||
|
toggled => on_name_entry_toggled();
|
||||||
|
|
||||||
|
styles [
|
||||||
|
"flat",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
MenuButton {
|
||||||
|
valign: center;
|
||||||
|
popover: pop_actions;
|
||||||
|
icon-name: "view-more-symbolic";
|
||||||
|
|
||||||
|
styles [
|
||||||
|
"flat",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
toggled => on_name_entry_toggled();
|
|
||||||
}
|
|
||||||
|
|
||||||
[suffix]
|
|
||||||
Button remove_button {
|
|
||||||
valign: center;
|
|
||||||
icon-name: "edit-delete-symbolic";
|
|
||||||
tooltip-text: _("Remove preset");
|
|
||||||
clicked => on_remove_button_clicked();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,11 @@ import aiohttp
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
|
|
||||||
|
PRESET_DIR = os.path.join(
|
||||||
|
os.environ.get("XDG_CONFIG_HOME", os.environ["HOME"] + "/.config"),
|
||||||
|
"presets",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def main(repo):
|
async def main(repo):
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
|
@ -81,12 +86,16 @@ 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(
|
||||||
os.environ.get("XDG_CONFIG_HOME",
|
PRESET_DIR,
|
||||||
os.environ["HOME"] + "/.config"),
|
|
||||||
"presets",
|
|
||||||
repo_name,
|
repo_name,
|
||||||
to_slug_case(name) + ".json",
|
to_slug_case(name) + ".json",
|
||||||
),
|
),
|
||||||
|
@ -94,7 +103,6 @@ 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}")
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,8 @@ class Preset:
|
||||||
"gtk3": "",
|
"gtk3": "",
|
||||||
}
|
}
|
||||||
plugins = {}
|
plugins = {}
|
||||||
|
repo = "user"
|
||||||
|
name = "new_preset"
|
||||||
|
|
||||||
def __init__(self, name=None, repo=None, preset_path=None, text=None, preset=None):
|
def __init__(self, name=None, repo=None, preset_path=None, text=None, preset=None):
|
||||||
if text: # load from ressource
|
if text: # load from ressource
|
||||||
|
@ -26,13 +28,9 @@ class Preset:
|
||||||
self.load_preset(preset=preset)
|
self.load_preset(preset=preset)
|
||||||
else:
|
else:
|
||||||
self.preset_name = name
|
self.preset_name = name
|
||||||
if name is None:
|
if name is not None:
|
||||||
self.name = "new_preset"
|
|
||||||
else:
|
|
||||||
self.name = to_slug_case(name)
|
self.name = to_slug_case(name)
|
||||||
if repo is None:
|
if repo is not None:
|
||||||
self.repo = "user"
|
|
||||||
else:
|
|
||||||
self.repo = repo
|
self.repo = repo
|
||||||
if preset_path is None:
|
if preset_path is None:
|
||||||
self.preset_path = os.path.join(PRESET_DIR, repo, self.name + ".json")
|
self.preset_path = os.path.join(PRESET_DIR, repo, self.name + ".json")
|
||||||
|
@ -70,6 +68,10 @@ class Preset:
|
||||||
buglog(error, " -> preset : ", self.preset_path)
|
buglog(error, " -> preset : ", self.preset_path)
|
||||||
|
|
||||||
def save_preset(self, name=None, plugins_list=None, to=None):
|
def save_preset(self, name=None, plugins_list=None, to=None):
|
||||||
|
if to is None:
|
||||||
|
self.preset_path = os.path.join(PRESET_DIR, self.repo, self.name + ".json")
|
||||||
|
else:
|
||||||
|
self.preset_path = to
|
||||||
if not os.path.exists(
|
if not os.path.exists(
|
||||||
os.path.join(
|
os.path.join(
|
||||||
PRESET_DIR,
|
PRESET_DIR,
|
||||||
|
|
|
@ -21,9 +21,11 @@ import os
|
||||||
|
|
||||||
from gi.repository import Gtk, Adw
|
from gi.repository import Gtk, Adw
|
||||||
|
|
||||||
|
from gradience.modules.custom_presets import PRESET_DIR
|
||||||
|
|
||||||
from .constants import rootdir
|
from .constants import rootdir
|
||||||
from .modules.utils import to_slug_case, buglog
|
from .modules.utils import to_slug_case, buglog
|
||||||
|
from .modules.preset import Preset
|
||||||
|
|
||||||
@Gtk.Template(resource_path=f"{rootdir}/ui/preset_row.ui")
|
@Gtk.Template(resource_path=f"{rootdir}/ui/preset_row.ui")
|
||||||
class GradiencePresetRow(Adw.ActionRow):
|
class GradiencePresetRow(Adw.ActionRow):
|
||||||
|
@ -52,6 +54,8 @@ class GradiencePresetRow(Adw.ActionRow):
|
||||||
self.win = win
|
self.win = win
|
||||||
self.toast_overlay = self.win.toast_overlay
|
self.toast_overlay = self.win.toast_overlay
|
||||||
|
|
||||||
|
self.preset = Preset(name, repo_name)
|
||||||
|
|
||||||
apply_button = Gtk.Template.Child("apply_button")
|
apply_button = Gtk.Template.Child("apply_button")
|
||||||
rename_button = Gtk.Template.Child("rename_button")
|
rename_button = Gtk.Template.Child("rename_button")
|
||||||
|
|
||||||
|
@ -89,100 +93,53 @@ class GradiencePresetRow(Adw.ActionRow):
|
||||||
self.delete_toast = Adw.Toast(title=_("Preset removed"))
|
self.delete_toast = Adw.Toast(title=_("Preset removed"))
|
||||||
self.delete_toast.set_button_label(_("Undo"))
|
self.delete_toast.set_button_label(_("Undo"))
|
||||||
self.delete_toast.connect("dismissed", self.on_delete_toast_dismissed)
|
self.delete_toast.connect("dismissed", self.on_delete_toast_dismissed)
|
||||||
self.delete_toast.connect(
|
|
||||||
"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
|
self.win.old_name = self.name
|
||||||
|
|
||||||
self.do_delete_preset()
|
try:
|
||||||
|
os.rename(
|
||||||
self.win.reload_pref_group()
|
|
||||||
|
|
||||||
def update_value(self):
|
|
||||||
with open(
|
|
||||||
os.path.join(
|
|
||||||
os.environ.get("XDG_CONFIG_HOME",
|
|
||||||
os.environ["HOME"] + "/.config"),
|
|
||||||
"presets",
|
|
||||||
self.prefix,
|
|
||||||
to_slug_case(self.old_name) + ".json",
|
|
||||||
),
|
|
||||||
"r",
|
|
||||||
encoding="utf-8",
|
|
||||||
) as file:
|
|
||||||
preset_text = file.read()
|
|
||||||
preset = json.loads(preset_text)
|
|
||||||
|
|
||||||
preset_name = preset["name"]
|
|
||||||
variables = preset["variables"]
|
|
||||||
palette = preset["palette"]
|
|
||||||
if "custom_css" in preset:
|
|
||||||
custom_css = preset["custom_css"]
|
|
||||||
else:
|
|
||||||
custom_css = {
|
|
||||||
"gtk4": "",
|
|
||||||
"gtk3": "",
|
|
||||||
}
|
|
||||||
|
|
||||||
with open(
|
|
||||||
os.path.join(
|
|
||||||
os.environ.get("XDG_CONFIG_HOME",
|
|
||||||
os.environ["HOME"] + "/.config"),
|
|
||||||
"presets",
|
|
||||||
self.prefix,
|
|
||||||
to_slug_case(self.name) + ".json",
|
|
||||||
),
|
|
||||||
"w",
|
|
||||||
encoding="utf-8",
|
|
||||||
) as file:
|
|
||||||
object_to_write = {
|
|
||||||
"name": self.name,
|
|
||||||
"variables": variables,
|
|
||||||
"palette": palette,
|
|
||||||
"custom_css": custom_css,
|
|
||||||
}
|
|
||||||
file.write(json.dumps(object_to_write, indent=4))
|
|
||||||
os.remove(
|
|
||||||
os.path.join(
|
os.path.join(
|
||||||
os.environ.get("XDG_CONFIG_HOME",
|
os.environ.get(
|
||||||
os.environ["HOME"] + "/.config"),
|
"XDG_CONFIG_HOME", os.environ["HOME"] + "/.config"
|
||||||
|
),
|
||||||
"presets",
|
"presets",
|
||||||
self.prefix,
|
self.prefix,
|
||||||
to_slug_case(self.old_name) + ".json",
|
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",
|
||||||
|
),
|
||||||
)
|
)
|
||||||
self.old_name = self.name
|
print("rename")
|
||||||
|
self.set_name(self.name + "(" +_("Pending deletion") + ")")
|
||||||
def do_delete_preset(self):
|
print("renamed")
|
||||||
if self.delete_preset:
|
except Exception as exception:
|
||||||
try:
|
buglog(exception)
|
||||||
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:
|
|
||||||
buglog(exception)
|
|
||||||
finally:
|
|
||||||
self.win.reload_pref_group()
|
|
||||||
|
|
||||||
self.delete_preset = True
|
self.delete_preset = True
|
||||||
|
|
||||||
|
#self.win.reload_pref_group()
|
||||||
|
|
||||||
|
def update_value(self):
|
||||||
|
self.preset.preset_name = self.name
|
||||||
|
self.preset.name = to_slug_case(self.name)
|
||||||
|
self.preset.save_preset()
|
||||||
|
os.remove(
|
||||||
|
os.path.join(
|
||||||
|
PRESET_DIR,
|
||||||
|
self.prefix,
|
||||||
|
to_slug_case(self.old_name) + ".json",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self.old_name = self.name
|
||||||
|
|
||||||
def on_delete_toast_dismissed(self, widget):
|
def on_delete_toast_dismissed(self, widget):
|
||||||
if self.delete_preset:
|
if self.delete_preset:
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -279,6 +279,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")
|
||||||
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",
|
||||||
|
@ -348,6 +349,8 @@ 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(_("Builtin Presets"))
|
self.builtin_preset_list.set_title(_("Builtin Presets"))
|
||||||
for preset, preset_name in self.builtin_presets.items():
|
for preset, preset_name in self.builtin_presets.items():
|
||||||
|
@ -372,6 +375,8 @@ 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():
|
||||||
|
@ -387,6 +392,7 @@ 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