aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples/data/uzbl/plugins/mode.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/mode.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/mode.py')
-rw-r--r--examples/data/uzbl/plugins/mode.py159
1 files changed, 159 insertions, 0 deletions
diff --git a/examples/data/uzbl/plugins/mode.py b/examples/data/uzbl/plugins/mode.py
new file mode 100644
index 0000000..ad0d9a8
--- /dev/null
+++ b/examples/data/uzbl/plugins/mode.py
@@ -0,0 +1,159 @@
+import sys
+import re
+
+__export__ = ['set_mode', 'get_mode']
+
+UZBLS = {}
+
+DEFAULTS = {
+ 'mode': '',
+ 'default': '',
+ 'modes': {
+ 'insert': {
+ 'forward_keys': True,
+ 'keycmd_events': False,
+ 'modcmd_updates': False,
+ 'indicator': 'I'},
+ 'command': {
+ 'forward_keys': False,
+ 'keycmd_events': True,
+ 'modcmd_updates': True,
+ 'indicator': 'C'}}}
+
+_RE_FINDSPACES = re.compile("\s+")
+
+
+def error(msg):
+ sys.stderr.write("mode plugin: error: %s\n" % msg)
+
+
+def add_instance(uzbl, *args):
+ UZBLS[uzbl] = dict(DEFAULTS)
+
+
+def del_instance(uzbl, *args):
+ if uzbl in UZBLS:
+ del UZBLS[uzbl]
+
+
+def get_mode_dict(uzbl):
+ if uzbl not in UZBLS:
+ add_instance(uzbl)
+
+ return UZBLS[uzbl]
+
+
+def get_mode_config(uzbl, mode):
+ modes = get_mode_dict(uzbl)['modes']
+ if mode not in modes:
+ modes[mode] = {}
+
+ return modes[mode]
+
+
+def get_mode(uzbl):
+ return get_mode_dict(uzbl)['mode']
+
+
+def key_press(uzbl, key):
+ if key != "Escape":
+ return
+
+ set_mode(uzbl)
+
+
+def set_mode(uzbl, mode=None):
+ mode_dict = get_mode_dict(uzbl)
+ if mode is None:
+ if not mode_dict['default']:
+ return error("no default mode to fallback on")
+
+ mode = mode_dict['default']
+
+ config = uzbl.get_config()
+ if 'mode' not in config or config['mode'] != mode:
+ config['mode'] = mode
+
+ mode_dict['mode'] = mode
+ mode_config = get_mode_config(uzbl, mode)
+
+ for (key, value) in mode_config.items():
+ if key not in config:
+ config[key] = value
+
+ elif config[key] != value:
+ config[key] = value
+
+ if 'mode_indicator' not in mode_config:
+ config['mode_indicator'] = mode
+
+ uzbl.clear_keycmd()
+ uzbl.send('update_gui')
+ uzbl.event("MODE_CHANGED", mode)
+
+
+def config_changed(uzbl, key, value):
+ if key == 'default_mode':
+ mode_dict = get_mode_dict(uzbl)
+ mode_dict['default'] = value
+ if value and not mode_dict['mode']:
+ set_mode(uzbl, value)
+
+ elif key == 'mode':
+ if not value:
+ value = None
+
+ set_mode(uzbl, value)
+
+
+def mode_config(uzbl, args):
+
+ split = map(unicode.strip, _RE_FINDSPACES.split(args.lstrip(), 1))
+ if len(split) != 2:
+ return error("invalid MODE_CONFIG syntax: %r" % args)
+
+ mode, set = split
+ split = map(unicode.strip, set.split('=', 1))
+ if len(split) != 2:
+ return error("invalid MODE_CONFIG set command: %r" % args)
+
+ key, value = split
+ mode_config = get_mode_config(uzbl, mode)
+ mode_config[key] = value
+
+ if get_mode(uzbl) == mode:
+ uzbl.set(key, value)
+
+
+def load_reset(uzbl, *args):
+ config = uzbl.get_config()
+ if 'reset_on_commit' not in config or config['reset_on_commit'] == '1':
+ set_mode(uzbl)
+
+
+def toggle_modes(uzbl, modes):
+
+ modelist = [s.strip() for s in modes.split(' ') if s]
+ if not len(modelist):
+ return error("no modes specified to toggle")
+
+ mode_dict = get_mode_dict(uzbl)
+ oldmode = mode_dict['mode']
+ if oldmode not in modelist:
+ return set_mode(uzbl, modelist[0])
+
+ newmode = modelist[(modelist.index(oldmode)+1) % len(modelist)]
+ set_mode(uzbl, newmode)
+
+
+def init(uzbl):
+
+ connects = {'CONFIG_CHANGED': config_changed,
+ 'INSTANCE_EXIT': del_instance,
+ 'INSTANCE_START': add_instance,
+ 'KEY_PRESS': key_press,
+ 'MODE_CONFIG': mode_config,
+ 'LOAD_START': load_reset,
+ 'TOGGLE_MODES': toggle_modes}
+
+ uzbl.connect_dict(connects)