backend/globals: move plugin dir variables to globals module

* change parent variable naming in about_window to make it similar to dialogs
    * misc refactoring changes
This commit is contained in:
tfuxu 2023-01-03 15:07:41 +01:00
parent ae2efee174
commit 9f9a547634
No known key found for this signature in database
GPG key ID: 79CFC3B9B31C098A
7 changed files with 31 additions and 34 deletions

View file

@ -20,6 +20,8 @@ import os
from gi.repository import Xdp
from gradience.backend import constants
presets_dir = os.path.join(
os.environ.get("XDG_CONFIG_HOME", os.environ["HOME"] + "/.config"),
@ -31,6 +33,17 @@ preset_repos = {
"Curated": "https://github.com/GradienceTeam/Community/raw/next/curated.json"
}
user_plugin_dir = os.path.join(
os.environ.get("XDG_DATA_HOME", os.environ["HOME"] + "/.local/share"),
"gradience",
"plugins"
)
system_plugin_dir = os.path.join(
constants.pkgdatadir,
"plugins"
)
def get_gtk_theme_dir(app_type):
if app_type == "gtk4":
theme_dir = os.path.join(

View file

@ -17,7 +17,7 @@ configure_file(
'LOCALE_DIR': conf.get('LOCALE_DIR'),
}),
install: true,
install_dir: PY_INSTALLDIR.get_install_dir() / backenddir,
install_dir: PY_INSTALLDIR.get_install_dir() / backenddir
)
subdir('models')

View file

@ -1,6 +1,6 @@
## `frontend/` directory structure:
- `cli/` - frontend interface for command-line commands
- `cli/` - frontend interface for command-line commands
- `dialogs/` - message boxes and simple popup windows
- `utils/` - general purpose utility modules for UI related stuff
- `views/` - more extensive widgets (eg. widget groups, lists) and windows

View file

@ -74,9 +74,9 @@ yangyangdaji https://github.com/yangyangdaji
class GradienceAboutWindow:
def __init__(self, win):
self.win = win
self.app = self.win.get_application()
def __init__(self, parent):
self.parent = parent
self.app = self.parent.get_application()
self.setup()

View file

@ -22,25 +22,13 @@ from gi.repository import Adw, GLib
from yapsy.PluginManager import PluginManager
from gradience.frontend.widgets.plugin_row import GradiencePluginRow
from gradience.backend.constants import pkgdatadir
from gradience.backend.globals import user_plugin_dir, system_plugin_dir
from gradience.backend.logger import Logger
logging = Logger()
USER_PLUGIN_DIR = os.path.join(
os.environ.get("XDG_DATA_HOME", os.environ["HOME"] + "/.local/share"),
"gradience",
"plugins",
)
SYSTEM_PLUGIN_DIR = os.path.join(
pkgdatadir,
"plugins",
)
class GradiencePluginsList:
"""Represent the plugin group in Advanced"""
@ -60,7 +48,7 @@ class GradiencePluginsList:
def reload(self):
self.pm = PluginManager()
self.pm.setPluginPlaces([USER_PLUGIN_DIR, SYSTEM_PLUGIN_DIR])
self.pm.setPluginPlaces([user_plugin_dir, system_plugin_dir])
self.pm.collectPlugins()
for pluginInfo in self.pm.getAllPlugins():
pluginInfo.plugin_object.activate()
@ -86,8 +74,8 @@ class GradiencePluginsList:
@staticmethod
def check_if_plugin_dir_exists():
"""Check if the plugin directory exists, if not, create it"""
if not os.path.exists(USER_PLUGIN_DIR):
os.makedirs(USER_PLUGIN_DIR)
if not os.path.exists(user_plugin_dir):
os.makedirs(user_plugin_dir)
return False
return True

View file

@ -52,7 +52,6 @@ class GradiencePreferencesWindow(Adw.PreferencesWindow):
self.setup()
def setup(self):
self.setup_flatpak_group()
def setup_flatpak_group(self):

View file

@ -18,10 +18,10 @@
import os
from pathlib import Path
from gi.repository import Gtk, Adw
from gradience.frontend.dialogs.no_plugin_window import GradienceNoPluginPrefWindow
from gradience.backend.globals import user_plugin_dir
from gradience.backend.constants import rootdir
from gradience.backend.logger import Logger
@ -29,15 +29,6 @@ from gradience.backend.logger import Logger
logging = Logger()
USER_PLUGIN_DIR = Path(
os.path.join(
os.environ.get("XDG_DATA_HOME", os.environ["HOME"] + "/.local/share"),
"gradience",
"plugins",
)
)
@Gtk.Template(resource_path=f"{rootdir}/ui/plugin_row.ui")
class GradiencePluginRow(Adw.ActionRow):
__gtype_name__ = "GradiencePluginRow"
@ -53,7 +44,10 @@ class GradiencePluginRow(Adw.ActionRow):
self.plugin_object = plugin_object
if not os.path.exists(
USER_PLUGIN_DIR / f"{self.plugin_object.plugin_id}.yapsy-plugin"
os.path.join(
user_plugin_dir,
f"{self.plugin_object.plugin_id}.yapsy-plugin"
)
):
self.remove_button.set_visible(False)
@ -78,7 +72,10 @@ class GradiencePluginRow(Adw.ActionRow):
@Gtk.Template.Callback()
def on_remove_plugin_clicked(self, *_args):
plugin_yapsy_file = (
USER_PLUGIN_DIR / f"{self.plugin_object.plugin_id}.yapsy-plugin"
os.path.join(
user_plugin_dir,
f"{self.plugin_object.plugin_id}.yapsy-plugin"
)
)
logging.debug(f"remove {plugin_yapsy_file}")
try: