Skip to content

Commit d3cbe16

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.
1 parent ae15d25 commit d3cbe16

File tree

13 files changed

+1009
-1189
lines changed

13 files changed

+1009
-1189
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ test-uzbl-browser-sandbox: uzbl-browser
6363
make DESTDIR=./sandbox RUN_PREFIX=`pwd`/sandbox/usr/local install-example-data
6464
cp -np ./misc/env.sh ./sandbox/env.sh
6565
source ./sandbox/env.sh && uzbl-cookie-daemon restart -nv &
66-
source ./sandbox/env.sh && uzbl-event-manager restart -nav &
66+
source ./sandbox/env.sh && uzbl-event-manager restart -navv &
6767
source ./sandbox/env.sh && uzbl-browser --uri http://www.uzbl.org --verbose
6868
source ./sandbox/env.sh && uzbl-cookie-daemon stop -v
69-
source ./sandbox/env.sh && uzbl-event-manager stop -v
69+
source ./sandbox/env.sh && uzbl-event-manager stop -ivv
7070
make DESTDIR=./sandbox uninstall
7171
rm -rf ./sandbox/usr
7272

examples/config/config

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ set mode_bind = request MODE_BIND
1414
set mode_config = request MODE_CONFIG
1515
# request ON_EVENT <EVENT_NAME> <command>
1616
set on_event = request ON_EVENT
17-
# request PROGRESS_CONFIG <key> = <value>
18-
set progress = request PROGRESS_CONFIG
17+
# request ON_SET <key/glob> <command>
18+
set on_set = request ON_SET
1919
# request MODMAP <From> <To>
2020
set modmap = request MODMAP
2121
# request IGNORE_KEY <glob>
@@ -93,7 +93,7 @@ set hint_style = weight="bold"
9393

9494
set mode_section = <span background="khaki" foreground="black">[\@[\@mode_indicator]\@]</span>
9595
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>]
96-
set progress_section = <span foreground="#606060">\@[\@progress_format]\@</span>
96+
set progress_section = <span foreground="#606060">\@[\@progress.output]\@</span>
9797
set scroll_section = <span foreground="#606060">\@[\@scroll_message]\@</span>
9898
set uri_section = <span foreground="#99FF66">\@[\@uri]\@</span>
9999
set name_section = <span foreground="khaki">\@[\@NAME]\@</span>
@@ -104,19 +104,19 @@ set status_format = <span font_family="monospace">@mode_section @keycmd_sect
104104

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

107-
# Progress bar config
108-
@progress width = 8
107+
# --- Progress bar configuration (progress_bar.py plugin) ---
109108
# %d = done, %p = pending %c = percent done, %i = int done, %s = spinner,
110109
# %t = percent pending, %o = int pending, %r = sprite scroll
111-
@progress format = [%d>%p]%c
112-
@progress done = =
113-
@progress pending =
114-
115-
# Or ride those spinnas'
116-
#@progress format = [%d%s%p]
117-
#@progress spinner = -\\|/
118-
#@progress done = -
119-
#@progress pending =
110+
set progress.width = 8
111+
set progress.format = [%d>%p]%c
112+
set progress.done = =
113+
set progress.pending =
114+
115+
# Or using a spinner:
116+
#set progress.format = [%d%s%p]
117+
#set progress.spinner = -\\|/
118+
#set progress.done = -
119+
#set progress.pending =
120120

121121

122122
# === Core settings ==========================================================

examples/data/plugins/bind.py

Lines changed: 21 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111

1212
import sys
1313
import re
14-
import pprint
15-
16-
# Hold the bind dicts for each uzbl instance.
17-
UZBLS = {}
1814

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

6359
if self.last_mode:
6460
mode, self.last_mode = self.last_mode, None
65-
self.uzbl.set_mode(mode)
61+
self.uzbl.config['mode'] = mode
6662

67-
self.uzbl.set('keycmd_prompt')
63+
del self.uzbl.config['keycmd_prompt']
6864

6965

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

7773
return
7874

79-
current_mode = self.uzbl.get_mode()
80-
if current_mode != 'stack':
81-
self.last_mode = current_mode
82-
self.uzbl.set_mode('stack')
75+
mode = self.uzbl.config.get('mode', None)
76+
if mode != 'stack':
77+
self.last_mode = mode
78+
self.uzbl.config['mode'] = 'stack'
8379

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

9894
self.uzbl.clear_keycmd()
9995
if prompt:
100-
self.uzbl.set('keycmd_prompt', prompt)
96+
self.uzbl.config['keycmd_prompt'] = prompt
10197

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

113109
if mode is None:
114-
mode = self.uzbl.get_mode()
110+
mode = self.uzbl.config.get('mode', None)
115111

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

147143

148-
def add_instance(uzbl, *args):
149-
UZBLS[uzbl] = Bindlet(uzbl)
150-
151-
152-
def del_instance(uzbl, *args):
153-
if uzbl in UZBLS:
154-
del UZBLS[uzbl]
155-
156-
157-
def get_bindlet(uzbl):
158-
'''Return the bind tracklet for the given uzbl instance.'''
159-
160-
if uzbl not in UZBLS:
161-
add_instance(uzbl)
162-
163-
return UZBLS[uzbl]
164-
165-
166144
def ismodbind(glob):
167145
'''Return True if the glob specifies a modbind.'''
168146

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

327-
bindlet = get_bindlet(uzbl)
305+
bindlet = uzbl.bindlet
328306

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

402380
if mode != 'stack':
403-
get_bindlet(uzbl).reset()
381+
uzbl.bindlet.reset()
382+
uzbl.clear_keycmd()
404383

405384

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

447426
return True
448427

449428

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

468447

448+
# plugin init hook
469449
def init(uzbl):
470-
# Event handling hooks.
471-
uzbl.connect_dict({
450+
'''Export functions and connect handlers to events.'''
451+
452+
connect_dict(uzbl, {
472453
'BIND': parse_bind,
473454
'MODE_BIND': parse_mode_bind,
474455
'MODE_CHANGED': mode_changed,
@@ -481,12 +462,10 @@ def init(uzbl):
481462
for mod_cmd in range(2):
482463
for on_exec in range(2):
483464
event = events[mod_cmd][on_exec]
484-
uzbl.connect(event, key_event, bool(mod_cmd), bool(on_exec))
465+
connect(uzbl, event, key_event, bool(mod_cmd), bool(on_exec))
485466

486-
# Function exports to the uzbl object, `function(uzbl, *args, ..)`
487-
# becomes `uzbl.function(*args, ..)`.
488-
uzbl.export_dict({
467+
export_dict(uzbl, {
489468
'bind': bind,
490469
'mode_bind': mode_bind,
491-
'get_bindlet': get_bindlet,
470+
'bindlet': Bindlet(uzbl),
492471
})

examples/data/plugins/cmd_expand.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ def cmd_expand(uzbl, cmd, args):
3535

3636
return cmd
3737

38-
38+
# plugin init hook
3939
def init(uzbl):
40-
# Function exports to the uzbl object, `function(uzbl, *args, ..)`
41-
# becomes `uzbl.function(*args, ..)`.
42-
uzbl.export('cmd_expand', cmd_expand)
40+
export(uzbl, 'cmd_expand', cmd_expand)

0 commit comments

Comments
 (0)