Created
November 7, 2017 08:13
-
-
Save quantum5/4aa0b5cdd7a753e828001e14532a44b9 to your computer and use it in GitHub Desktop.
Revisions
-
quantum5 created this gist
Nov 7, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,60 @@ #!/usr/bin/env python from __future__ import division import time import os import threading import subprocess from wand.image import Image from watchdog.events import FileSystemEventHandler from watchdog.observers import Observer BACKGROUND = '/mnt/c/Users/Quantum/AppData/Roaming/Microsoft/Windows/Themes/TranscodedWallpaper' RESULT = '/home/quantum/.config/i3/background.png' WIDTH = 1600 HEIGHT = 860 REAL_HEIGHT = 900 background_dir = os.path.dirname(BACKGROUND) debounce = threading.Event() class EventHandler(FileSystemEventHandler): def on_modified(self, event): if event.src_path == BACKGROUND: debounce.set() def update_wallpaper(): with Image(filename=BACKGROUND) as img: w, h = img.size scale = max(WIDTH / w, REAL_HEIGHT / h) left = (w * scale - WIDTH) / 2 top = (h * scale - REAL_HEIGHT * 2 + HEIGHT) / 2 img.resize(int(w * scale), int(h * scale)) img.crop(left=int(left), top=int(top), width=WIDTH, height=HEIGHT) img.save(filename=RESULT) subprocess.call(['feh', '--bg-fill', RESULT]) def main(): handler = EventHandler() observer = Observer() observer.schedule(handler, background_dir) observer.start() update_wallpaper() try: while True: while not debounce.wait(86400): pass debounce.clear() while debounce.wait(0.2): debounce.clear() update_wallpaper() except KeyboardInterrupt: observer.stop() observer.join() if __name__ == '__main__': main()