Fix wallpaper script

This commit is contained in:
Michael Bradley 2025-10-07 18:03:10 -04:00
parent f32eedec8f
commit b805a0c3fe
Signed by: MichaelBradley
SSH key fingerprint: SHA256:BKO2eI2LPsCbQS3n3i5SdwZTAIV3F1lHezR07qP+Ob0

View file

@ -8,8 +8,7 @@ from pathlib import Path
from random import sample
from re import Pattern, compile, match
from subprocess import run
from time import sleep
from typing import cast, override
from typing import cast, override, Self
from .evening import on_steam, sunup_amount
@ -47,6 +46,7 @@ class Background(ABC):
class Wallpaper(Background):
_cache: Path = Path(environ["XDG_CACHE_HOME"]) / "wallpaper_blue_light.json"
_wallpapers: Path = Path("~/Pictures/wallpapers/").expanduser()
_ignore_dirs: tuple[str, ...] = ("ignore", ".stfolder")
def __init__(self, image: Path) -> None:
self._path: Path = image
@ -74,12 +74,12 @@ class Wallpaper(Background):
@classmethod
def _files(cls) -> Iterator[Path]:
for (root, _, files) in cls._wallpapers.walk():
if root.name != "ignore":
if root.name not in cls._ignore_dirs:
for file in files:
yield root / file
@classmethod
def available(cls) -> "OrderedSet[Background]":
def available(cls) -> OrderedSet[Background]:
cache = cls._read_cache()
modified = False
wallpapers = {str(path): Wallpaper(path) for path in cls._files()}
@ -87,7 +87,11 @@ class Wallpaper(Background):
cached = cache.get(str(wallpaper._path))
if cached is None or isnan(cached):
print("New file:", wallpaper._path)
cached = wallpaper._calculate_blue_light()
try:
cached = wallpaper._calculate_blue_light()
except Exception as e:
print(e)
continue
modified = True
cache[str(wallpaper._path)] = cached
wallpaper._blue_light = cached
@ -158,7 +162,7 @@ def _swww_cmd(*args: str) -> str:
class Monitor:
_query: Pattern[str] = compile(r"^([^:]+): (\d+)x(\d+), scale: ([\d.]+), currently displaying: (?:image|color): (.+)$")
_query: Pattern[str] = compile(r"^(?:: )?([^:]+): (\d+)x(\d+), scale: ([\d.]+), currently displaying: (?:image|color): (.+)$")
_transition_args: list[str] = [
"--transition-type=wipe",
"--transition-angle=30",
@ -185,7 +189,7 @@ class Monitor:
return self._background
@classmethod
def current(cls) -> "list[Monitor]":
def current(cls) -> list[Self]:
return [Monitor(line) for line in _swww_cmd("query").splitlines()]
@override
@ -221,4 +225,3 @@ def main(check_steam: bool = False) -> None:
for monitor, wallpaper in zip(monitors, sample(select_wallpapers(list(wallpapers.keys())), len(monitors))):
monitor.set_wallpaper(wallpaper)
sleep(1.25)