From 9c707affb39cadb5958d73b405b4cbc246510e54 Mon Sep 17 00:00:00 2001 From: Joshua Robinson Date: Sun, 14 Jul 2019 21:12:32 -0400 Subject: [PATCH 1/7] Adding gsettings backend for Gnome/Budgie --- blurwal/backends/gsettings.py | 64 +++++++++++++++++++++++++++++++++++ blurwal/environment.py | 11 ++++-- 2 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 blurwal/backends/gsettings.py diff --git a/blurwal/backends/gsettings.py b/blurwal/backends/gsettings.py new file mode 100644 index 0000000..3c64afa --- /dev/null +++ b/blurwal/backends/gsettings.py @@ -0,0 +1,64 @@ +""" +Author: Joshua Robinson +License: MIT +""" + +import logging +import pathlib +import subprocess +import sys +from typing import List, Optional + +from blurwal import x11 +from blurwal.backends import base + +def find_wallpaper_properties() -> List[str]: + """ + Return a list of properties that need to be set + + :param path: The image to set as the wallpaper + :return: A list of commands to be executed + """ + + return [] + +class GsettingsBackend(base.Backend): + """Wallpaper operations utilizing gnome/budgie's gsettings backend.""" + + def __init__(self): + x_conn = x11.XConnection() + self._primary_screen = x_conn.get_primary_output() + self._properties = find_wallpaper_properties() + logging.warning("Primary screen:" + self._primary_screen) + + def get_wallpaper_set_cmds(self, path: pathlib.Path) -> List[List[str]]: + """ + Return a list of commands to be executed to set the wallpaper. + + :param path: The image to set as the wallpaper + :return: A list of commands to be executed + """ + temp1 = str(path) + temp = [['gsettings', 'set', 'org.gnome.desktop.background', 'picture-uri', 'file://' + str(path)]] + logging.info(temp1) + logging.info(temp) + return temp + + def get_current(self) -> Optional[pathlib.Path]: + """ + Return the current wallpaper's path from gsettings + + :return: The current wallpaper's path (formatted for gsettings) or + None if not retrievable + """ + try: + process = subprocess.check_output(['gsettings', + 'get', + 'org.gnome.desktop.background', + 'picture-uri']) + + return pathlib.Path(process.strip().decode().replace("'file://", "", 1)[:-1]) + except subprocess.CalledProcessError: + logging.exception('Could not retrieve current wallpaper, call to' + 'gsettings returned a non-zero exit status.') + sys.exit(1) diff --git a/blurwal/environment.py b/blurwal/environment.py index cec4cb9..8997f1f 100644 --- a/blurwal/environment.py +++ b/blurwal/environment.py @@ -12,16 +12,21 @@ import shutil from typing import Dict, Optional, Tuple, Type from blurwal import paths, utils -from blurwal.backends import base, feh, xfconf +from blurwal.backends import base, feh, xfconf, gsettings #: Supported backend names with their implementation and binary BACKENDS: Dict[str, Tuple[Type[base.Backend], str]] = { 'feh': (feh.FehBackend, 'feh'), - 'xfce': (xfconf.XfconfBackend, 'xfconf-query') + 'xfce': (xfconf.XfconfBackend, 'xfconf-query'), + 'gnome': (gsettings.GsettingsBackend, 'gsettings') } #: A map of XDG_CURRENT_DESKTOP values to their respective backends -XDG_TO_BACKEND: Dict[str, str] = {'XFCE': 'xfce'} +XDG_TO_BACKEND: Dict[str, str] = { + 'XFCE': 'xfce', + 'Budgie:GNOME': 'gnome', + 'GNOME': 'gnome' +} def get_backend(name: Optional[str]) -> Optional[base.Backend]: -- GitLab From 1ee3020c4a1435706f52d5a470e7cb59ce50f88c Mon Sep 17 00:00:00 2001 From: Joshua Robinson Date: Sun, 14 Jul 2019 21:31:16 -0400 Subject: [PATCH 2/7] Fixed line length > 79 and incorrect comment --- blurwal/backends/gsettings.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/blurwal/backends/gsettings.py b/blurwal/backends/gsettings.py index 3c64afa..3c6d43b 100644 --- a/blurwal/backends/gsettings.py +++ b/blurwal/backends/gsettings.py @@ -48,7 +48,7 @@ class GsettingsBackend(base.Backend): """ Return the current wallpaper's path from gsettings - :return: The current wallpaper's path (formatted for gsettings) or + :return: The current wallpaper's path or None if not retrievable """ try: @@ -57,7 +57,9 @@ class GsettingsBackend(base.Backend): 'org.gnome.desktop.background', 'picture-uri']) - return pathlib.Path(process.strip().decode().replace("'file://", "", 1)[:-1]) + return pathlib.Path( + process.strip().decode().replace("'file://", "", 1)[:-1] + ) except subprocess.CalledProcessError: logging.exception('Could not retrieve current wallpaper, call to' 'gsettings returned a non-zero exit status.') -- GitLab From fee617ac756ccf0e293e2a318d3390fcb63abeda Mon Sep 17 00:00:00 2001 From: Joshua Robinson Date: Mon, 15 Jul 2019 01:34:08 +0000 Subject: [PATCH 3/7] Removed white space on empty line --- blurwal/backends/gsettings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blurwal/backends/gsettings.py b/blurwal/backends/gsettings.py index 3c6d43b..3cec2b5 100644 --- a/blurwal/backends/gsettings.py +++ b/blurwal/backends/gsettings.py @@ -56,7 +56,7 @@ class GsettingsBackend(base.Backend): 'get', 'org.gnome.desktop.background', 'picture-uri']) - + return pathlib.Path( process.strip().decode().replace("'file://", "", 1)[:-1] ) -- GitLab From cf3e681de8de0b8e70296bc2073d71a4aed0ec06 Mon Sep 17 00:00:00 2001 From: Joshua Robinson Date: Mon, 15 Jul 2019 13:48:03 +0000 Subject: [PATCH 4/7] Update blurwal/backends/gsettings.py --- blurwal/backends/gsettings.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/blurwal/backends/gsettings.py b/blurwal/backends/gsettings.py index 3cec2b5..574e4a1 100644 --- a/blurwal/backends/gsettings.py +++ b/blurwal/backends/gsettings.py @@ -38,11 +38,9 @@ class GsettingsBackend(base.Backend): :param path: The image to set as the wallpaper :return: A list of commands to be executed """ - temp1 = str(path) - temp = [['gsettings', 'set', 'org.gnome.desktop.background', 'picture-uri', 'file://' + str(path)]] - logging.info(temp1) - logging.info(temp) - return temp + return [['gsettings', + 'set', 'org.gnome.desktop.background', + 'picture-uri', 'file://' + str(path)]] def get_current(self) -> Optional[pathlib.Path]: """ -- GitLab From a5bae7e0b8450cd16ff6666c4300b472d1b26d19 Mon Sep 17 00:00:00 2001 From: Joshua Robinson Date: Tue, 20 Oct 2020 09:49:16 -0400 Subject: [PATCH 5/7] Updated gsettings.py for merge requirements --- blurwal/backends/gsettings.py | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/blurwal/backends/gsettings.py b/blurwal/backends/gsettings.py index 574e4a1..06ec19c 100644 --- a/blurwal/backends/gsettings.py +++ b/blurwal/backends/gsettings.py @@ -12,25 +12,9 @@ from typing import List, Optional from blurwal import x11 from blurwal.backends import base -def find_wallpaper_properties() -> List[str]: - """ - Return a list of properties that need to be set - - :param path: The image to set as the wallpaper - :return: A list of commands to be executed - """ - - return [] - class GsettingsBackend(base.Backend): """Wallpaper operations utilizing gnome/budgie's gsettings backend.""" - def __init__(self): - x_conn = x11.XConnection() - self._primary_screen = x_conn.get_primary_output() - self._properties = find_wallpaper_properties() - logging.warning("Primary screen:" + self._primary_screen) - def get_wallpaper_set_cmds(self, path: pathlib.Path) -> List[List[str]]: """ Return a list of commands to be executed to set the wallpaper. @@ -46,7 +30,7 @@ class GsettingsBackend(base.Backend): """ Return the current wallpaper's path from gsettings - :return: The current wallpaper's path or + :return: The current wallpaper's path (formatted for gsettings) or None if not retrievable """ try: @@ -55,9 +39,9 @@ class GsettingsBackend(base.Backend): 'org.gnome.desktop.background', 'picture-uri']) - return pathlib.Path( - process.strip().decode().replace("'file://", "", 1)[:-1] - ) + filepath = process.strip().decode().replace("'file://", "", 1)[:-1] + + return pathlib.Path(filepath) except subprocess.CalledProcessError: logging.exception('Could not retrieve current wallpaper, call to' 'gsettings returned a non-zero exit status.') -- GitLab From a410efa6320479b5503a0cb5acd3b1cbd472ccbb Mon Sep 17 00:00:00 2001 From: Joshua Robinson Date: Tue, 20 Oct 2020 09:56:05 -0400 Subject: [PATCH 6/7] Attempting to fix linting errors --- blurwal/backends/gsettings.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/blurwal/backends/gsettings.py b/blurwal/backends/gsettings.py index 06ec19c..17213d2 100644 --- a/blurwal/backends/gsettings.py +++ b/blurwal/backends/gsettings.py @@ -9,11 +9,12 @@ import subprocess import sys from typing import List, Optional -from blurwal import x11 from blurwal.backends import base class GsettingsBackend(base.Backend): - """Wallpaper operations utilizing gnome/budgie's gsettings backend.""" + """ + Wallpaper operations utilizing gnome/budgie's gsettings backend. + """ def get_wallpaper_set_cmds(self, path: pathlib.Path) -> List[List[str]]: """ @@ -23,7 +24,7 @@ class GsettingsBackend(base.Backend): :return: A list of commands to be executed """ return [['gsettings', - 'set', 'org.gnome.desktop.background', + 'set', 'org.gnome.desktop.background', 'picture-uri', 'file://' + str(path)]] def get_current(self) -> Optional[pathlib.Path]: -- GitLab From 5e141fd3280ec08de39690431800988808e70106 Mon Sep 17 00:00:00 2001 From: Joshua Robinson Date: Tue, 20 Oct 2020 10:00:26 -0400 Subject: [PATCH 7/7] More linting fixes I hope --- blurwal/backends/gsettings.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/blurwal/backends/gsettings.py b/blurwal/backends/gsettings.py index 17213d2..bb169e3 100644 --- a/blurwal/backends/gsettings.py +++ b/blurwal/backends/gsettings.py @@ -11,6 +11,7 @@ from typing import List, Optional from blurwal.backends import base + class GsettingsBackend(base.Backend): """ Wallpaper operations utilizing gnome/budgie's gsettings backend. @@ -25,7 +26,7 @@ class GsettingsBackend(base.Backend): """ return [['gsettings', 'set', 'org.gnome.desktop.background', - 'picture-uri', 'file://' + str(path)]] + 'picture-uri', 'file://' + str(path)]] def get_current(self) -> Optional[pathlib.Path]: """ @@ -36,9 +37,9 @@ class GsettingsBackend(base.Backend): """ try: process = subprocess.check_output(['gsettings', - 'get', - 'org.gnome.desktop.background', - 'picture-uri']) + 'get', + 'org.gnome.desktop.background', + 'picture-uri']) filepath = process.strip().decode().replace("'file://", "", 1)[:-1] -- GitLab