Permalink
Browse files

Huge plugin & event manager upgrades.

1. Removed unused modules
2. Re-use event handlers with identical callbacks and args.
3. Removed plugin exceptions in favour of assertions.
4. Remove useless raw_keycmd and raw_bind config vars.
5. Implemented and use `after` and `cleanup` plugin hooks (correctly)
6. EM & plugins now use the python logging module to output messages
7. Null config items are removed automatically
8. Simpler mode plugin
9. The init plugins function is called after the INSTANCE_START event
10. New optparse option to silence event echoing to stdout
11. Close instance socket on INSTANCE_EXIT before event handling
12. Caught signals are logged
13. Show times on the messages in the log file
14. Refactor bind pluin to use uzbl.bindlet directly.
15. Refactor keycmd plugin to use uzbl.keycmd directly.
16. Refactored on_event plugin to use uzbl.on_events dict over UZBLS dict
17. Refactor completion plugin to use uzbl.completion set object.
18. Modified progress plugin to use config vars instead of `@progress k = v`
19. mode_config now a defaultdict(dict) (I.e. this allows you to
    `uzbl.mode_config[mode][var] = value` without needing to check `mode`
    is in the `uzbl.mode_config` dict).
20. Removed all default mode config values.
21. Removed all `get_mode()` and `set_mode(..)` functions (and the like).
22. Setting the mode is now done via the config object directly (I.e.
    `uzbl.config['mode'] = 'insert'`).
23. Uses the on_set plugin to watch for 'mode' and 'default_mode' config
    changes.
24. Don't raise the useless NEW_ON_SET event, missing ON_SET connect.
25. Plugin and EventHandler aren't suited as dict objects.
26. Also using collections.defaultdict(list) for uzbl.handlers dict.
27. Plugin `on_set.py` allows you to attach handlers to config var changes
28. Config plugin reduced to one `uzbl.config` dict-like object.
29. Update export and connect calls in plugins.
30. The functions connect, connect_dict, export, export_dict, require,
    logging are exported directly to the plugin namespace.
31. Moved parse_msg into Uzbl class.
32. Generally improved comments.
33. UzblEventDaemon now an object.
34. Various variable, function & class renames.
  • Loading branch information...
mason-larobina committed Apr 3, 2010
1 parent ae15d25 commit d3cbe16bf16ff63c0e3db15d645e958712bd02d8
@@ -63,10 +63,10 @@ test-uzbl-browser-sandbox: uzbl-browser
make DESTDIR=./sandbox RUN_PREFIX=`pwd`/sandbox/usr/local install-example-data
cp -np ./misc/env.sh ./sandbox/env.sh
source ./sandbox/env.sh && uzbl-cookie-daemon restart -nv &
source ./sandbox/env.sh && uzbl-event-manager restart -nav &
source ./sandbox/env.sh && uzbl-event-manager restart -navv &
source ./sandbox/env.sh && uzbl-browser --uri http://www.uzbl.org --verbose
source ./sandbox/env.sh && uzbl-cookie-daemon stop -v
source ./sandbox/env.sh && uzbl-event-manager stop -v
source ./sandbox/env.sh && uzbl-event-manager stop -ivv
make DESTDIR=./sandbox uninstall
rm -rf ./sandbox/usr

@@ -14,8 +14,8 @@ set mode_bind = request MODE_BIND
set mode_config = request MODE_CONFIG
# request ON_EVENT <EVENT_NAME> <command>
set on_event = request ON_EVENT
# request PROGRESS_CONFIG <key> = <value>
set progress = request PROGRESS_CONFIG
# request ON_SET <key/glob> <command>
set on_set = request ON_SET
# request MODMAP <From> <To>
set modmap = request MODMAP
# request IGNORE_KEY <glob>
@@ -93,7 +93,7 @@ set hint_style = weight="bold"

set mode_section = <span background="khaki" foreground="black">[\@[\@mode_indicator]\@]</span>
set keycmd_section = [<span \@prompt_style>\@[\@keycmd_prompt]\@</span><span \@modcmd_style>\@modcmd</span><span \@keycmd_style>\@keycmd</span><span \@completion_style>\@completion_list</span>]
set progress_section = <span foreground="#606060">\@[\@progress_format]\@</span>
set progress_section = <span foreground="#606060">\@[\@progress.output]\@</span>
set scroll_section = <span foreground="#606060">\@[\@scroll_message]\@</span>
set uri_section = <span foreground="#99FF66">\@[\@uri]\@</span>
set name_section = <span foreground="khaki">\@[\@NAME]\@</span>
@@ -104,19 +104,19 @@ set status_format = <span font_family="monospace">@mode_section @keycmd_sect

set title_format_long = \@keycmd_prompt \@raw_modcmd \@raw_keycmd \@TITLE - Uzbl browser <\@NAME> \@SELECTED_URI

# Progress bar config
@progress width = 8
# --- Progress bar configuration (progress_bar.py plugin) ---
# %d = done, %p = pending %c = percent done, %i = int done, %s = spinner,
# %t = percent pending, %o = int pending, %r = sprite scroll
@progress format = [%d>%p]%c
@progress done = =
@progress pending =

# Or ride those spinnas'
#@progress format = [%d%s%p]
#@progress spinner = -\\|/
#@progress done = -
#@progress pending =
set progress.width = 8
set progress.format = [%d>%p]%c
set progress.done = =
set progress.pending =

# Or using a spinner:
#set progress.format = [%d%s%p]
#set progress.spinner = -\\|/
#set progress.done = -
#set progress.pending =


# === Core settings ==========================================================
@@ -11,10 +11,6 @@

import sys
import re
import pprint

# Hold the bind dicts for each uzbl instance.
UZBLS = {}

# Commonly used regular expressions.
MOD_START = re.compile('^<([A-Z][A-Za-z0-9-_]*)>').match
@@ -62,9 +58,9 @@ def reset(self):

if self.last_mode:
mode, self.last_mode = self.last_mode, None
self.uzbl.set_mode(mode)
self.uzbl.config['mode'] = mode

self.uzbl.set('keycmd_prompt')
del self.uzbl.config['keycmd_prompt']


def stack(self, bind, args, depth):
@@ -76,10 +72,10 @@ def stack(self, bind, args, depth):

return

current_mode = self.uzbl.get_mode()
if current_mode != 'stack':
self.last_mode = current_mode
self.uzbl.set_mode('stack')
mode = self.uzbl.config.get('mode', None)
if mode != 'stack':
self.last_mode = mode
self.uzbl.config['mode'] = 'stack'

self.stack_binds = [bind,]
self.args += args
@@ -97,7 +93,7 @@ def after(self):

self.uzbl.clear_keycmd()
if prompt:
self.uzbl.set('keycmd_prompt', prompt)
self.uzbl.config['keycmd_prompt'] = prompt

if set and is_cmd:
self.uzbl.send(set)
@@ -111,7 +107,7 @@ def get_binds(self, mode=None):
the filtered stack list and modkey & non-stack globals.'''

if mode is None:
mode = self.uzbl.get_mode()
mode = self.uzbl.config.get('mode', None)

if not mode:
mode = 'global'
@@ -145,24 +141,6 @@ def add_bind(self, mode, glob, bind=None):
self.globals.append(bind)


def add_instance(uzbl, *args):
UZBLS[uzbl] = Bindlet(uzbl)


def del_instance(uzbl, *args):
if uzbl in UZBLS:
del UZBLS[uzbl]


def get_bindlet(uzbl):
'''Return the bind tracklet for the given uzbl instance.'''

if uzbl not in UZBLS:
add_instance(uzbl)

return UZBLS[uzbl]


def ismodbind(glob):
'''Return True if the glob specifies a modbind.'''

@@ -324,7 +302,7 @@ def exec_bind(uzbl, bind, *args, **kargs):
def mode_bind(uzbl, modes, glob, handler=None, *args, **kargs):
'''Add a mode bind.'''

bindlet = get_bindlet(uzbl)
bindlet = uzbl.bindlet

if not hasattr(modes, '__iter__'):
modes = unicode(modes).split(',')
@@ -400,7 +378,8 @@ def mode_changed(uzbl, mode):
'''Clear the stack on all non-stack mode changes.'''

if mode != 'stack':
get_bindlet(uzbl).reset()
uzbl.bindlet.reset()
uzbl.clear_keycmd()


def match_and_exec(uzbl, bind, depth, keylet, bindlet):
@@ -440,15 +419,15 @@ def match_and_exec(uzbl, bind, depth, keylet, bindlet):
args = bindlet.args + args
exec_bind(uzbl, bind, *args)
if not has_args or on_exec:
uzbl.set_mode()
del uzbl.config['mode']
bindlet.reset()
uzbl.clear_current()

return True


def key_event(uzbl, keylet, mod_cmd=False, on_exec=False):
bindlet = get_bindlet(uzbl)
bindlet = uzbl.bindlet
depth = bindlet.depth
for bind in bindlet.get_binds():
t = bind[depth]
@@ -463,12 +442,14 @@ def key_event(uzbl, keylet, mod_cmd=False, on_exec=False):
# Return to the previous mode if the KEYCMD_EXEC keycmd doesn't match any
# binds in the stack mode.
if on_exec and not mod_cmd and depth and depth == bindlet.depth:
uzbl.set_mode()
del uzbl.config['mode']


# plugin init hook
def init(uzbl):
# Event handling hooks.
uzbl.connect_dict({
'''Export functions and connect handlers to events.'''

connect_dict(uzbl, {
'BIND': parse_bind,
'MODE_BIND': parse_mode_bind,
'MODE_CHANGED': mode_changed,
@@ -481,12 +462,10 @@ def init(uzbl):
for mod_cmd in range(2):
for on_exec in range(2):
event = events[mod_cmd][on_exec]
uzbl.connect(event, key_event, bool(mod_cmd), bool(on_exec))
connect(uzbl, event, key_event, bool(mod_cmd), bool(on_exec))

# Function exports to the uzbl object, `function(uzbl, *args, ..)`
# becomes `uzbl.function(*args, ..)`.
uzbl.export_dict({
export_dict(uzbl, {
'bind': bind,
'mode_bind': mode_bind,
'get_bindlet': get_bindlet,
'bindlet': Bindlet(uzbl),
})
@@ -35,8 +35,6 @@ def cmd_expand(uzbl, cmd, args):

return cmd


# plugin init hook
def init(uzbl):
# Function exports to the uzbl object, `function(uzbl, *args, ..)`
# becomes `uzbl.function(*args, ..)`.
uzbl.export('cmd_expand', cmd_expand)
export(uzbl, 'cmd_expand', cmd_expand)
Oops, something went wrong.

0 comments on commit d3cbe16

Please sign in to comment.