X-Git-Url: https://code.delx.au/bg-scripts/blobdiff_plain/ca96b32295cd38cdb4a150c1111159cbc9c77f2f..ef17c1d24360f73053de29324e033b0046772543:/lib/WallChanger.py diff --git a/lib/WallChanger.py b/lib/WallChanger.py index 147518b..c6958a8 100644 --- a/lib/WallChanger.py +++ b/lib/WallChanger.py @@ -11,8 +11,6 @@ desktop image.""" __all__ = ('RandomBG') -KDE_CONFIG = os.path.expanduser('~/.kde/share/config/kdesktoprc') - def RandomBG(*args, **kwargs): """Desktop Changer factory""" @@ -145,57 +143,27 @@ class __OSXChanger(__BaseChanger): debug(cmd, DEBUG_LEVEL_DEBUG) return not commands.getstatusoutput(cmd)[0] +class __GnomeChanger(__BaseChanger): + def changeTo(self, file): + cmd = ['gconftool-2', '--type', 'string', '--set', '/desktop/gnome/background/picture_filename', file] + debug(cmd, DEBUG_LEVEL_DEBUG) + return subprocess.Popen(cmd, stdout=sys.stdout, stderr=sys.stderr, stdin=None).wait() + class __KDEChanger(__BaseChanger): - def _parseKDEConfig(self, filename = KDE_CONFIG): - fd = open(filename, 'r') - result = collection.defaultdict(dict) - section = None - for line in fd: - line = line.strip() - if not line or line.startswith('#'): - continue - - if line.startswith('[') and line.endswith(']'): - section = line[1:-1] - result[section] = {} - continue - elif not section: - raise Exception('Invalid kdesktoprc file') - - unpack = line.split('=', 1) - if len(unpack) == 2: - key, val = unpack - else: - key, val = unpack[0], None - result[section][key] = val - - fd.close() - return result - - def _writeKDEConfig(self, config, filename = KDE_CONFIG): - fd = open(filename, 'w') - for section, values in config.items(): - print >>fd, '[%s]' % section - for k, v in values.items(): - if v != None: - print >>fd, '%s=%s' % (k,v) - else: - print >>fd, k - print >>fd - fd.close() - def changeTo(self, file): - kdeconfig = self._parseKDEConfig() - #kdeconfig['Background Common']['DrawBackgroundPerScreen_0']='true' - for section in ('Desktop0', 'Desktop0Screen0'): - kdeconfig[section]['Wallpaper'] = file - kdeconfig[section]['UseSHM'] = 'true' - kdeconfig[section]['WallpaperMode'] = 'ScaleAndCrop' - # Ensure that random mode is disabled... - if 'MultiWallpaperMode' in kdeconfig[section]: - del kdeconfig[section]['MultiWallpaperMode'] - - self._writeKDEConfig(kdeconfig) - - return not subprocess.Popen(['dcop', 'kdesktop', 'KBackgroundIface', 'configure'], - stdout=sys.stdout, stderr=sys.stderr, stdin=open('/dev/null', 'r')).wait() + cmds = [] + for group in ('Desktop0', 'Desktop0Screen0'): + base = ['kwriteconfig', '--file', 'kdesktoprc', '--group', group, '--key'] + cmds.append(base + ['Wallpaper', file]) + cmds.append(base + ['UseSHM', '--type', 'bool', 'true']) + cmds.append(base + ['WallpaperMode', 'ScaleAndCrop']) + cmds.append(base + ['MultiWallpaperMode', 'NoMulti']) + + cmds.append(['dcop', 'kdesktop', 'KBackgroundIface', 'configure']) + for cmd in cmds: + debug(cmd, DEBUG_LEVEL_DEBUG) + if subprocess.Popen(cmd, stdout=sys.stdout, stderr=sys.stderr, stdin=None).wait() != 0: + return 1 # Fail + + return 0 # Success +