From 5cecb5d6570df33c2ce9c700c563fad8b787f13e Mon Sep 17 00:00:00 2001 From: Mason Larobina Date: Sun, 29 Nov 2009 18:27:07 +0800 Subject: Add force option to set in config plugin. --- examples/data/uzbl/plugins/config.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'examples/data/uzbl/plugins') diff --git a/examples/data/uzbl/plugins/config.py b/examples/data/uzbl/plugins/config.py index 57c2403..47b59f9 100644 --- a/examples/data/uzbl/plugins/config.py +++ b/examples/data/uzbl/plugins/config.py @@ -22,12 +22,16 @@ def get_config(uzbl): return UZBLS[uzbl] -def set(uzbl, key, value=''): - '''Sends a: "set key = value" command to the uzbl instance.''' +def set(uzbl, key, value='', force=True): + '''Sends a: "set key = value" command to the uzbl instance. If force is + False then only send a set command if the values aren't equal.''' if type(value) == types.BooleanType: value = int(value) + else: + value = unicode(value) + if not _VALIDSETKEY(key): raise KeyError("%r" % key) @@ -35,6 +39,11 @@ def set(uzbl, key, value=''): if '\n' in value: value = value.replace("\n", "\\n") + if not force: + config = get_config(uzbl) + if key in config and config[key] == value: + return + uzbl.send('set %s = %s' % (key, value)) @@ -61,8 +70,7 @@ class ConfigDict(dict): def __setitem__(self, key, value): '''Makes "config[key] = value" a wrapper for the set function.''' - if key not in self or unicode(self[key]) != unicode(value): - set(self._uzbl, key, value) + set(self._uzbl, key, value, force=False) def variable_set(uzbl, args): -- cgit v1.2.3