import commands, sys, os, os.path, time
import logging
+try:
+ import PIL, PIL.Image
+except ImportError:
+ PIL = None
__all__ = ("init", "set_image")
if commands.getstatusoutput("xwininfo -name 'KDE Desktop'")[0] == 0:
changers.append(KDEChanger(*args, **kwargs))
+ logging.debug("Testing for Unity")
+ if commands.getstatusoutput("xlsclients | grep -qi unity")[0] == 0:
+ changers.append(UnityChanger(*args, **kwargs))
+
logging.debug("Testing for Gnome")
if commands.getstatusoutput("xwininfo -name 'gnome-settings-daemon'")[0] == 0:
changers.append(GnomeChanger(*args, **kwargs))
self.permanent = permanent
self.convert = convert
- try:
+ try:
+ def _exec_cmd(self, cmd):
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()
+ 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)
+ except ImportError:
+ # A simple implementation of subprocess for python2.4
+ def _exec_cmd(self, cmd):
+ """Runs a program given in cmd"""
+ return os.spawnvp(os.P_WAIT, cmd[0], cmd)
def set_image(self, filename):
raise NotImplementedError()
def convert_image_format(self, filename, format='BMP', allowAlpha=False, extension='.bmp'):
"""Convert the image to another format, and store it in a local place"""
if not os.path.exists(filename):
+ logger.warn('The input file "%s" does not exist, so it will not be converted', filename)
+ return filename, False
+ if PIL is None:
+ logger.warn('PIL could not be found, not converting image format')
return filename, False
- import PIL, PIL.Image
self.remove_old_image_cache()
output_name = os.path.join(self._ConvertedWallpaperLocation, '%s%s' % (time.time(), extension))
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, self._runProgram(cmd)
+ return output_name, self._exec_cmd(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 self._runProgram(cmd)
+ return not self._exec_cmd(cmd)
class OSXChanger(BaseChanger):
name = "Mac OS X"
def set_image(self, file):
cmd = ['gconftool-2', '--type', 'string', '--set', '/desktop/gnome/background/picture_filename', file]
logging.debug(cmd)
- return not self._runProgram(cmd)
+ return not self._exec_cmd(cmd)
+
+class UnityChanger(BaseChanger):
+ name = "Unity"
+ def set_image(self, file):
+ cmd = ['gsettings', 'set', 'org.gnome.desktop.background', 'picture-uri', 'file://'+file]
+ logging.debug(cmd)
+ return not self._exec_cmd(cmd)
class KDEChanger(BaseChanger):
name = "KDE"
cmds.append(['dcop', 'kdesktop', 'KBackgroundIface', 'configure'])
for cmd in cmds:
logging.debug(cmd)
- if self._runProgram(cmd) != 0:
+ if self._exec_cmd(cmd) != 0:
return False
return True