]> code.delx.au - bg-scripts/commitdiff
WallChanger:Removed the MacOSX dependency on imagemagick, we now depend on PIL (Pytho...
authorGreg Darke <greg@tsukasa.net.au>
Wed, 25 Jun 2008 04:09:53 +0000 (14:09 +1000)
committerGreg Darke <greg@tsukasa.net.au>
Wed, 25 Jun 2008 04:09:53 +0000 (14:09 +1000)
lib/WallChanger.py

index d9f80dd8702d7cf58606511ec2fea99754786516..b7a81ab18fea42e341466fe084f4e5979f9fb682 100644 (file)
@@ -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())
                """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 _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)
 
        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
                        return False
                self._fixDesktopPList()
                cmd = """osascript -e 'tell application "finder" to set desktop picture to posix file "%s"'""" % output_name