Skip to content

Commit

Permalink
dont change wallpaer if display sleeps
Browse files Browse the repository at this point in the history
  • Loading branch information
axeII committed Sep 26, 2017
1 parent 276b9b5 commit bf664ed
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
15 changes: 14 additions & 1 deletion WallpDesk/wall.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
__author__ = 'ales lerch'

import os
import re
import subprocess
from multiprocessing import active_children

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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():
Expand Down
4 changes: 2 additions & 2 deletions WallpDesk/wallpaper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit bf664ed

Please sign in to comment.