diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/config/config | 9 | ||||
-rwxr-xr-x | examples/data/scripts/uzbl-event-manager | 41 | ||||
-rwxr-xr-x | examples/data/scripts/uzbl-tabbed | 30 |
3 files changed, 61 insertions, 19 deletions
diff --git a/examples/config/config b/examples/config/config index cd6a0c0..ae97443 100644 --- a/examples/config/config +++ b/examples/config/config @@ -57,12 +57,12 @@ set new_window = sh 'uzbl-browser -u $8' # Load start handler @on_event LOAD_START @set_status <span foreground="khaki">wait</span> +# Reset the keycmd on navigation +@on_event LOAD_START @set_mode # Load commit handlers @on_event LOAD_COMMIT @set_status <span foreground="green">recv</span> #@on_event LOAD_COMMIT script @scripts_dir/scroll-percentage.js -# Reset the keycmd on navigation -@on_event LOAD_COMMIT @set_mode # Load finish handlers @on_event LOAD_FINISH @set_status <span foreground="gold">done</span> @@ -235,7 +235,9 @@ set ebind = @mode_bind global,-insert # --- Uzbl tabbed binds --- # Tab opening @cbind gn = event NEW_TAB +@cbind gN = event NEW_TAB_NEXT @cbind go<uri:>_ = event NEW_TAB %s +@cbind gO<uri:>_ = event NEW_TAB_NEXT %s @cbind gY = sh 'echo "event NEW_TAB `xclip -selection primary -o`" > $4' # Closing / resting @cbind gC = exit @@ -267,7 +269,8 @@ set preset = event PRESET_TABS @cbind !dump = sh "echo dump_config > $4" # Reload config @cbind !reload = sh "sed '/^# === Post-load misc commands/,$d' $1 > $4" -# If you want to see all events being triggered: +# Use socat to directly inject commands into uzbl-core and view events +# raised by uzbl-core: @cbind <Ctrl><Alt>t = sh 'xterm -e "socat unix-connect:$5 -"' #@cbind <Ctrl><Alt>t = sh 'urxvt -e socat unix-connect:$5 -' diff --git a/examples/data/scripts/uzbl-event-manager b/examples/data/scripts/uzbl-event-manager index 9624b14..99773ae 100755 --- a/examples/data/scripts/uzbl-event-manager +++ b/examples/data/scripts/uzbl-event-manager @@ -348,7 +348,7 @@ class EventHandler(object): class UzblInstance(object): # Give all plugins access to the main config dict. - config = CONFIG + global_config = CONFIG def __init__(self, parent, client_socket): @@ -385,21 +385,40 @@ class UzblInstance(object): print (u'%s!-- %s' % (' ' * self.depth, msg)).encode('utf-8') - def export(self, name, function): - '''Export `function(uzbl, *args, ..)` inside a plugin to the uzbl - object like so `uzbl.function(*args, ..)`. This will allow other - plugins to call functions inside the current plugin (which is currently - calling this function) via the uzbl object.''' + def export(self, attr, object, prepend=True): + '''Attach an object to the current class instance. This is the + preferred method of sharing functionality, functions and objects + between plugins. - self.__dict__.__setitem__(name, partial(function, self)) + If the object is callable you may wish to turn the callable object in + to an "instance method call" by using the `functools.partial(..)` + tool to prepend the `self` object to the callable objects argument + list. + + Example session from a plugins POV: + >>> config_dict = {'foo': 'data..', 'bar': 'other data..'} + >>> uzbl.export('config', config_dict) + >>> uzbl.config is config_dict + True + >>> print uzbl.config['foo'] + data.. + >>> uzbl.export('get', lambda uzbl, key: uzbl.config[key]) + >>> print uzbl.get('bar') + other data.. + ''' + + if prepend and callable(object): + object = partial(object, self) + + self.__dict__.__setitem__(attr, object) def export_dict(self, export_dict): - '''Export multiple (name, function)'s at once inside a dict of the - form `{name1: function1, name2: function2, ...}`.''' + '''Export multiple (attr, object)'s at once inside a dict of the + form `{attr1: object1, attr2: object2, ...}`.''' - for (name, function) in export_dict.items(): - self.export(name, function) + for (attr, object) in export_dict.items(): + self.export(attr, object) def connect(self, event, handler, *args, **kargs): diff --git a/examples/data/scripts/uzbl-tabbed b/examples/data/scripts/uzbl-tabbed index 7bd90d5..f07bae4 100755 --- a/examples/data/scripts/uzbl-tabbed +++ b/examples/data/scripts/uzbl-tabbed @@ -371,8 +371,9 @@ class SocketClient: class UzblInstance: '''Uzbl instance meta-data/meta-action object.''' - def __init__(self, parent, tab, name, uri, title, switch): + def __init__(self, parent, tab, name, uri, title, switch, process): + self.process = process self.parent = parent self.tab = tab self.name = name @@ -488,6 +489,13 @@ class UzblInstance: self.parent.update_tablist() elif type == "NEW_TAB": self.parent.new_tab(args) + elif type == "NEW_BG_TAB": + self.parent.new_tab(args, '', 0) + elif type == "NEW_TAB_NEXT": + self.parent.new_tab(args, next=True) + elif type == "NEW_BG_TAB_NEXT": + self.parent.new_tab(args, '', 0, next=True) + elif type == "NEXT_TAB": if args: self.parent.next_tab(int(args)) @@ -521,6 +529,18 @@ class UzblInstance: self._client.close() self._client = None + pid = self.process.pid + timeout = time.time() + 5 + + while self.process.poll() is None and time.time() < timeout: + # Sleep between polls. + time.sleep(0.1) + + if self.process.poll() is None: + # uzbl instance didn't exit in time. + error("quit timeout expired, sending SIGTERM to uzbl instance") + self.process.terminate() + class UzblTabbed: '''A tabbed version of uzbl using gtk.Notebook''' @@ -966,7 +986,7 @@ class UzblTabbed: return False - def new_tab(self, uri='', title='', switch=None): + def new_tab(self, uri='', title='', switch=None, next=False): '''Add a new tab to the notebook and start a new instance of uzbl. Use the switch option to negate config['switch_to_new_tabs'] option when you need to load multiple tabs at a time (I.e. like when @@ -974,7 +994,7 @@ class UzblTabbed: tab = gtk.Socket() tab.show() - self.notebook.append_page(tab) + self.notebook.insert_page(tab, position=next and self.notebook.get_current_page() + 1 or -1) sid = tab.get_id() uri = uri.strip() name = "%d-%d" % (os.getpid(), self.next_pid()) @@ -987,9 +1007,9 @@ class UzblTabbed: cmd = ['uzbl-browser', '-n', name, '-s', str(sid), '--connect-socket', self.socket_path, '--uri', uri] - subprocess.Popen(cmd) # TODO: do i need close_fds=True ? + process = subprocess.Popen(cmd) # TODO: do i need close_fds=True ? - uzbl = UzblInstance(self, tab, name, uri, title, switch) + uzbl = UzblInstance(self, tab, name, uri, title, switch, process) SocketClient.instances_queue[name] = uzbl self.tabs[tab] = uzbl |