From 398f73483d6835c7f64511cbfbacf15e90e2c9ce Mon Sep 17 00:00:00 2001 From: James Bunton Date: Thu, 3 Jul 2008 14:38:27 +1000 Subject: [PATCH] RandomBG: Make ImageMagick/PIL conversions optional * This speeds up randombg considerably when they're not necessary. * Also moved the plist fix to OSXChanger.__init__ to save time. --- bin/randombg.py | 3 +++ bin/wallchanger.py | 28 +++++++++++++++++----------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/bin/randombg.py b/bin/randombg.py index 29dcc20..039b762 100755 --- a/bin/randombg.py +++ b/bin/randombg.py @@ -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") diff --git a/bin/wallchanger.py b/bin/wallchanger.py index 1ac5dcf..b20c068 100755 --- a/bin/wallchanger.py +++ b/bin/wallchanger.py @@ -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] -- 2.39.2