feat: kde fixes, icon, logging

This commit is contained in:
Kat Inskip 2024-02-05 19:28:12 -08:00
parent bfb74c7aca
commit a461bf400f
Signed by: kat
GPG key ID: 465E64DECEA8CF0F
5 changed files with 64 additions and 15 deletions

View file

@ -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])
image_list_string = "[" + ",".join(quote(p) for p in files) + "]"
script = SCRIPT_ALL.replace("IMAGE_LIST", image_list_string)
plasma_dbus().evaluateScript(script)

View file

@ -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,

BIN
konawall/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

View file

@ -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;

View file

@ -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",