aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorGravatar Mason Larobina <mason.larobina@gmail.com>2009-09-21 23:30:40 +0800
committerGravatar Mason Larobina <mason.larobina@gmail.com>2009-09-21 23:30:40 +0800
commit99742e877c6b97bd29c4f47f4c79f6565b4699a0 (patch)
tree789c38a792b3272e3c3c87b6d656cc77d08fd7eb /examples
parent327db778f3a5446d57969bb6ce1e038799aa86aa (diff)
Added progress_bar plugin and updated config with examples.
Diffstat (limited to 'examples')
-rw-r--r--examples/config/uzbl/config22
-rw-r--r--examples/data/uzbl/scripts/plugins/progress_bar.py142
2 files changed, 161 insertions, 3 deletions
diff --git a/examples/config/uzbl/config b/examples/config/uzbl/config
index 9ff27bc..9c690ed 100644
--- a/examples/config/uzbl/config
+++ b/examples/config/uzbl/config
@@ -11,7 +11,8 @@ set mode_config = request MODE_CONFIG
set toggle_modes = request TOGGLE_MODES
# request ON_EVENT <EVENT_NAME> <command>
set on_event = request ON_EVENT
-
+# request PROGRESS_CONFIG <key> = <value>
+set progress = request PROGRESS_CONFIG
set set_mode = set mode =
set set_status = set status_message =
@@ -49,14 +50,29 @@ set prompt_style = foreground="grey"
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 progress_section = <span foreground="#606060">\@[\@LOAD_PROGRESSBAR]\@</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>
set status_section = <span foreground="orange">\@status_message</span>
-set selected_section = <span foreground="#606060"> \@[\@SELECTED_URI]\@</span>
+set selected_section = <span foreground="#606060">\@[\@SELECTED_URI]\@</span>
set status_format = <span font_family="monospace">@mode_section @keycmd_section @progress_section @uri_section @name_section @status_section @selected_section</span>
+# Progress bar config
+@progress width = 8
+# %d = done, %p = pending, %a = arrow, %c = percent done, %i = int done,
+# %s = spinner, %t = percent pending, %o = int pending.
+@progress format = [%d>%p]%c
+@progress spinner = -\\|/
+@progress arrow = >
+@progress done = =
+@progress pending = .
+
+# Or ride those spinnas'
+#@progress format = [%d%s%p]
+#@progress done = -
+#@progress pending =
+
# Core settings
set useragent = Uzbl (Webkit @WEBKIT_MAJOR.@WEBKIT_MINOR.@WEBKIT_MICRO) (@(uname -o)@ @(uname -m)@ [@ARCH_UZBL]) (Commit @COMMIT)
set fifo_dir = /tmp
diff --git a/examples/data/uzbl/scripts/plugins/progress_bar.py b/examples/data/uzbl/scripts/plugins/progress_bar.py
new file mode 100644
index 0000000..450e972
--- /dev/null
+++ b/examples/data/uzbl/scripts/plugins/progress_bar.py
@@ -0,0 +1,142 @@
+import sys
+
+UZBLS = {}
+
+
+DEFAULTS = {'width': 8,
+ 'done': '=',
+ 'pending': '.',
+ 'arrow': '>',
+ 'format': '[%d%a%p]%c',
+ 'spinner': '-\\|/',
+ 'updates': 0,
+ 'progress': 100}
+
+
+def error(msg):
+ sys.stderr.write("progress_bar 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_progress_config(uzbl):
+ if uzbl not in UZBLS:
+ add_instance(uzbl)
+
+ return UZBLS[uzbl]
+
+
+def update_progress(uzbl, prog=None):
+ '''Updates the progress_format variable on LOAD_PROGRESS update.
+
+ The current substitution options are:
+ %d = done char * done
+ %p = pending char * remaining
+ %a = arrow
+ %c = percent done
+ %i = int done
+ %s = -\|/ spinner
+ %t = percent pending
+ %o = int pending
+ '''
+
+ prog_config = get_progress_config(uzbl)
+ config = uzbl.get_config()
+
+ if prog is None:
+ prog = prog_config['progress']
+
+ prog = int(prog)
+ if prog < prog_config['progress']:
+ prog_config['updates'] = 0
+
+ prog_config['updates'] += 1
+ prog_config['progress'] = prog
+ format = prog_config['format']
+ width = prog_config['width']
+
+ # Inflate the done and pending bars to stop the progress bar
+ # jumping around.
+ if '%c' in format or '%i' in format:
+ count = format.count('%c') + format.count('%i')
+ width += (3-len(str(prog))) * count
+
+ if '%t' in format or '%o' in format:
+ count = format.count('%t') + format.count('%o')
+ width += (3-len(str(100-prog))) * count
+
+ done = int(((prog/100.0)*width)+0.5)
+ pending = width - done
+
+ if '%d' in format:
+ format = format.replace('%d', prog_config['done']*done)
+
+ if '%p' in format:
+ format = format.replace('%p', prog_config['pending']*pending)
+
+ if '%a' in format:
+ format = format.replace('%a', prog_config['arrow'])
+
+ if '%c' in format:
+ format = format.replace('%c', '%d%%' % prog)
+
+ if '%i' in format:
+ format = format.replace('%i', '%d' % prog)
+
+ if '%t' in format:
+ format = format.replace('%t', '%d%%' % (100-prog))
+
+ if '%o' in format:
+ format = format.replace('%o', '%d' % (100-prog))
+
+ if '%s' in format:
+ spin = '-' if not prog_config['spinner'] else prog_config['spinner']
+ index = 0 if prog == 100 else prog_config['updates'] % len(spin)
+ char = '\\\\' if spin[index] == '\\' else spin[index]
+ format = format.replace('%s', char)
+
+ if 'progress_format' not in config or config['progress_format'] != format:
+ config['progress_format'] = format
+
+
+def progress_config(uzbl, args):
+ split = args.split('=', 1)
+ if len(split) != 2:
+ return error("invalid syntax: %r" % args)
+
+ key, value = map(str.strip, split)
+ prog_config = get_progress_config(uzbl)
+
+ if key not in prog_config:
+ return error("key error: %r" % args)
+
+ if type(prog_config[key]) == type(1):
+ try:
+ value = int(value)
+
+ except:
+ return error("invalid type: %r" % args)
+
+ elif not value:
+ value = ' '
+
+ prog_config[key] = value
+ update_progress(uzbl)
+
+
+def init(uzbl):
+
+ connects = {'LOAD_PROGRESS': update_progress,
+ 'INSTANCE_START': add_instance,
+ 'INSTANCE_EXIT': del_instance,
+ 'PROGRESS_CONFIG': progress_config}
+
+ for (event, handler) in connects.items():
+ uzbl.connect(event, handler)