# 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")
else:
if os.uname()[0] == 'Darwin':
# Try to detect if the X11 server is running on OSX
- if commands.getstatusoutput("ps ax -o command|grep -q '/.*X11 .* %s'" % os.environ['DISPLAY'])[0] != 0:
+ if commands.getstatusoutput("ps ax -o command|grep -q '^/.*X11 .* %s'" % os.environ['DISPLAY'])[0] != 0:
# X11 is not running for this display
return
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()
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:
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"
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"""
logging.debug('Could not import the Foundation module, you may have problems with dual screens')
def set_image(self, filename):
+ self.fix_desktop_plist()
if self.convert:
filename, ret = self.convert_image_format(filename)
if not ret:
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"
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