]> code.delx.au - bg-scripts/commitdiff
RandomBG: Make ImageMagick/PIL conversions optional
authorJames Bunton <jamesbunton@delx.net.au>
Thu, 3 Jul 2008 04:38:27 +0000 (14:38 +1000)
committerJames Bunton <jamesbunton@delx.net.au>
Thu, 3 Jul 2008 04:38:27 +0000 (14:38 +1000)
 * This speeds up randombg considerably when they're not necessary.
 * Also moved the plist fix to OSXChanger.__init__ to save time.

bin/randombg.py
bin/wallchanger.py

index 29dcc20fd346351c9cfb6c89947b243f911dfd93..039b762aee70afa47788f301324ee253b83e547a 100755 (executable)
@@ -364,6 +364,9 @@ def build_parser():
        parser.add_option("--folder-random",
                action="store_true", dest="folder_random", default=False,
                help="Give each folder an equal chance of having an image selected from it")
+       parser.add_option("--convert",
+               action="store_true", dest="convert", default=False,
+               help="Do conversions using ImageMagick or PIL, don't rely on the window manager")
        parser.add_option("--cycle-time",
                action="store", type="int", default=1800, dest="cycle_time",
                help="Cause the image to cycle every X seconds")
index 1ac5dcff2955c198dfa105d5a6220c92f42f629b..b20c0683b84404326f3afd5f2b1fdc27d639a74b 100755 (executable)
@@ -53,10 +53,11 @@ def init(*args, **kwargs):
 
 class BaseChanger(object):
        name = "undefined"
-       def __init__(self, background_color='black', permanent=False):
+       def __init__(self, background_color='black', permanent=False, convert=False):
                info('Determined the window manager is "%s"' % self.name)
                self.background_color = background_color
                self.permanent = permanent
+               self.convert = convert
 
        def set_image(self, filename):
                raise NotImplementedError()
@@ -83,9 +84,10 @@ class WMakerChanger(BaseChanger):
                return output_name, subprocess.Popen(cmd, stdout=sys.stdout, stderr=sys.stderr, stdin=None).wait()
 
        def set_image(self, file):
-               file, convert_status = self.convert_image_format(file)
-               if convert_status:
-                       debug('Convert failed')
+               if self.convert:
+                       file, convert_status = self.convert_image_format(file)
+                       if convert_status:
+                               debug('Convert failed')
                cmd = ["wmsetbg", 
                        "-b", self.background_color, # Sets the background colour to be what the user specified
                        "-S", # 'Smooth' (WTF?)
@@ -105,6 +107,10 @@ class OSXChanger(BaseChanger):
        _ConvertedWallpaperLocation = '/tmp/wallpapers/'
        _DesktopPlistLocation = os.path.expanduser('~/Library/Preferences/com.apple.desktop.plist')
 
+       def __init__(self, *args, **kwargs):
+               BaseChanger.__init__(self, *args, **kwargs)
+               self.fix_desktop_plist()
+
        def remove_old_image_cache(self):
                """Cleans up any old temp images"""
                if not os.path.isdir(self._ConvertedWallpaperLocation):
@@ -146,13 +152,13 @@ class OSXChanger(BaseChanger):
                except ImportError:
                        debug('Could not import the Foundation module, you may have problems with dual screens')
 
-       def set_image(self, file):
-               output_name, ret = self.convert_image_format(file)
-               if not ret:
-                       debug("Convert failed")
-                       return False
-               self.fix_desktop_plist()
-               cmd = """osascript -e 'tell application "finder" to set desktop picture to posix file "%s"'""" % output_name
+       def set_image(self, filename):
+               if self.convert:
+                       filename, ret = self.convert_image_format(filename)
+                       if not ret:
+                               debug("Convert failed")
+                               return False
+               cmd = """osascript -e 'tell application "finder" to set desktop picture to posix file "%s"'""" % filename
                debug(cmd)
                return not commands.getstatusoutput(cmd)[0]