aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples/data/scripts/uzbl-event-manager
diff options
context:
space:
mode:
authorGravatar Mason Larobina <mason.larobina@gmail.com>2010-03-02 02:04:20 +0800
committerGravatar Mason Larobina <mason.larobina@gmail.com>2010-03-02 02:04:20 +0800
commit944536c6f035816dced88347fcefad6148def7f3 (patch)
treef25b996ae086871de892c8a32f3c3906335969ae /examples/data/scripts/uzbl-event-manager
parentd7e60e00dc876d74dc603d908b37d8257d8e1583 (diff)
Given export method `prepend` option and now allows non-callable exports
Diffstat (limited to 'examples/data/scripts/uzbl-event-manager')
-rwxr-xr-xexamples/data/scripts/uzbl-event-manager41
1 files changed, 30 insertions, 11 deletions
diff --git a/examples/data/scripts/uzbl-event-manager b/examples/data/scripts/uzbl-event-manager
index 757dc27..99773ae 100755
--- a/examples/data/scripts/uzbl-event-manager
+++ b/examples/data/scripts/uzbl-event-manager
@@ -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.'''
-
- self.__dict__.__setitem__(name, partial(function, self))
+ 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.
+
+ 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):