- name = "undefined"
- def __init__(self, background_color='black', permanent=False, convert=False):
- logging.info('Determined the window manager is "%s"', self.name)
- self.background_color = background_color
- 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()
-
- 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"""
- import PIL, PIL.Image
-
- self.remove_old_image_cache()
- output_name = os.path.join(self._ConvertedWallpaperLocation, '%s%s' % (time.time(), extension))
- img = PIL.Image.open(filename)
-
- # Remove the alpha channel if the user doens't want it
- if not allowAlpha and img.mode == 'RGBA':
- img = img.convert('RGB')
- img.save(output_name, format)
-
- return output_name, True
-
-
-class WMakerChanger(BaseChanger):
- name = "WindowMaker"
- _ConvertedWallpaperLocation = '/tmp/wallpapers_wmaker/'
- def remove_old_image_cache(self):
- """Cleans up any old temp images"""
- if not os.path.isdir(self._ConvertedWallpaperLocation):
- os.mkdir(self._ConvertedWallpaperLocation)
- for fullpath, filenames, dirnames in os.walk(self._ConvertedWallpaperLocation, topdown=False):
- for filename in filenames:
- os.unlink(os.path.join(fullpath, filename))
- for dirname in dirnames:
- os.unlink(os.path.join(fullpath, dirname))
-
- def convert_image_format(self, file):
- """Convert the image to a png, and store it in a local place"""
- self.remove_old_image_cache()
- 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)
-
- def set_image(self, file):
- if self.convert:
- file, convert_status = self.convert_image_format(file)
- if convert_status:
- logging.debug('Convert failed')
- cmd = ["wmsetbg",
- "-b", self.background_color, # Sets the background colour to be what the user specified
- "-S", # 'Smooth' (WTF?)
- "-e", # Center the image on the screen (only affects when the image in no the in the correct aspect ratio
-### "-a", # scale the image, keeping the aspect ratio
- "-u", # Force this to be the default background
- "-d" # dither
- ]
- if self.permanent:
- cmd += ["-u"] # update the wmaker database
- cmd += [file]
- logging.debug('''WMaker bgset command: "'%s'"''', "' '".join(cmd))
- return not self._runProgram(cmd)
+ name = "undefined"
+ def __init__(self, background_color='black', convert=False):
+ logging.info('Determined the window manager is "%s"', self.name)
+ self.background_color = background_color
+ self.convert = convert
+
+ 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
+
+ self.remove_old_image_cache()
+ output_name = os.path.join(self._ConvertedWallpaperLocation, '%s%s' % (time.time(), extension))
+ img = PIL.Image.open(filename)
+
+ # Remove the alpha channel if the user doens't want it
+ if not allowAlpha and img.mode == 'RGBA':
+ img = img.convert('RGB')
+ img.save(output_name, format)
+
+ return output_name, True
+
+
+class XLoadImageChanger(BaseChanger):
+ name = "xloadimage"
+ _ConvertedWallpaperLocation = '/tmp/wallpapers_xloadimage/'
+ def remove_old_image_cache(self):
+ """Cleans up any old temp images"""
+ if not os.path.isdir(self._ConvertedWallpaperLocation):
+ os.mkdir(self._ConvertedWallpaperLocation)
+ for fullpath, filenames, dirnames in os.walk(self._ConvertedWallpaperLocation, topdown=False):
+ for filename in filenames:
+ os.unlink(os.path.join(fullpath, filename))
+ for dirname in dirnames:
+ os.unlink(os.path.join(fullpath, dirname))
+
+ def convert_image_format(self, filename):
+ """Convert the image to a png, and store it in a local place"""
+ self.remove_old_image_cache()
+ output_name = os.path.join(self._ConvertedWallpaperLocation, '%s.png' % time.time())
+ cmd = ["convert", filename, output_name]
+ logging.debug("""Convert command: '"%s"'""", '" "'.join(cmd))
+ return output_name, subprocess.call(cmd) == 0
+
+ def set_image(self, filename):
+ if self.convert:
+ filename, convert_status = self.convert_image_format(filename)
+ if convert_status:
+ logging.debug('Convert failed')
+ cmd = [
+ "xloadimage",
+ "-onroot",
+ "-fullscreen",
+ "-border", "black",
+ filename,
+ ]
+ logging.debug('''WMaker bgset command: "'%s'"''', "' '".join(cmd))
+ return subprocess.call(cmd) == 0