mirror of
https://github.com/anufrievroman/waypaper.git
synced 2024-08-16 11:40:44 +03:00
Implementing swww transitions and improving config
This commit is contained in:
parent
af26245572
commit
858c0127f2
@ -46,8 +46,10 @@ def change_wallpaper(image_path, cf, monitor, txt):
|
||||
command = ["swww", "img", image_path]
|
||||
command.extend(["--resize", fill])
|
||||
command.extend(["--fill-color", cf.color])
|
||||
command.extend(["--transition-type", cf.swww_transition])
|
||||
# command.extend(["--transition-step", str(30)])
|
||||
command.extend(["--transition-type", cf.swww_transition_type])
|
||||
command.extend(["--transition-step", str(cf.swww_transition_step)])
|
||||
command.extend(["--transition-angle", str(cf.swww_transition_angle)])
|
||||
command.extend(["--transition-duration", str(cf.swww_transition_duration)])
|
||||
if monitor != "All":
|
||||
command.extend(["--outputs", monitor])
|
||||
subprocess.Popen(command)
|
||||
|
@ -1,4 +1,4 @@
|
||||
"""Module responsible for taking care of configuration file"""
|
||||
"""Module responsible for reading and saving the configuration file"""
|
||||
|
||||
import configparser
|
||||
import pathlib
|
||||
@ -7,7 +7,7 @@ from sys import exit
|
||||
from platformdirs import user_config_path, user_pictures_path, user_cache_path
|
||||
|
||||
from waypaper.aboutdata import AboutData
|
||||
from waypaper.options import FILL_OPTIONS, SORT_OPTIONS, SWWW_TRANSITIONS, BACKEND_OPTIONS
|
||||
from waypaper.options import FILL_OPTIONS, SORT_OPTIONS, SWWW_TRANSITION_TYPES, BACKEND_OPTIONS
|
||||
from waypaper.common import check_installed_backends
|
||||
|
||||
|
||||
@ -22,7 +22,10 @@ class Config:
|
||||
self.sort_option = SORT_OPTIONS[0]
|
||||
self.backend = self.installed_backends[0] if self.installed_backends else BACKEND_OPTIONS[0]
|
||||
self.color = "#ffffff"
|
||||
self.swww_transition = SWWW_TRANSITIONS[0]
|
||||
self.swww_transition_type = SWWW_TRANSITION_TYPES[0]
|
||||
self.swww_transition_step = 90
|
||||
self.swww_transition_angle = 0
|
||||
self.swww_transition_duration = 2
|
||||
self.lang = "en"
|
||||
self.monitors = [self.selected_monitor]
|
||||
self.wallpaper = []
|
||||
@ -38,36 +41,53 @@ class Config:
|
||||
self.cache_dir.mkdir(parents=True,exist_ok=True)
|
||||
|
||||
self.read()
|
||||
self.check_validity()
|
||||
|
||||
|
||||
def read(self):
|
||||
"""Load data from the config.ini or use default if it does not exists"""
|
||||
config = configparser.ConfigParser()
|
||||
config.read(self.config_file, 'utf-8')
|
||||
|
||||
# Read parameters:
|
||||
self.image_folder = config.get("Settings", "folder", fallback=self.image_folder)
|
||||
self.fill_option = config.get("Settings", "fill", fallback=self.fill_option)
|
||||
if self.fill_option not in FILL_OPTIONS:
|
||||
self.sort_option = FILL_OPTIONS[0]
|
||||
self.sort_option = config.get("Settings", "sort", fallback=self.sort_option)
|
||||
if self.sort_option not in SORT_OPTIONS:
|
||||
self.sort_option = SORT_OPTIONS[0]
|
||||
self.backend = config.get("Settings", "backend", fallback=self.backend)
|
||||
self.color = config.get("Settings", "color", fallback=self.color)
|
||||
self.post_command = config.get("Settings", "post_command", fallback=self.post_command)
|
||||
self.swww_transition = config.get("Settings", "swww_transition", fallback=self.swww_transition)
|
||||
if self.swww_transition not in SWWW_TRANSITIONS:
|
||||
self.swww_transition = "any"
|
||||
self.swww_transition_type = config.get("Settings", "swww_transition_type", fallback=self.swww_transition_type)
|
||||
self.swww_transition_step = config.get("Settings", "swww_transition_step", fallback=self.swww_transition_step)
|
||||
self.swww_transition_angle = config.get("Settings", "swww_transition_angle", fallback=self.swww_transition_angle)
|
||||
self.swww_transition_duration = config.get("Settings", "swww_transition_duration", fallback=self.swww_transition_duration)
|
||||
self.lang = config.get("Settings", "language", fallback=self.lang)
|
||||
self.include_subfolders = config.getboolean("Settings", "subfolders", fallback=self.include_subfolders)
|
||||
|
||||
self.monitors_str = config.get("Settings", "monitors", fallback=self.selected_monitor, raw=True)
|
||||
self.wallpaper_str = config.get("Settings", "wallpaper", fallback="", raw=True)
|
||||
|
||||
# Convert strings to lists:
|
||||
if self.monitors_str is not None:
|
||||
self.monitors = [str(monitor) for monitor in self.monitors_str.split(",")]
|
||||
|
||||
self.wallpaper_str = config.get("Settings", "wallpaper", fallback="", raw=True)
|
||||
if self.wallpaper_str is not None:
|
||||
self.wallpaper = [str(paper) for paper in self.wallpaper_str.split(",")]
|
||||
|
||||
def check_validity(self):
|
||||
"""Check if the config parameters are valid and correct them if needed"""
|
||||
if self.backend not in BACKEND_OPTIONS:
|
||||
self.backend = self.installed_backends[0] if self.installed_backends else BACKEND_OPTIONS[0]
|
||||
if self.sort_option not in SORT_OPTIONS:
|
||||
self.sort_option = SORT_OPTIONS[0]
|
||||
if self.fill_option not in FILL_OPTIONS:
|
||||
self.fill_option = FILL_OPTIONS[0]
|
||||
if self.swww_transition_type not in SWWW_TRANSITION_TYPES:
|
||||
self.swww_transition_type = "any"
|
||||
|
||||
if 0 > int(self.swww_transition_angle) > 180:
|
||||
self.swww_transition_angle = 0
|
||||
if 0 > int(self.swww_transition_step) > 255:
|
||||
self.swww_transition_step = 90
|
||||
if 0 > int(self.swww_transition_duration):
|
||||
self.swww_transition_duration = 2
|
||||
|
||||
def save(self):
|
||||
"""Update the parameters and save them to the configuration file"""
|
||||
@ -88,17 +108,20 @@ class Config:
|
||||
config.read(self.config_file)
|
||||
if not config.has_section("Settings"):
|
||||
config.add_section("Settings")
|
||||
config.set("Settings", "language", self.lang)
|
||||
config.set("Settings", "folder", self.image_folder)
|
||||
config.set("Settings", "wallpaper", ",".join(self.wallpaper))
|
||||
config.set("Settings", "backend", self.backend)
|
||||
config.set("Settings", "monitors", ",".join(self.monitors))
|
||||
config.set("Settings", "fill", self.fill_option)
|
||||
config.set("Settings", "sort", self.sort_option)
|
||||
config.set("Settings", "backend", self.backend)
|
||||
config.set("Settings", "color", self.color)
|
||||
config.set("Settings", "swww_transition", self.swww_transition)
|
||||
config.set("Settings", "language", self.lang)
|
||||
config.set("Settings", "subfolders", str(self.include_subfolders))
|
||||
config.set("Settings", "wallpaper", ",".join(self.wallpaper))
|
||||
config.set("Settings", "monitors", ",".join(self.monitors))
|
||||
config.set("Settings", "post_command", self.post_command)
|
||||
config.set("Settings", "swww_transition_type", str(self.swww_transition_type))
|
||||
config.set("Settings", "swww_transition_step", str(self.swww_transition_step))
|
||||
config.set("Settings", "swww_transition_angle", str(self.swww_transition_angle))
|
||||
config.set("Settings", "swww_transition_duration", str(self.swww_transition_duration))
|
||||
with open(self.config_file, "w") as configfile:
|
||||
config.write(configfile)
|
||||
|
||||
|
@ -14,5 +14,5 @@ IMAGE_EXTENSIONS = {
|
||||
BACKEND_OPTIONS[3]: ['.gif', '.jpg', '.jpeg', '.png'],
|
||||
}
|
||||
|
||||
SWWW_TRANSITIONS = ["any", "none", "simple", "fade", "wipe", "left", "right", "top",
|
||||
SWWW_TRANSITION_TYPES = ["any", "none", "simple", "fade", "wipe", "left", "right", "top",
|
||||
"bottom", "wave", "grow", "center", "outer", "random"]
|
||||
|
Loading…
Reference in New Issue
Block a user