X-Git-Url: https://code.delx.au/bg-scripts/blobdiff_plain/a407e8b413e333ac956dd54e600f7868ab1b57a8..0769d8f2a3ce12b2023335b5c3c9bbbd76b7d531:/wallchanger.py?ds=sidebyside diff --git a/wallchanger.py b/wallchanger.py index 5982621..b48775e 100755 --- a/wallchanger.py +++ b/wallchanger.py @@ -4,7 +4,7 @@ # Licensed for distribution under the GPL version 2, check COPYING for details # This is a cross platform/cross window manager way to change your wallpaper -import commands, sys, os, os.path, subprocess, time +import commands, sys, os, os.path, time import logging __all__ = ("init", "set_image") @@ -59,6 +59,22 @@ class BaseChanger(object): self.permanent = permanent self.convert = convert + try: + import subprocess + except ImportError: + self._runProgram = self._runProgram_command + else: + self._runProgram = self._runProgram_subprocess + + def _runProgram_subprocess(self, cmd): + import subprocess + return subprocess.Popen(cmd, stdout=sys.stdout, stderr=sys.stderr, stdin=None).wait() + + # A simple implementation of subprocess for python2.4 + def _runProgram_command(self, cmd): + """Runs a program given in cmd""" + return os.spawnvp(os.P_WAIT, cmd[0], cmd) + def set_image(self, filename): raise NotImplementedError() @@ -81,7 +97,7 @@ class WMakerChanger(BaseChanger): output_name = os.path.join(self._ConvertedWallpaperLocation, '%s.png' % time.time()) cmd = ["convert", '-resize', '1280', '-gravity', 'Center', '-crop', '1280x800+0+0', file, output_name] logging.debug("""Convert command: '"%s"'""", '" "'.join(cmd)) - return output_name, subprocess.Popen(cmd, stdout=sys.stdout, stderr=sys.stderr, stdin=None).wait() + return output_name, self._runProgram(cmd) def set_image(self, file): if self.convert: @@ -100,7 +116,7 @@ class WMakerChanger(BaseChanger): cmd += ["-u"] # update the wmaker database cmd += [file] logging.debug('''WMaker bgset command: "'%s'"''', "' '".join(cmd)) - return not subprocess.Popen(cmd, stdout=sys.stdout, stderr=sys.stderr, stdin=None).wait() + return not self._runProgram(cmd) class OSXChanger(BaseChanger): name = "Mac OS X" @@ -167,7 +183,7 @@ class GnomeChanger(BaseChanger): def set_image(self, file): cmd = ['gconftool-2', '--type', 'string', '--set', '/desktop/gnome/background/picture_filename', file] logging.debug(cmd) - return not subprocess.Popen(cmd, stdout=sys.stdout, stderr=sys.stderr, stdin=None).wait() + return not self._runProgram(cmd) class KDEChanger(BaseChanger): name = "KDE" @@ -183,7 +199,7 @@ class KDEChanger(BaseChanger): cmds.append(['dcop', 'kdesktop', 'KBackgroundIface', 'configure']) for cmd in cmds: logging.debug(cmd) - if subprocess.Popen(cmd, stdout=sys.stdout, stderr=sys.stderr, stdin=None).wait() != 0: + if self._runProgram(cmd) != 0: return False return True