mirror of
https://github.com/anufrievroman/waypaper.git
synced 2024-08-16 11:40:44 +03:00
Removing errors when swaybg is not installed
This commit is contained in:
parent
0733122f82
commit
7d912f4dfb
@ -7,7 +7,7 @@ import argparse
|
||||
from waypaper.config import Config
|
||||
from waypaper.app import App
|
||||
from waypaper.changer import change_wallpaper
|
||||
from waypaper.common import get_random_file
|
||||
from waypaper.common import get_random_file, check_missing_backends
|
||||
from waypaper.aboutdata import AboutData
|
||||
from waypaper.options import FILL_OPTIONS, BACKEND_OPTIONS
|
||||
from waypaper.translations import English, German, French, Russian, Polish, Chinese
|
||||
@ -44,6 +44,7 @@ def run():
|
||||
"""Read user arguments and either run GUI app or just reset the wallpaper"""
|
||||
|
||||
cf.read_parameters_from_user_arguments(args)
|
||||
missing_backends = check_missing_backends()
|
||||
|
||||
# Set the wallpaper and quit:
|
||||
if args.restore:
|
||||
@ -54,7 +55,7 @@ def run():
|
||||
|
||||
if wallpaper is None:
|
||||
continue
|
||||
change_wallpaper(wallpaper, cf.fill_option, cf.color, cf.backend, monitor, cf.swww_transition, txt)
|
||||
change_wallpaper(wallpaper, cf, monitor, txt, missing_backends)
|
||||
time.sleep(0.1)
|
||||
exit(0)
|
||||
|
||||
|
@ -3,7 +3,6 @@
|
||||
import subprocess
|
||||
import threading
|
||||
import os
|
||||
import shutil
|
||||
import gi
|
||||
from pathlib import Path
|
||||
from platformdirs import user_cache_path
|
||||
@ -12,7 +11,7 @@ from PIL import Image
|
||||
from waypaper.aboutdata import AboutData
|
||||
from waypaper.changer import change_wallpaper
|
||||
from waypaper.config import Config
|
||||
from waypaper.common import get_image_paths, get_random_file
|
||||
from waypaper.common import get_image_paths, get_random_file, check_missing_backends
|
||||
from waypaper.options import FILL_OPTIONS, BACKEND_OPTIONS, SORT_OPTIONS, SORT_DISPLAYS
|
||||
|
||||
gi.require_version("Gtk", "3.0")
|
||||
@ -221,12 +220,7 @@ class App(Gtk.Window):
|
||||
|
||||
def check_backends(self):
|
||||
"""Before running the app, check which backends are installed"""
|
||||
self.missing_backends = []
|
||||
for backend in BACKEND_OPTIONS:
|
||||
if backend == "wallutils":
|
||||
backend = "setwallpaper"
|
||||
is_backend_missing = not bool(shutil.which(backend))
|
||||
self.missing_backends.append(is_backend_missing)
|
||||
self.missing_backends = check_missing_backends()
|
||||
|
||||
# Show error message if no backends are installed:
|
||||
if all(self.missing_backends):
|
||||
@ -411,8 +405,7 @@ class App(Gtk.Window):
|
||||
self.load_image_grid()
|
||||
print(self.txt.msg_path, self.cf.selected_wallpaper)
|
||||
self.cf.fill_option = self.fill_option_combo.get_active_text() or self.cf.fill_option
|
||||
change_wallpaper(self.cf.selected_wallpaper, self.cf.fill_option, self.cf.color,
|
||||
self.cf.backend, self.cf.selected_monitor, self.cf.swww_transition, self.txt)
|
||||
change_wallpaper(self.cf.selected_wallpaper, self.cf, self.cf.selected_monitor, self.txt, self.missing_backends)
|
||||
self.cf.save()
|
||||
|
||||
|
||||
@ -438,8 +431,7 @@ class App(Gtk.Window):
|
||||
return
|
||||
print(self.txt.msg_path, self.cf.selected_wallpaper)
|
||||
self.cf.fill_option = self.fill_option_combo.get_active_text() or self.cf.fill_option
|
||||
change_wallpaper(self.cf.selected_wallpaper, self.cf.fill_option, self.cf.color,
|
||||
self.cf.backend, self.cf.selected_monitor, self.cf.swww_transition, self.txt)
|
||||
change_wallpaper(self.cf.selected_wallpaper, self.cf, self.cf.selected_monitor, self.txt, self.missing_backends)
|
||||
self.cf.save()
|
||||
|
||||
|
||||
@ -506,8 +498,7 @@ class App(Gtk.Window):
|
||||
self.cf.selected_wallpaper = wallpaper_path
|
||||
print(self.txt.msg_path, self.cf.selected_wallpaper)
|
||||
self.cf.fill_option = self.fill_option_combo.get_active_text() or self.cf.fill_option
|
||||
change_wallpaper(self.cf.selected_wallpaper, self.cf.fill_option, self.cf.color,
|
||||
self.cf.backend, self.cf.selected_monitor, self.cf.swww_transition, self.txt)
|
||||
change_wallpaper(self.cf.selected_wallpaper, self.cf, self.cf.selected_monitor, self.txt, self.missing_backends)
|
||||
self.cf.save()
|
||||
|
||||
# Prevent other default key handling:
|
||||
|
@ -3,10 +3,17 @@
|
||||
import subprocess
|
||||
import time
|
||||
|
||||
from waypaper.options import BACKEND_OPTIONS
|
||||
|
||||
def change_wallpaper(image_path, fill_option, color, backend, monitor, transition, txt):
|
||||
|
||||
def change_wallpaper(image_path, cf, monitor, txt, missing_backends):
|
||||
"""Run a system command to change the wallpaper depending on the backend"""
|
||||
|
||||
fill_option = cf.fill_option
|
||||
color = cf.color
|
||||
backend = cf.backend
|
||||
swww_transition = cf.swww_transition
|
||||
|
||||
try:
|
||||
# swaybg backend:
|
||||
if backend == "swaybg":
|
||||
@ -34,16 +41,19 @@ def change_wallpaper(image_path, fill_option, color, backend, monitor, transitio
|
||||
"tile": "no",
|
||||
}
|
||||
fill = fill_types[fill_option.lower()]
|
||||
try:
|
||||
subprocess.Popen(["killall", "swaybg"])
|
||||
time.sleep(0.005)
|
||||
except Exception as e:
|
||||
print(f"{ERR_KILL} {e}")
|
||||
is_swaybg_installed = not missing_backends[BACKEND_OPTIONS.index("swaybg")]
|
||||
if is_swaybg_installed:
|
||||
try:
|
||||
subprocess.Popen(["killall", "swaybg"])
|
||||
time.sleep(0.005)
|
||||
except Exception as e:
|
||||
print(f"{ERR_KILL} {e}")
|
||||
print(missing_backends)
|
||||
subprocess.Popen(["swww", "init"])
|
||||
command = ["swww", "img", image_path]
|
||||
command.extend(["--resize", fill])
|
||||
command.extend(["--fill-color", color])
|
||||
command.extend(["--transition-type", transition])
|
||||
command.extend(["--transition-type", swww_transition])
|
||||
# command.extend(["--transition-step", str(30)])
|
||||
if monitor != "All":
|
||||
command.extend(["--outputs", monitor])
|
||||
|
@ -2,8 +2,9 @@
|
||||
|
||||
import os
|
||||
import random
|
||||
import shutil
|
||||
|
||||
from waypaper.options import IMAGE_EXTENSIONS
|
||||
from waypaper.options import IMAGE_EXTENSIONS, BACKEND_OPTIONS
|
||||
|
||||
def has_image_extension(file_path, backend):
|
||||
"""Check if the file has image extension"""
|
||||
@ -35,3 +36,14 @@ def get_random_file(folder, include_subfolders):
|
||||
return random.choice(image_paths)
|
||||
except:
|
||||
return None
|
||||
|
||||
|
||||
def check_missing_backends():
|
||||
"""Check which backends are installed in the system"""
|
||||
missing_backends = []
|
||||
for backend in BACKEND_OPTIONS:
|
||||
if backend == "wallutils":
|
||||
backend = "setwallpaper"
|
||||
is_backend_missing = not bool(shutil.which(backend))
|
||||
missing_backends.append(is_backend_missing)
|
||||
return missing_backends
|
||||
|
Loading…
Reference in New Issue
Block a user