diff --git a/waypaper/app.py b/waypaper/app.py index b5b8f0b..15f0dbf 100644 --- a/waypaper/app.py +++ b/waypaper/app.py @@ -15,7 +15,7 @@ from waypaper.changer import change_wallpaper from waypaper.config import Config from waypaper.common import get_image_paths, get_random_file -from waypaper.options import FILL_OPTIONS, SORT_OPTIONS, SORT_DISPLAYS, VIDEO_EXTENSIONS , SWWW_TRANSITION_TYPES +from waypaper.options import FILL_OPTIONS, SORT_OPTIONS, SORT_DISPLAYS, VIDEO_EXTENSIONS , SWWW_TRANSITION_TYPES, MPV_TIMERS from waypaper.translations import Chinese, English, French, German, Polish, Russian, Belarusian, Spanish gi.require_version("Gtk", "3.0") @@ -225,6 +225,16 @@ def init_ui(self) -> None: self.mpv_sound_toggle.connect("toggled", self.on_mpv_sound_toggled) self.mpv_sound_toggle.set_tooltip_text(self.txt.tip_mpv_sound) + # Create mpv times drop: + self.mpv_timer_combo = Gtk.ComboBoxText() + options = list(MPV_TIMERS.keys()) + for option in MPV_TIMERS: + self.mpv_timer_combo.append_text(option) + active_num = next((i for i, (k, v) in enumerate(MPV_TIMERS.items()) if v == self.cf.mpvpaper_timer), None) + self.mpv_timer_combo.set_active(active_num) + self.mpv_timer_combo.connect("changed", self.on_mpv_timer_changed) + self.mpv_timer_combo.set_tooltip_text(self.txt.tip_timer) + # Create a box to contain the bottom row of buttons: self.bottom_button_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=60) self.bottom_button_box.set_margin_bottom(15) @@ -394,10 +404,12 @@ def mpv_options_display(self) -> None: self.options_box.remove(self.mpv_stop_button) self.options_box.remove(self.mpv_pause_button) self.options_box.remove(self.mpv_sound_toggle) + self.options_box.remove(self.mpv_timer_combo) if self.cf.backend == "mpvpaper": self.options_box.pack_end(self.mpv_stop_button, False, False, 0) self.options_box.pack_end(self.mpv_pause_button, False, False, 0) self.options_box.pack_end(self.mpv_sound_toggle, False, False, 0) + self.options_box.pack_end(self.mpv_timer_combo, False, False, 0) def fill_option_display(self): """Display fill option if backend is not hyprpaper""" @@ -632,13 +644,20 @@ def on_monitor_option_changed(self, combo) -> None: def on_sort_option_changed(self, combo) -> None: - """Save sort parameter whet it is changed""" + """Save sort parameter when it is changed""" selected_option = combo.get_active_text() selected_option_num = list(SORT_DISPLAYS.values()).index(selected_option) self.cf.sort_option = list(SORT_DISPLAYS.keys())[selected_option_num] threading.Thread(target=self.process_images).start() + def on_mpv_timer_changed(self, combo) -> None: + """Save timer parameter when it is changed""" + selected_option = combo.get_active_text() + selected_option_num = list(MPV_TIMERS.keys()).index(selected_option) + self.cf.mpvpaper_timer = list(MPV_TIMERS.values())[selected_option_num] + + def on_backend_option_changed(self, combo) -> None: """Save backend parameter whet it is changed""" self.cf.backend = self.backend_option_combo.get_active_text() diff --git a/waypaper/changer.py b/waypaper/changer.py index 24535be..75796ca 100644 --- a/waypaper/changer.py +++ b/waypaper/changer.py @@ -73,13 +73,17 @@ def change_wallpaper(image_path: Path, cf: Config, monitor: str): try: subprocess.check_output(["pgrep", "-f", f"socket-{monitor}"], encoding='utf-8') time.sleep(0.2) - print("Detected running mpvpaper on {monitor}, now trying to call mpvpaper socket") + print(f"Detected running mpvpaper on {monitor}, now trying to call mpvpaper socket") subprocess.Popen(f"echo 'loadfile \"{image_path}\"' | socat - /tmp/mpv-socket-{monitor}", shell=True) # If mpvpaper is not running, create a new process in a new socket: except subprocess.CalledProcessError: print("Detected no running mpvpaper, starting new mpvpaper process") command = ["mpvpaper", "--fork"] + print(cf.mpvpaper_timer) + if cf.mpvpaper_timer > 0: + print(cf.mpvpaper_timer) + command.extend(["-n", str(cf.mpvpaper_timer)]) if cf.mpvpaper_sound: command.extend(["-o", f"input-ipc-server=/tmp/mpv-socket-{monitor} loop {fill} --background-color='{cf.color}'"]) else: diff --git a/waypaper/config.py b/waypaper/config.py index d607359..62b5b81 100644 --- a/waypaper/config.py +++ b/waypaper/config.py @@ -7,7 +7,7 @@ from platformdirs import user_config_path, user_pictures_path, user_cache_path, user_state_path from waypaper.aboutdata import AboutData -from waypaper.options import FILL_OPTIONS, SORT_OPTIONS, SWWW_TRANSITION_TYPES, BACKEND_OPTIONS +from waypaper.options import FILL_OPTIONS, SORT_OPTIONS, SWWW_TRANSITION_TYPES, BACKEND_OPTIONS, MPV_TIMERS from waypaper.common import check_installed_backends @@ -31,6 +31,7 @@ def __init__(self): self.swww_transition_duration = 2 self.swww_transition_fps = 60 self.mpvpaper_sound = False + self.mpvpaper_timer = MPV_TIMERS["Never"] self.lang = "en" self.monitors = [self.selected_monitor] self.wallpapers = [] @@ -88,6 +89,7 @@ def read(self) -> None: self.swww_transition_duration = config.get("Settings", "swww_transition_duration", fallback=self.swww_transition_duration) self.swww_transition_fps = config.get("Settings", "swww_transition_fps", fallback=self.swww_transition_fps) self.mpvpaper_sound = config.getboolean("Settings", "mpvpaper_sound", fallback=self.mpvpaper_sound) + self.mpvpaper_timer = config.get("Settings", "mpvpaper_timer", fallback=self.mpvpaper_timer) self.lang = config.get("Settings", "language", fallback=self.lang) self.include_subfolders = config.getboolean("Settings", "subfolders", fallback=self.include_subfolders) self.include_all_subfolders = config.getboolean("Settings", "all_subfolders", fallback=self.include_all_subfolders) @@ -145,6 +147,8 @@ def check_validity(self) -> None: self.fill_option = FILL_OPTIONS[0] if self.swww_transition_type not in SWWW_TRANSITION_TYPES: self.swww_transition_type = "any" + if self.mpvpaper_timer not in list(MPV_TIMERS.values()): + self.mpvpaper_timer = 0 # Check the validity of the number of columns: try: @@ -161,6 +165,8 @@ def check_validity(self) -> None: self.swww_transition_duration = 2 if 0 > int(self.swww_transition_fps): self.swww_transition_fps = 60 + if 0 > int(self.mpvpaper_timer): + self.mpvpaper_timer = 0 def attribute_selected_wallpaper(self) -> None: """ @@ -230,6 +236,7 @@ def save(self, only_state=False) -> None: config.set("Settings", "swww_transition_duration", str(self.swww_transition_duration)) config.set("Settings", "swww_transition_fps", str(self.swww_transition_fps)) config.set("Settings", "mpvpaper_sound", str(self.mpvpaper_sound)) + config.set("Settings", "mpvpaper_timer", str(self.mpvpaper_timer)) config.set("Settings", "use_xdg_state", str(self.use_xdg_state)) try: diff --git a/waypaper/options.py b/waypaper/options.py index a5ed0d0..4e5a43e 100644 --- a/waypaper/options.py +++ b/waypaper/options.py @@ -26,3 +26,18 @@ SWWW_TRANSITION_TYPES: List[str] = ["any", "none", "simple", "fade", "wipe", "left", "right", "top", "bottom", "wave", "grow", "center", "outer", "random"] + +MPV_TIMERS = {"Never": 0, + "30 sec": 30, + "1 min": 60, + "2 min": 120, + "5 min": 300, + "10 min": 600, + "30 min": 1800, + "1 hour": 3600, + "2 hours": 7200, + "6 hours": 21600, + "12 hours": 43200, + "1 day": 86400, + "1 week": 604800, + } diff --git a/waypaper/translations.py b/waypaper/translations.py index b4d1393..6568eb7 100644 --- a/waypaper/translations.py +++ b/waypaper/translations.py @@ -66,6 +66,7 @@ def __init__(self): self.tip_mpv_stop = "Stop all mpv processes" self.tip_mpv_pause = "Play/Pause video wallpaper" self.tip_mpv_sound = "Play sound of the video" + self.tip_timer = "How often to automatically change wallpaper" class German: @@ -130,6 +131,7 @@ def __init__(self): self.tip_mpv_stop = "Stoppe alle mpv-Prozesse" self.tip_mpv_pause = "Pause Video-Wallpaper" self.tip_mpv_sound = "Play sound of the video" + self.tip_timer = "How often to automatically change wallpaper" class French: def __init__(self): @@ -193,6 +195,7 @@ def __init__(self): self.tip_mpv_stop = "Arrêter tous les processus mpv" self.tip_mpv_pause = "Pause du fond d'écran vidéo" self.tip_mpv_sound = "Play sound of the video" + self.tip_timer = "How often to automatically change wallpaper" class Polish: def __init__(self): @@ -257,6 +260,7 @@ def __init__(self): self.tip_mpv_stop = "Zatrzymaj wszystkie procesy mpv" self.tip_mpv_pause = "Odtwarzaj/Zatrzymaj animowaną" self.tip_mpv_sound = "Play sound of the video" + self.tip_timer = "How often to automatically change wallpaper" class Russian: def __init__(self): @@ -320,6 +324,7 @@ def __init__(self): self.tip_mpv_stop = "Остановить все mpv процессы" self.tip_mpv_pause = "Плей/пауза видео-обоев" self.tip_mpv_sound = "Проигрывать звук видео-обоев" + self.tip_timer = "Как часто автоматически менять обои" class Belarusian: @@ -384,6 +389,7 @@ def __init__(self): self.tip_mpv_stop = "Спыніць усе працэсы mpv" self.tip_mpv_pause = "Паўза відэа-абояў" self.tip_mpv_sound = "Play sound of the video" + self.tip_timer = "How often to automatically change wallpaper" class Chinese: @@ -448,6 +454,7 @@ def __init__(self): self.tip_mpv_stop = "停止所有 mpv 进程" self.tip_mpv_pause = "暂停视频壁纸" self.tip_mpv_sound = "Play sound of the video" + self.tip_timer = "How often to automatically change wallpaper" class Spanish: def __init__(self): @@ -511,6 +518,7 @@ def __init__(self): self.tip_mpv_stop = "Detener todos los procesos de mpv" self.tip_mpv_pause = "Pausar fondo de pantalla de video" self.tip_mpv_sound = "Play sound of the video" + self.tip_timer = "How often to automatically change wallpaper" def load_language(lang):