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