From 2b409fe71b4c840a02e2b8d739a44c233c960514 Mon Sep 17 00:00:00 2001 From: l0drex Date: Wed, 17 Apr 2024 23:18:36 +0200 Subject: [PATCH 1/5] Use env before installing --- scripts/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install.sh b/scripts/install.sh index ee62edf..c07d8ab 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -17,8 +17,8 @@ echo "Installing dependencies …" # Tell Poetry not to use a keyring export PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring # create virtual environment and install packages -poetry install --sync poetry env use python +poetry install --sync poetry build pip install ./dist/yin_yang-*-py3-none-any.whl From 04f7d81a56c8c04290e2d31a8e577beaa425ff2a Mon Sep 17 00:00:00 2001 From: l0drex Date: Thu, 18 Apr 2024 10:44:36 +0200 Subject: [PATCH 2/5] Refactor gtk available_themes property --- yin_yang/plugins/_plugin.py | 19 ++++++++++++++++++- yin_yang/plugins/gtk.py | 15 ++------------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/yin_yang/plugins/_plugin.py b/yin_yang/plugins/_plugin.py index d7469d2..de7abd7 100644 --- a/yin_yang/plugins/_plugin.py +++ b/yin_yang/plugins/_plugin.py @@ -4,7 +4,7 @@ from abc import ABC, abstractmethod from configparser import ConfigParser from pathlib import Path -from typing import Optional +from typing import Optional, List from PySide6.QtDBus import QDBusConnection, QDBusMessage from PySide6.QtGui import QColor, QRgba64 @@ -365,3 +365,20 @@ def flatpak_user(app_id: str) -> Path: def snap_path(app: str) -> Path: return Path(f'/var/lib/snapd/snap/{app}/current') + +def themes_from_theme_directories(type: str) -> List[Path]: + theme_directories = [ + Path('/usr/share/themes'), + Path('/usr/local/share/themes'), + Path.home() / '.themes', + Path.home() / '.local/share/themes', + ] + + themes = [] + for directory in theme_directories: + if not directory.is_dir(): + continue + + themes.extend(d.name for d in directory.iterdir() if d.is_dir() and (d / type).is_dir()) + + return themes diff --git a/yin_yang/plugins/gtk.py b/yin_yang/plugins/gtk.py index 1a5eb20..89ba084 100755 --- a/yin_yang/plugins/gtk.py +++ b/yin_yang/plugins/gtk.py @@ -5,16 +5,13 @@ from PySide6.QtDBus import QDBusMessage -from ._plugin import PluginDesktopDependent, PluginCommandline, DBusPlugin +from ._plugin import PluginDesktopDependent, PluginCommandline, DBusPlugin, themes_from_theme_directories from .system import test_gnome_availability from ..meta import Desktop logger = logging.getLogger(__name__) -theme_directories = ['/usr/share/themes', f'{Path.home()}/.themes'] - - class Gtk(PluginDesktopDependent): name = 'GTK' @@ -40,15 +37,7 @@ def __init__(self, desktop: Desktop): @property def available_themes(self) -> dict: - themes = [] - - for directory in theme_directories: - if not path.isdir(directory): - continue - - with scandir(directory) as entries: - themes.extend(d.name for d in entries if d.is_dir() and path.isdir(d.path + '/gtk-3.0')) - + themes = themes_from_theme_directories('gtk-3.0') return {t: t for t in themes} From 97e9e8cc9e62bea3a6ece7d54f515a2b51cbc8c7 Mon Sep 17 00:00:00 2001 From: l0drex Date: Sun, 14 Apr 2024 17:26:01 +0200 Subject: [PATCH 3/5] Add support for xfce --- yin_yang/plugins/system.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/yin_yang/plugins/system.py b/yin_yang/plugins/system.py index c58bb14..ce24523 100644 --- a/yin_yang/plugins/system.py +++ b/yin_yang/plugins/system.py @@ -7,9 +7,10 @@ from pathlib import Path from PySide6.QtCore import QLocale +from PySide6.QtDBus import QDBusMessage, QDBusVariant from ..meta import Desktop -from ._plugin import PluginDesktopDependent, PluginCommandline +from ._plugin import PluginDesktopDependent, PluginCommandline, themes_from_theme_directories, DBusPlugin logger = logging.getLogger(__name__) @@ -33,6 +34,8 @@ def __init__(self, desktop: Desktop): super().__init__(_Cinnamon()) case Desktop.BUDGIE: super().__init__(_Budgie()) + case Desktop.XFCE: + super().__init__(_Xfce()) case _: super().__init__(None) @@ -209,3 +212,22 @@ def __init__(self): @property def available(self) -> bool: return test_gnome_availability(self.command) + + +class _Xfce(DBusPlugin): + def create_message(self, theme: str) -> QDBusMessage: + message = QDBusMessage.createMethodCall( + 'org.xfce.Xfconf', + '/org/xfce/Xfconf', + 'org.xfce.Xfconf', + 'SetProperty' + ) + theme_variant = QDBusVariant() + theme_variant.setVariant(theme) + message.setArguments(['xfwm4', '/general/theme', theme_variant]) + return message + + @property + def available_themes(self) -> dict: + themes = themes_from_theme_directories('xfwm4') + return {t: t for t in themes} From cf2a4d3cf350913cfb2e93b7d78bc52d63ae0499 Mon Sep 17 00:00:00 2001 From: l0drex Date: Thu, 18 Apr 2024 21:56:42 +0200 Subject: [PATCH 4/5] Use dbus for notifications --- yin_yang/NotificationHandler.py | 31 ++++++++++++++++++++++++++++--- yin_yang/plugins/notify.py | 13 +++++++++---- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/yin_yang/NotificationHandler.py b/yin_yang/NotificationHandler.py index 1751a82..e001d76 100644 --- a/yin_yang/NotificationHandler.py +++ b/yin_yang/NotificationHandler.py @@ -1,9 +1,34 @@ -import subprocess from logging import Handler +from PySide6.QtDBus import QDBusMessage, QDBusConnection + + +def create_dbus_message(title: str, body: str): + message = QDBusMessage.createMethodCall( + 'org.freedesktop.portal.Desktop', + '/org/freedesktop/portal/desktop', + 'org.freedesktop.portal.Notification', + 'AddNotification' + ) + + notification = { + 'title': title, + 'body': body, + 'icon': 'yin_yang', + 'priority': 'low', + } + + message.setArguments([ + 'YingYang.ThemeChanged', + notification + ]) + + return message + class NotificationHandler(Handler): """Shows logs as notifications""" def emit(self, record): - subprocess.call(['notify-send', record.levelname, str(record.msg), - '-a', 'Yin & Yang', '-u', 'low', '--icon', 'yin_yang']) + connection = QDBusConnection.sessionBus() + message = create_dbus_message(record.levelname, str(record.msg)) + connection.call(message) diff --git a/yin_yang/plugins/notify.py b/yin_yang/plugins/notify.py index 12707bb..03b9d37 100644 --- a/yin_yang/plugins/notify.py +++ b/yin_yang/plugins/notify.py @@ -1,9 +1,14 @@ -from ._plugin import PluginCommandline +from PySide6.QtDBus import QDBusMessage +from NotificationHandler import create_dbus_message +from ._plugin import DBusPlugin -class Notification(PluginCommandline): + +class Notification(DBusPlugin): def __init__(self): - super().__init__(['notify-send', 'Theme changed', 'Set the theme to {theme}', - '-a', 'Yin & Yang', '-u', 'low', '--icon', 'yin_yang']) + super().__init__() self.theme_light = 'Day' self.theme_dark = 'Night' + + def create_message(self, theme: str) -> QDBusMessage: + return create_dbus_message('Theme changed', f'Set the theme to {theme}') From 9188801d50b8346f42721e5763ac4902fed3171c Mon Sep 17 00:00:00 2001 From: l0drex Date: Thu, 18 Apr 2024 22:15:22 +0200 Subject: [PATCH 5/5] Fix import --- yin_yang/plugins/notify.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yin_yang/plugins/notify.py b/yin_yang/plugins/notify.py index 03b9d37..6184eeb 100644 --- a/yin_yang/plugins/notify.py +++ b/yin_yang/plugins/notify.py @@ -1,6 +1,6 @@ from PySide6.QtDBus import QDBusMessage -from NotificationHandler import create_dbus_message +from ..NotificationHandler import create_dbus_message from ._plugin import DBusPlugin