diff --git a/konawall/environments/kde.py b/konawall/environments/kde.py index e7bbd79..797beed 100644 --- a/konawall/environments/kde.py +++ b/konawall/environments/kde.py @@ -1,16 +1,55 @@ import subprocess +import dbus from konawall.module_loader import add_environment +# https://powersnail.com/2023/set-plasma-wallpaper/ + +SCRIPT_GET_DESKTOPS = """ +function getDesktops() { + return desktops() + .filter(d => d.screen != -1) + .sort((a, b) => screenGeometry(a.screen).left - screenGeometry(b.screen).left); +} +""" + +SCRIPT_SET_WALLPAPER = """ +function setWallpaper(desktop, path) { + desktop.wallpaperPlugin = "org.kde.image" + desktop.currentConfigGroup = Array("Wallpaper", "org.kde.image", "General") + desktop.writeConfig("Image", path) +} +""" + +SCRIPT_ALL = f""" +{SCRIPT_GET_DESKTOPS} +{SCRIPT_SET_WALLPAPER} +const imageList = IMAGE_LIST; +getDesktops().forEach((desktop, i) => setWallpaper(desktop, imageList[i % imageList.length])); +""" + + +SCRIPT_ONE = f""" +{SCRIPT_GET_DESKTOPS} +{SCRIPT_SET_WALLPAPER} +setWallpaper(getDesktops()[DESKTOP_ID], IMAGE); +""" """ This sets the wallpaper on KDE. """ + +def quote(s): + return "'" + s + "'" + +def plasma_dbus(): + bus = dbus.SessionBus() + plasma = dbus.Interface( + bus.get_object("org.kde.plasmashell", "/PlasmaShell"), dbus_interface="org.kde.PlasmaShell" + ) + return plasma + + @add_environment("kde_setter") def set_wallpapers(files: list, displays: list): - for file in files: - kde_script = f""" - for (const desktop of desktops()) {{ - desktop.currentConfigGroup = ["Wallpaper", "org.kde.image", "General"] - desktop.writeConfig("Image", "{file}") - }} - """ - subprocess.run(["qdbus", "org.kde.plasmashell", "/PlasmaShell", "org.kde.PlasmaShell.evaluateScript", kde_script]) \ No newline at end of file + image_list_string = "[" + ",".join(quote(p) for p in files) + "]" + script = SCRIPT_ALL.replace("IMAGE_LIST", image_list_string) + plasma_dbus().evaluateScript(script) \ No newline at end of file diff --git a/konawall/gui.py b/konawall/gui.py index ca58520..4df3fef 100755 --- a/konawall/gui.py +++ b/konawall/gui.py @@ -70,10 +70,7 @@ class Konawall(wx.adv.TaskBarIcon): height = 128 # Missing texture style, magenta and black checkerboard - image = Image.new('RGB', (width, height), (0, 0, 0)) - dc = ImageDraw.Draw(image) - dc.rectangle((0, 0, width//2, height//2), fill=(255, 0, 255)) - dc.rectangle((width//2, height//2, width, height), fill=(255, 0, 255)) + image = Image.open(os.path.join(os.path.dirname(__file__), 'icon.png')) if "wxMSW" in wx.PlatformInfo: image = image.resize((16, 16)) elif "wxGTK" in wx.PlatformInfo: @@ -331,7 +328,18 @@ def main(): except: version = "testing version" - file_logger = logging.FileHandler("app.log", mode="a") + if wx.Platform == "__WXGTK__": + from xdg_base_dirs import xdg_config_home + log_path = os.path.join(xdg_config_home(), "konawall", "log.toml") + if wx.Platform == "__WXMAC__": + log_path_string = "~/Library/Application Support/konawall/log.toml" + log_path = os.path.expanduser(log_path_string) + elif wx.Platform == "__WXMSW__": + log_path_string = "%APPDATA%\\konawall\\log.toml" + log_path = os.path.expandvars(log_path_string) + else: + log_path = os.path.join(os.path.expanduser("~"), ".config", "konawall", "log.toml") + file_logger = logging.FileHandler(log_path, mode="a") console_logger = logging.StreamHandler() logging.basicConfig( level=logging.DEBUG, diff --git a/konawall/icon.png b/konawall/icon.png new file mode 100644 index 0000000..a21660e Binary files /dev/null and b/konawall/icon.png differ diff --git a/package.nix b/package.nix index 5bd3f02..8e151db 100644 --- a/package.nix +++ b/package.nix @@ -18,7 +18,7 @@ in doCheck = false; propagatedBuildInputs = let - dependencyNames = lib.attrNames poetryBlock.dependencies; + dependencyNames = (lib.attrNames poetryBlock.dependencies) ++ ["dbus-python"]; dependencies = map (name: python311Packages.${name} or dependencyReplacements.${name}) dependencyNames; in dependencies; diff --git a/setup.py b/setup.py index 92639b3..9e4e7b0 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,4 @@ -from setuptools import setup +from setuptools import setup, find_packages with open("README.MD", "r") as f: long_description = f.read() @@ -16,6 +16,8 @@ setup( author_email = poetryBlock["authors"][0].split(" <")[1][:-1], description = poetryBlock["description"], long_description = long_description, + package_data={'': ['*.png', '*.jpg', '*.jpeg', '*.gif', '*.bmp', '*.tiff', '*.webp']}, + include_package_data=True, entry_points = { "console_scripts": [ "konawall = konawall.gui:main",