aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorGravatar Mason Larobina <mason.larobina@gmail.com>2009-09-16 14:00:25 +0800
committerGravatar Mason Larobina <mason.larobina@gmail.com>2009-09-16 14:00:25 +0800
commit3702a07d3bdbc45f6bc31a70b528a9c51d82929b (patch)
tree7be28de1db8467042877019c7f4cce76f1e622a3 /examples
parent5e8224c60e887253669cd72ae0df5c343825c221 (diff)
Removed "<a><b>c" binding ability after horrifing bug discovered.
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/data/uzbl/scripts/event_manager.py1
-rw-r--r--examples/data/uzbl/scripts/plugins/bind.py33
-rw-r--r--examples/data/uzbl/scripts/plugins/keycmd.py71
3 files changed, 54 insertions, 51 deletions
diff --git a/examples/data/uzbl/scripts/event_manager.py b/examples/data/uzbl/scripts/event_manager.py
index b3d5ea2..0bb4876 100755
--- a/examples/data/uzbl/scripts/event_manager.py
+++ b/examples/data/uzbl/scripts/event_manager.py
@@ -386,6 +386,7 @@ class UzblInstance(object):
msg = self._fifo_cmd_queue.pop(0)
print "Sending via fifo: %r" % msg
h.write("%s\n" % msg)
+
h.close()
if len(self._socket_cmd_queue) and self.uzbl_socket:
diff --git a/examples/data/uzbl/scripts/plugins/bind.py b/examples/data/uzbl/scripts/plugins/bind.py
index a3618ca..2321679 100644
--- a/examples/data/uzbl/scripts/plugins/bind.py
+++ b/examples/data/uzbl/scripts/plugins/bind.py
@@ -20,16 +20,16 @@ __export__ = ['bind', 'del_bind', 'del_bind_by_glob', 'get_binds']
_UZBLS = {}
# Commonly used regular expressions.
-starts_with_mod = re.compile('^<([A-Za-z0-9-_]+|.)>')
+starts_with_mod = re.compile('^<([A-Z][A-Za-z0-9-_]+)>')
def echo(msg):
if config['verbose']:
- print "plugin: bind:", msg
+ print 'bind plugin:', msg
def error(msg):
- sys.stderr.write("plugin: bind: error: %s" % msg)
+ sys.stderr.write('bind plugin: error: %s\n' % msg)
def ismodbind(glob):
@@ -52,7 +52,7 @@ def sort_mods(glob):
mods.append(glob[:end])
glob = glob[end:]
- return "%s%s" % (''.join(sorted(mods)), glob)
+ return '%s%s' % (''.join(sorted(mods)), glob)
def add_instance(uzbl, *args):
@@ -79,7 +79,7 @@ def del_bind(uzbl, bind):
binds = get_binds(uzbl)
if bind in binds:
binds.remove(bind)
- uzbl.event("DELETED_BIND", bind)
+ uzbl.event('DELETED_BIND', bind)
return True
return False
@@ -92,7 +92,7 @@ def del_bind_by_glob(uzbl, glob):
for bind in list(binds):
if bind.glob == glob:
binds.remove(bind)
- uzbl.event("DELETED_BIND", bind)
+ uzbl.event('DELETED_BIND', bind)
return True
return False
@@ -114,7 +114,7 @@ class Bind(object):
self.kargs = kargs
elif kargs:
- raise ArgumentError("cannot supply kargs for uzbl commands")
+ raise ArgumentError('cannot supply kargs for uzbl commands')
elif isiterable(handler):
self.commands = handler
@@ -142,22 +142,22 @@ class Bind(object):
def __repr__(self):
- args = ["glob=%r" % self.glob, "bid=%d" % self.bid]
+ args = ['glob=%r' % self.glob, 'bid=%d' % self.bid]
if self.callable:
- args.append("function=%r" % self.function)
+ args.append('function=%r' % self.function)
if self.args:
- args.append("args=%r" % self.args)
+ args.append('args=%r' % self.args)
if self.kargs:
- args.append("kargs=%r" % self.kargs)
+ args.append('kargs=%r' % self.kargs)
else:
cmdlen = len(self.commands)
cmds = self.commands[0] if cmdlen == 1 else self.commands
- args.append("command%s=%r" % ("s" if cmdlen-1 else "", cmds))
+ args.append('command%s=%r' % ('s' if cmdlen-1 else '', cmds))
- return "<Bind(%s)>" % ', '.join(args)
+ return '<Bind(%s)>' % ', '.join(args)
def bind(uzbl, glob, handler, *args, **kargs):
@@ -179,10 +179,11 @@ def bind(uzbl, glob, handler, *args, **kargs):
def parse_bind_event(uzbl, args):
'''Parse "event BIND fl* = js follownums.js" commands.'''
- if len(args.split('=', 1)) != 2:
- error('invalid bind format: %r' % args)
+ split = map(str.strip, args.split('=', 1))
+ if len(split) != 2:
+ return error('missing "=" in bind definition: %r' % args)
- glob, command = map(str.strip, args.split('=', 1))
+ glob, command = split
bind(uzbl, glob, command)
diff --git a/examples/data/uzbl/scripts/plugins/keycmd.py b/examples/data/uzbl/scripts/plugins/keycmd.py
index 10c7b5d..67ab6c2 100644
--- a/examples/data/uzbl/scripts/plugins/keycmd.py
+++ b/examples/data/uzbl/scripts/plugins/keycmd.py
@@ -32,7 +32,7 @@ class Keylet(object):
typed.'''
def __init__(self):
- self.cmd = ""
+ self.cmd = ''
self.held = []
# to_string() string building cache.
@@ -43,7 +43,7 @@ class Keylet(object):
def __repr__(self):
- return "<Keycmd(%r)>" % self.to_string()
+ return '<Keycmd(%r)>' % self.to_string()
def to_string(self):
@@ -58,9 +58,9 @@ class Keylet(object):
self._to_string = self.cmd
else:
- self._to_string = ''.join(["<%s>" % key for key in self.held])
+ self._to_string = ''.join(['<%s>' % key for key in self.held])
if self.cmd:
- self._to_string += "%s" % self.cmd
+ self._to_string += '%s' % self.cmd
return self._to_string
@@ -75,7 +75,7 @@ def make_simple(key):
'''Make some obscure names for some keys friendlier.'''
# Remove left-right discrimination.
- if key.endswith("_L") or key.endswith("_R"):
+ if key.endswith('_L') or key.endswith('_R'):
key = key[:-2]
if key in _SIMPLEKEYS:
@@ -117,15 +117,18 @@ def clear_keycmd(uzbl):
if not k:
return
- k.cmd = ""
+ k.cmd = ''
k._to_string = None
if k.modcmd:
k.wasmod = True
k.modcmd = False
- uzbl.get_config()['keycmd'] = ""
- uzbl.event("KEYCMD_CLEAR")
+ config = uzbl.get_config()
+ if config['keycmd'] != '':
+ config['keycmd'] = ''
+
+ uzbl.event('KEYCMD_CLEAR')
def update_event(uzbl, keylet):
@@ -134,12 +137,16 @@ def update_event(uzbl, keylet):
config = uzbl.get_config()
if keylet.modcmd:
- config['keycmd'] = keylet.to_string()
- uzbl.event("MODCMD_UPDATE", keylet)
+ keycmd = keylet.to_string()
+ uzbl.event('MODCMD_UPDATE', keylet)
+ if keycmd == keylet.to_string():
+ config['keycmd'] = keylet.to_string()
else:
- config['keycmd'] = keylet.cmd
- uzbl.event("KEYCMD_UPDATE", keylet)
+ keycmd = keylet.cmd
+ uzbl.event('KEYCMD_UPDATE', keylet)
+ if keycmd == keylet.cmd:
+ config['keycmd'] = keylet.cmd
def key_press(uzbl, key):
@@ -153,13 +160,12 @@ def key_press(uzbl, key):
a. BackSpace deletes the last character in the keycmd.
b. Return raises a KEYCMD_EXEC event then clears the keycmd.
c. Escape clears the keycmd.
- d. Normal keys are added to held keys list (I.e. <a><b>+c).
4. If keycmd and held keys are both empty/null and a modkey was pressed
set modcmd mode.
5. If in modcmd mode only mod keys are added to the held keys list.
6. Keycmd is updated and events raised if anything is changed.'''
- if key.startswith("Shift_"):
+ if key.startswith('Shift_'):
return
if len(key) > 1:
@@ -175,9 +181,9 @@ def key_press(uzbl, key):
k.wasmod = False
cmdmod = True
- if k.cmd and key == "Space":
+ if k.cmd and key == 'Space':
if k.cmd:
- k.cmd += " "
+ k.cmd += ' '
cmdmod = True
elif not k.modcmd and key == 'BackSpace':
@@ -190,23 +196,23 @@ def key_press(uzbl, key):
cmdmod = True
elif not k.modcmd and key == 'Return':
- uzbl.event("KEYCMD_EXEC", k)
+ uzbl.event('KEYCMD_EXEC', k)
clear_keycmd(uzbl)
elif not k.modcmd and key == 'Escape':
clear_keycmd(uzbl)
- elif not k.held and not k.cmd:
- k.modcmd = True if len(key) > 1 else False
+ elif not k.held and not k.cmd and len(key) > 1:
+ k.modcmd = True
k.held.append(key)
- k.held.sort()
cmdmod = True
- if not k.modcmd:
- k.cmd += key
elif k.modcmd:
cmdmod = True
if len(key) > 1:
+ if key == 'Shift-Tab' and 'Tab' in k.held:
+ k.held.remove('Tab')
+
if key not in k.held:
k.held.append(key)
k.held.sort()
@@ -215,12 +221,8 @@ def key_press(uzbl, key):
k.cmd += key
else:
- cmdmod = True
if len(key) == 1:
- if key not in k.held:
- k.held.append(key)
- k.held.sort()
-
+ cmdmod = True
k.cmd += key
if cmdmod:
@@ -245,16 +247,15 @@ def key_release(uzbl, key):
return
cmdmod = False
- if k.modcmd and key in k.held:
- uzbl.event("MODCMD_EXEC", k)
- k.held.remove(key)
- k.held.sort()
- clear_keycmd(uzbl)
+ if key in ['Shift', 'Tab'] and 'Shift-Tab' in k.held:
+ key = 'Shift-Tab'
+
+ if key in k.held:
+ if k.modcmd:
+ uzbl.event('MODCMD_EXEC', k)
- elif not k.modcmd and key in k.held:
k.held.remove(key)
- k.held.sort()
- cmdmod = True
+ clear_keycmd(uzbl)
if not k.held and not k.cmd and k.wasmod:
k.wasmod = False