aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples/data/uzbl/plugins/config.py
diff options
context:
space:
mode:
authorGravatar Mason Larobina <mason.larobina@gmail.com>2009-10-15 00:08:45 +0800
committerGravatar Mason Larobina <mason.larobina@gmail.com>2009-10-15 00:08:45 +0800
commitfdd8d07eba9e483baf618b6d8fd928fefb8465f3 (patch)
tree26ea2f4359db95f27ec80224d7f9b13766845eb0 /examples/data/uzbl/plugins/config.py
parent847ddc83ccbd7964898980f3f4dd520937ea3bbe (diff)
Added multi-instance managing to event_manager.py
1. Moved plugin directory from './examples/data/scripts/plugins' to './examples/data/'. 2. Broke up the plugin manager class into two small functions. 3. Removed the handler objects ability to have non-callable handlers given that there is a perfectly good on_event.py plugin which can do exactly the same. 4. Gave event_manager daemon abilities similar to the cookie_daemon. 5. Using pid to track the event manager daemons running status. 6. Added the ability to load plugins from multiple locations. 7. Removed all outgoing message queues as this work-around is no longer required after the newly added --connect-socket uzbl-core ability. 8. Removed native stdin/fifo reading ability. Use socat if required. 9. Updated uzbl-browser script to load example cookie_daemon if cookie_daemon is not in $XDG_DATA_HOME/uzbl/scripts/ 10. Added a new event_manager.py launcher uzbl-daemon. 11. Updated make test-dev-browser target to test uzbl-daemon also. 12. Added init like {start|stop|restart} to the event manager. 13. Added a fourth 'list' option to {start|stop|..} to list the plugins and dirs of each plugin that would be loaded by the event manager.
Diffstat (limited to 'examples/data/uzbl/plugins/config.py')
-rw-r--r--examples/data/uzbl/plugins/config.py87
1 files changed, 87 insertions, 0 deletions
diff --git a/examples/data/uzbl/plugins/config.py b/examples/data/uzbl/plugins/config.py
new file mode 100644
index 0000000..22803b4
--- /dev/null
+++ b/examples/data/uzbl/plugins/config.py
@@ -0,0 +1,87 @@
+import re
+import types
+
+__export__ = ['set', 'get_config']
+
+_VALIDSETKEY = re.compile("^[a-zA-Z][a-zA-Z0-9_]*$").match
+_TYPECONVERT = {'int': int, 'float': float, 'str': unicode}
+
+UZBLS = {}
+
+
+def escape(value):
+ '''A real escaping function may be required.'''
+
+ return unicode(value)
+
+
+def get_config(uzbl):
+ if uzbl not in UZBLS:
+ add_instance(uzbl)
+
+ return UZBLS[uzbl]
+
+
+def set(uzbl, key, value):
+ '''Sends a: "set key = value" command to the uzbl instance.'''
+
+ if type(value) == types.BooleanType:
+ value = int(value)
+
+ if not _VALIDSETKEY(key):
+ raise KeyError("%r" % key)
+
+ value = escape(value)
+ if '\n' in value:
+ value = value.replace("\n", "\\n")
+
+ uzbl.send('set %s = %s' % (key, value))
+
+
+def add_instance(uzbl, *args):
+ UZBLS[uzbl] = ConfigDict(uzbl)
+
+
+def del_instance(uzbl, *args):
+ if uzbl in UZBLS:
+ del uzbl
+
+
+def get_config(uzbl):
+ if uzbl not in UZBLS:
+ add_instance(uzbl)
+
+ return UZBLS[uzbl]
+
+
+class ConfigDict(dict):
+ def __init__(self, uzbl):
+ self._uzbl = uzbl
+
+ 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)
+
+
+def variable_set(uzbl, args):
+ config = get_config(uzbl)
+
+ key, type, value = list(args.split(' ', 2) + ['',])[:3]
+ old = config[key] if key in config else None
+ value = _TYPECONVERT[type](value)
+
+ dict.__setitem__(config, key, value)
+
+ if old != value:
+ uzbl.event("CONFIG_CHANGED", key, value)
+
+
+def init(uzbl):
+
+ connects = {'VARIABLE_SET': variable_set,
+ 'INSTANCE_START': add_instance,
+ 'INSTANCE_EXIT': del_instance}
+
+ uzbl.connect_dict(connects)