diff options
author | Robert Manea <gotmor@gmail.com> | 2009-09-30 16:46:31 +0200 |
---|---|---|
committer | Robert Manea <gotmor@gmail.com> | 2009-09-30 16:46:31 +0200 |
commit | 93bcfb0d08807a68da314ef844c9cfc9afd07ae9 (patch) | |
tree | 2fd9e2e87fe7b6c734e6d7a8cdb2157c27044a0c | |
parent | 3e6b009c35776f1ab9b18bd8ef84148830109108 (diff) | |
parent | 925a20268e793f38b043b5b8dc2670a732c18f36 (diff) |
Merge branch 'experimental' of git://github.com/mason-larobina/uzbl into experimental
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | docs/INSTALL | 2 | ||||
-rw-r--r-- | examples/config/uzbl/config | 3 | ||||
-rwxr-xr-x | examples/data/uzbl/scripts/event_manager.py | 11 | ||||
-rw-r--r-- | examples/data/uzbl/scripts/plugins/bind.py | 3 | ||||
-rw-r--r-- | examples/data/uzbl/scripts/plugins/config.py | 3 | ||||
-rw-r--r-- | examples/data/uzbl/scripts/plugins/keycmd.py | 174 | ||||
-rw-r--r-- | examples/data/uzbl/scripts/plugins/mode.py | 3 | ||||
-rw-r--r-- | examples/data/uzbl/scripts/plugins/on_event.py | 4 | ||||
-rw-r--r-- | examples/data/uzbl/scripts/plugins/plugin_template.py | 16 | ||||
-rw-r--r-- | examples/data/uzbl/scripts/plugins/progress_bar.py | 3 | ||||
-rwxr-xr-x | uzbl-browser | 4 |
12 files changed, 162 insertions, 65 deletions
@@ -20,6 +20,7 @@ In alphabetical order: Aaron Griffin (phrakture) - Makefile patches to build on OSX Abel Camarillo (00z) - various portability fixes, such as BSD fixes for Makefile and posix shell scripts Andraž 'ruskie' Levstik - font_family patch + Barak A. Pearlmutter - typo fix Brendan Taylor (bct) - various bugfixes, making misc variables much better using expand(), refactoring some internal var stuff Chris Mason - code snippets such as basic cookie handler Chris van Dijk (quigybo) - work on uzbl_tabbed.py diff --git a/docs/INSTALL b/docs/INSTALL index 59bdaad..93e55f7 100644 --- a/docs/INSTALL +++ b/docs/INSTALL @@ -28,7 +28,7 @@ Though you can only get tagged versions from the master branch, which may be old Dependencies ------------ * git (for downloading) -* pkgconfig (for Make/gcc) +* pkg-config (for Make/gcc) * libwebkit 1.1.4 or higher * libsoup 2.24 or higher (dep for webkit/gtk+) * gtk 2.14 or higher diff --git a/examples/config/uzbl/config b/examples/config/uzbl/config index ba684a0..fd5fe52 100644 --- a/examples/config/uzbl/config +++ b/examples/config/uzbl/config @@ -54,9 +54,10 @@ set status_background = #303030 set keycmd_style = weight="bold" foreground="red" set prompt_style = foreground="grey" +set cursor_style = underline="single" set mode_section = <span background="khaki" foreground="black">[\@[\@mode_indicator]\@]</span> -set keycmd_section = [<span \@prompt_style>\@[\@keycmd_prompt]\@</span><span \@keycmd_style>\@[\@keycmd]\@</span>] +set keycmd_section = [<span \@prompt_style>\@[\@keycmd_prompt]\@</span><span \@keycmd_style>\@keycmd</span>] set progress_section = <span foreground="#606060">\@[\@progress_format]\@</span> set uri_section = <span foreground="#99FF66">\@[\@uri]\@</span> set name_section = <span foreground="khaki">\@[\@NAME]\@</span> diff --git a/examples/data/uzbl/scripts/event_manager.py b/examples/data/uzbl/scripts/event_manager.py index 18a6d54..2e84ded 100755 --- a/examples/data/uzbl/scripts/event_manager.py +++ b/examples/data/uzbl/scripts/event_manager.py @@ -439,6 +439,17 @@ class UzblInstance(object): return handler + def connect_dict(self, connect_dict): + '''Connect a dictionary comprising of {"EVENT_NAME": handler, ..} to + the event handler stack. + + If you need to supply args or kargs to an event use the normal connect + function.''' + + for (event, handler) in connect_dict.items(): + self.connect(event, handler) + + def remove_by_id(self, hid): '''Remove connected event handler by unique handler id.''' diff --git a/examples/data/uzbl/scripts/plugins/bind.py b/examples/data/uzbl/scripts/plugins/bind.py index b7a6e9b..15f6f8e 100644 --- a/examples/data/uzbl/scripts/plugins/bind.py +++ b/examples/data/uzbl/scripts/plugins/bind.py @@ -371,5 +371,4 @@ def init(uzbl): 'MODCMD_EXEC': modcmd_exec, 'MODE_CHANGED': clear_stack} - for (event, handler) in connects.items(): - uzbl.connect(event, handler) + uzbl.connect_dict(connects) diff --git a/examples/data/uzbl/scripts/plugins/config.py b/examples/data/uzbl/scripts/plugins/config.py index dc2070a..22803b4 100644 --- a/examples/data/uzbl/scripts/plugins/config.py +++ b/examples/data/uzbl/scripts/plugins/config.py @@ -84,5 +84,4 @@ def init(uzbl): 'INSTANCE_START': add_instance, 'INSTANCE_EXIT': del_instance} - for (event, handler) in connects.items(): - uzbl.connect(event, handler) + uzbl.connect_dict(connects) diff --git a/examples/data/uzbl/scripts/plugins/keycmd.py b/examples/data/uzbl/scripts/plugins/keycmd.py index 4b243a7..3dd6f37 100644 --- a/examples/data/uzbl/scripts/plugins/keycmd.py +++ b/examples/data/uzbl/scripts/plugins/keycmd.py @@ -1,7 +1,7 @@ import re # Map these functions/variables in the plugins namespace to the uzbl object. -__export__ = ['clear_keycmd',] +__export__ = ['clear_keycmd', 'set_keycmd', 'set_cursor_pos', 'get_keylet'] # Regular expression compile cache. _RE_CACHE = {} @@ -16,16 +16,22 @@ _SIMPLEKEYS = { 'space':'Space', } +# Keycmd format which includes the markup for the cursor. +KEYCMD_FORMAT = "%s<span @cursor_style>%s</span>%s" -def keycmd_escape(keycmd): + +def escape(str): '''Prevent outgoing keycmd values from expanding inside the status_format.''' + if not str: + return '' + for char in ['\\', '@']: - if char in keycmd: - keycmd = keycmd.replace(char, '\\'+char) + if char in str: + str = str.replace(char, '\\'+char) - return keycmd + return "@[%s]@" % str def get_regex(regex): @@ -44,14 +50,14 @@ class Keylet(object): def __init__(self): self.cmd = '' + self.cursor = 0 self.held = [] # to_string() string building cache. self._to_string = None self.modcmd = False - self.wasmod = True - + self.wasmod = False def __repr__(self): return '<Keycmd(%r)>' % self.to_string() @@ -71,7 +77,7 @@ class Keylet(object): else: self._to_string = ''.join(['<%s>' % key for key in self.held]) if self.cmd: - self._to_string += '%s' % self.cmd + self._to_string += self.cmd return self._to_string @@ -125,10 +131,8 @@ def clear_keycmd(uzbl): '''Clear the keycmd for this uzbl instance.''' k = get_keylet(uzbl) - if not k: - return - k.cmd = '' + k.cursor = 0 k._to_string = None if k.modcmd: @@ -142,27 +146,41 @@ def clear_keycmd(uzbl): uzbl.event('KEYCMD_CLEAR') -def update_event(uzbl, keylet): - '''Raise keycmd/modcmd update events.''' +def update_event(uzbl, k): + '''Raise keycmd & modcmd update events.''' config = uzbl.get_config() - - if keylet.modcmd: - keycmd = keylet.to_string() - uzbl.event('MODCMD_UPDATE', keylet) - if keycmd != keylet.to_string(): + if k.modcmd: + keycmd = k.to_string() + uzbl.event('MODCMD_UPDATE', k) + if keycmd != k.to_string(): return if 'modcmd_updates' in config and config['modcmd_updates'] != '1': return - uzbl.set('keycmd', keycmd_escape(keycmd)) + return uzbl.set('keycmd', escape(keycmd)) + + if 'keycmd_events' in config and config['keycmd_events'] != '1': + return + + keycmd = k.cmd + uzbl.event('KEYCMD_UPDATE', k) + if keycmd != k.cmd: + return + + if not k.cmd: + return uzbl.set('keycmd', '') - elif 'keycmd_events' not in config or config['keycmd_events'] == '1': - keycmd = keylet.cmd - uzbl.event('KEYCMD_UPDATE', keylet) - if keycmd == keylet.cmd: - uzbl.set('keycmd', keycmd_escape(keycmd)) + # Generate the pango markup for the cursor in the keycmd. + if k.cursor < len(k.cmd): + cursor = k.cmd[k.cursor] + + else: + cursor = ' ' + + chunks = map(escape, [k.cmd[:k.cursor], cursor, k.cmd[k.cursor+1:]]) + uzbl.set('keycmd', KEYCMD_FORMAT % tuple(chunks)) def key_press(uzbl, key): @@ -173,9 +191,12 @@ def key_press(uzbl, key): modkey still held from the previous modcmd (I.e. <Ctrl>+t, clear & <Ctrl>+o without having to re-press <Ctrl>) 3. In non-modcmd mode: - 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. + a. BackSpace deletes the character before the cursor position. + b. Delete deletes the character at the cursor position. + c. End moves the cursor to the end of the keycmd. + d. Home moves the cursor to the beginning of the keycmd. + e. Return raises a KEYCMD_EXEC event then clears the keycmd. + f. Escape clears the keycmd. 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. @@ -188,9 +209,6 @@ def key_press(uzbl, key): key = make_simple(key) k = get_keylet(uzbl) - if not k: - return - cmdmod = False if k.held and k.wasmod: k.modcmd = True @@ -198,25 +216,56 @@ def key_press(uzbl, key): cmdmod = True if k.cmd and key == 'Space': - if k.cmd: - k.cmd += ' ' - cmdmod = True + k.cmd = "%s %s" % (k.cmd[:k.cursor], k.cmd[k.cursor:]) + k.cursor += 1 + cmdmod = True - elif not k.modcmd and key == 'BackSpace': - if k.cmd: - k.cmd = k.cmd[:-1] - if not k.cmd: - clear_keycmd(uzbl) + elif not k.modcmd and k.cmd and key in ['BackSpace', 'Delete']: + if key == 'BackSpace' and k.cursor > 0: + k.cursor -= 1 + k.cmd = k.cmd[:k.cursor] + k.cmd[k.cursor+1:] - else: + elif key == 'Delete': + cmd = k.cmd + k.cmd = k.cmd[:k.cursor] + k.cmd[k.cursor+1:] + if k.cmd != cmd: cmdmod = True + if not k.cmd: + clear_keycmd(uzbl) + + elif key == 'BackSpace': + cmdmod = True + elif not k.modcmd and key == 'Return': if k.cmd: uzbl.event('KEYCMD_EXEC', k) clear_keycmd(uzbl) + elif not k.modcmd and key == 'Escape': + clear_keycmd(uzbl) + + elif not k.modcmd and k.cmd and key == 'Left': + if k.cursor > 0: + k.cursor -= 1 + cmdmod = True + + elif not k.modcmd and k.cmd and key == 'Right': + if k.cursor < len(k.cmd): + k.cursor += 1 + cmdmod = True + + elif not k.modcmd and k.cmd and key == 'End': + if k.cursor != len(k.cmd): + k.cursor = len(k.cmd) + cmdmod = True + + elif not k.modcmd and k.cmd and key == 'Home': + if k.cursor: + k.cursor = 0 + cmdmod = True + elif not k.held and not k.cmd and len(key) > 1: k.modcmd = True k.held.append(key) @@ -233,18 +282,21 @@ def key_press(uzbl, key): k.held.sort() else: - k.cmd += key + k.cmd = "%s%s%s" % (k.cmd[:k.cursor], key, k.cmd[k.cursor:]) + k.cursor += 1 else: config = uzbl.get_config() if 'keycmd_events' not in config or config['keycmd_events'] == '1': if len(key) == 1: cmdmod = True - k.cmd += key + k.cmd = "%s%s%s" % (k.cmd[:k.cursor], key, k.cmd[k.cursor:]) + k.cursor += 1 elif k.cmd: cmdmod = True k.cmd = '' + k.cursor = 0 if cmdmod: update_event(uzbl, k) @@ -264,8 +316,6 @@ def key_release(uzbl, key): key = make_simple(key) k = get_keylet(uzbl) - if not k: - return cmdmod = False if key in ['Shift', 'Tab'] and 'Shift-Tab' in k.held: @@ -288,13 +338,45 @@ def key_release(uzbl, key): update_event(uzbl, k) +def set_keycmd(uzbl, keycmd): + '''Allow setting of the keycmd externally.''' + + k = get_keylet(uzbl) + k.wasmod = k.modcmd = False + k._to_string = None + k.cmd = keycmd + k.cursor = len(keycmd) + update_event(uzbl, k) + + +def set_cursor_pos(uzbl, index): + '''Allow setting of the cursor position externally. Supports negative + indexing.''' + + cursor = int(index.strip()) + k = get_keylet(uzbl) + + if cursor < 0: + cursor = len(k.cmd) + cursor + + if cursor < 0: + cursor = 0 + + if cursor > len(k.cmd): + cursor = len(k.cmd) + + k.cursor = cursor + update_event(uzbl, k) + + def init(uzbl): '''Connect handlers to uzbl events.''' connects = {'INSTANCE_START': add_instance, 'INSTANCE_EXIT': del_instance, 'KEY_PRESS': key_press, - 'KEY_RELEASE': key_release} + 'KEY_RELEASE': key_release, + 'SET_KEYCMD': set_keycmd, + 'SET_CURSOR_POS': set_cursor_pos} - for (event, handler) in connects.items(): - uzbl.connect(event, handler) + uzbl.connect_dict(connects) diff --git a/examples/data/uzbl/scripts/plugins/mode.py b/examples/data/uzbl/scripts/plugins/mode.py index f8464e7..ad0d9a8 100644 --- a/examples/data/uzbl/scripts/plugins/mode.py +++ b/examples/data/uzbl/scripts/plugins/mode.py @@ -156,5 +156,4 @@ def init(uzbl): 'LOAD_START': load_reset, 'TOGGLE_MODES': toggle_modes} - for (event, handler) in connects.items(): - uzbl.connect(event, handler) + uzbl.connect_dict(connects) diff --git a/examples/data/uzbl/scripts/plugins/on_event.py b/examples/data/uzbl/scripts/plugins/on_event.py index fbbc75d..242f9b0 100644 --- a/examples/data/uzbl/scripts/plugins/on_event.py +++ b/examples/data/uzbl/scripts/plugins/on_event.py @@ -109,9 +109,9 @@ def parse_on_event(uzbl, args): def init(uzbl): + connects = {'ON_EVENT': parse_on_event, 'INSTANCE_START': add_instance, 'INSTANCE_EXIT': del_instance} - for (event, handler) in connects.items(): - uzbl.connect(event, handler) + uzbl.connect_dict(connects) diff --git a/examples/data/uzbl/scripts/plugins/plugin_template.py b/examples/data/uzbl/scripts/plugins/plugin_template.py index 55bb62a..03cb748 100644 --- a/examples/data/uzbl/scripts/plugins/plugin_template.py +++ b/examples/data/uzbl/scripts/plugins/plugin_template.py @@ -10,13 +10,13 @@ UZBLS = {} DEFAULTS = {} -def add_instance(uzbl, pid): +def add_instance(uzbl, *args): '''Add a new instance with default config options.''' UZBLS[uzbl] = dict(DEFAULTS) -def del_instance(uzbl, pid): +def del_instance(uzbl, *args): '''Delete data stored for an instance.''' if uzbl in UZBLS: @@ -58,12 +58,18 @@ def init(uzbl): is called each time a UzblInstance() object is created in the event manager.''' + # Make a dictionary comprising of {"EVENT_NAME": handler, ..} to the event + # handler stack: connects = { - # EVENT_NAME HANDLER_FUNCTION 'INSTANCE_START': add_instance, 'INSTANCE_EXIT': del_instance, 'MYPLUGIN_EVENT': myplugin_event_parser, } - for (event, handler) in connects.items(): - uzbl.connect(event, handler) + # And connect the dicts event handlers to the handler stack. + uzbl.connect_dict(connects) + + # Or connect a handler to an event manually and supply additional optional + # arguments: + + #uzbl.connect("MYOTHER_EVENT", myother_event_parser, True, limit=20) diff --git a/examples/data/uzbl/scripts/plugins/progress_bar.py b/examples/data/uzbl/scripts/plugins/progress_bar.py index c9f8a36..b6fcb1b 100644 --- a/examples/data/uzbl/scripts/plugins/progress_bar.py +++ b/examples/data/uzbl/scripts/plugins/progress_bar.py @@ -155,5 +155,4 @@ def init(uzbl): 'PROGRESS_CONFIG': progress_config, 'LOAD_COMMIT': reset_progress} - for (event, handler) in connects.items(): - uzbl.connect(event, handler) + uzbl.connect_dict(connects) diff --git a/uzbl-browser b/uzbl-browser index eeabcc0..f5ad14b 100755 --- a/uzbl-browser +++ b/uzbl-browser @@ -8,12 +8,12 @@ # But this shouldn't cause much problems.. -if [ x"$XDG_DATA_HOME" == 'x' ] +if [ -z "$XDG_DATA_HOME" ] then XDG_DATA_HOME=$HOME/.local/share fi -if [ x"$XDG_CACHE_HOME" == 'x' ] +if [ -z "$XDG_CACHE_HOME" ] then XDG_CACHE_HOME=$HOME/.cache fi |