From bf664ed7fe6ec9f93a598635755cbe78cc2aec59 Mon Sep 17 00:00:00 2001 From: Ales Lerch Date: Tue, 26 Sep 2017 23:05:25 +0200 Subject: [PATCH] dont change wallpaer if display sleeps --- WallpDesk/wall.py | 15 ++++++++++++++- WallpDesk/wallpaper.py | 4 ++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/WallpDesk/wall.py b/WallpDesk/wall.py index 0070778..a75d145 100644 --- a/WallpDesk/wall.py +++ b/WallpDesk/wall.py @@ -5,6 +5,7 @@ __author__ = 'ales lerch' import os +import re import subprocess from multiprocessing import active_children @@ -21,6 +22,7 @@ def __init__(self, directory): self.directory = directory self.db = DB_lite() self.types = (".jpg",".png",".jpeg",".tiff") + self.iopm = re.compile(r'IOPowerManagement.*{(.*)}') def set_directory(self, directory): self.directory = directory @@ -31,7 +33,7 @@ def set_wallpaper(self,img): subprocess.call(["killall", "Dock"]) def set_wallpaper_with_effect(self, img, save): - if img: + if img and self.get_display_status() == 4: path = f"{HOME}/Library/Application Support/WallpDesk/current/" cmd = b"""tell application "System Events" tell current desktop @@ -72,6 +74,17 @@ def get_images_files(self, any_ = False): else: print("Folder for images not found") + def get_display_status(self): + """ return iokit powermanagement status if 4 then display is on elif 1 + screen is off""" + output = subprocess.check_output( + 'ioreg -w 0 -c IODisplayWrangler -r IODisplayWrangler'.split()).decode('utf-8') + status = self.iopm.search(output).group(1) + power_state = dict((k[1:-1], v) for (k, v) in + (x.split('=') for x in status.split(',')))["CurrentPowerState"] + return int(power_state) + + def shut_down(self, name): #in future update use mutltiprocessing.queue for sperate processes for process in active_children(): diff --git a/WallpDesk/wallpaper.py b/WallpDesk/wallpaper.py index 6f2d196..2c1192d 100644 --- a/WallpDesk/wallpaper.py +++ b/WallpDesk/wallpaper.py @@ -110,8 +110,8 @@ def choose_random_image(self, _alive = False): super().set_wallpaper_with_effect(f"{image[1]}/{image[0]}", True) except Exception as e: print(e) - cmd = f"""display notification " Chaning wallpaper to {image} daemon" with title\ - "WallpDesk" subtitle "Wallpaper change" """ + cmd = f"""display notification " Chaning wallpaper to {image[0]} daemon" with title\ + "WallpDesk" subtitle "Wallpaper change theme {image[2]}" """ Popen(["osascript", '-'], stdin=PIPE, stdout=PIPE).communicate(cmd.encode()) def choose_last_image(self):