From: Greg Darke Date: Wed, 25 Jun 2008 04:09:53 +0000 (+1000) Subject: WallChanger:Removed the MacOSX dependency on imagemagick, we now depend on PIL (Pytho... X-Git-Url: https://code.delx.au/bg-scripts/commitdiff_plain/de8ac8c2cc2d21dc2e649ca3e565ee3907f1038a WallChanger:Removed the MacOSX dependency on imagemagick, we now depend on PIL (Python Imaging Library). --- diff --git a/lib/WallChanger.py b/lib/WallChanger.py index d9f80dd..b7a81ab 100644 --- a/lib/WallChanger.py +++ b/lib/WallChanger.py @@ -143,9 +143,17 @@ class __OSXChanger(__BaseChanger): """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""" @@ -164,8 +172,8 @@ class __OSXChanger(__BaseChanger): 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