"""Convert the image to a png, and store it in a local place"""
self._removeOldImageCache()
output_name = os.path.join(self._ConvertedWallpaperLocation, '%s.png' % time.time())
- cmd = ["convert", file, output_name]
- debug("""Convert command: '"%s"'""" % '" "'.join(cmd), DEBUG_LEVEL_DEBUG)
- return output_name, subprocess.Popen(cmd, stdout=sys.stdout, stderr=sys.stderr, stdin=None).wait()
+ try:
+ import PIL, PIL.Image
+ img = PIL.Image.open(file)
+ img.save(output_name, "PNG")
+ return output_name, True
+ except ImportError:
+ debug('Could not load PIL, going to try just copying the image')
+ import shutil
+ output_name = os.path.join(self._ConvertedWallpaperLocation, os.path.basename(file))
+ shutil.copyfile(file, output_name)
+ return output_name, True
def _fixDesktopPList(self):
"""Removes the entry in the desktop plist file that specifies the wallpaper for each monitor"""
def changeTo(self, file):
output_name, ret = self._convertImageFormat(file)
- if ret: # Since 0 indicates success
- debug("Convert failed %s" % ret)
+ if not ret:
+ debug("Convert failed")
return False
self._fixDesktopPList()
cmd = """osascript -e 'tell application "finder" to set desktop picture to posix file "%s"'""" % output_name