diff options
author | Mason Larobina <mason.larobina@gmail.com> | 2009-10-15 00:08:45 +0800 |
---|---|---|
committer | Mason Larobina <mason.larobina@gmail.com> | 2009-10-15 00:08:45 +0800 |
commit | fdd8d07eba9e483baf618b6d8fd928fefb8465f3 (patch) | |
tree | 26ea2f4359db95f27ec80224d7f9b13766845eb0 /examples/data/uzbl/plugins/plugin_template.py | |
parent | 847ddc83ccbd7964898980f3f4dd520937ea3bbe (diff) |
Added multi-instance managing to event_manager.py
1. Moved plugin directory from './examples/data/scripts/plugins' to
'./examples/data/'.
2. Broke up the plugin manager class into two small functions.
3. Removed the handler objects ability to have non-callable handlers
given that there is a perfectly good on_event.py plugin which can
do exactly the same.
4. Gave event_manager daemon abilities similar to the cookie_daemon.
5. Using pid to track the event manager daemons running status.
6. Added the ability to load plugins from multiple locations.
7. Removed all outgoing message queues as this work-around is no longer
required after the newly added --connect-socket uzbl-core ability.
8. Removed native stdin/fifo reading ability. Use socat if required.
9. Updated uzbl-browser script to load example cookie_daemon if
cookie_daemon is not in $XDG_DATA_HOME/uzbl/scripts/
10. Added a new event_manager.py launcher uzbl-daemon.
11. Updated make test-dev-browser target to test uzbl-daemon also.
12. Added init like {start|stop|restart} to the event manager.
13. Added a fourth 'list' option to {start|stop|..} to list the plugins
and dirs of each plugin that would be loaded by the event manager.
Diffstat (limited to 'examples/data/uzbl/plugins/plugin_template.py')
-rw-r--r-- | examples/data/uzbl/plugins/plugin_template.py | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/examples/data/uzbl/plugins/plugin_template.py b/examples/data/uzbl/plugins/plugin_template.py new file mode 100644 index 0000000..03cb748 --- /dev/null +++ b/examples/data/uzbl/plugins/plugin_template.py @@ -0,0 +1,75 @@ +'''Plugin template.''' + +# A list of functions this plugin exports to be used via uzbl object. +__export__ = ['myplugin_function',] + +# Holds the per-instance data dict. +UZBLS = {} + +# The default instance dict. +DEFAULTS = {} + + +def add_instance(uzbl, *args): + '''Add a new instance with default config options.''' + + UZBLS[uzbl] = dict(DEFAULTS) + + +def del_instance(uzbl, *args): + '''Delete data stored for an instance.''' + + if uzbl in UZBLS: + del UZBLS[uzbl] + + +def get_myplugin_dict(uzbl): + '''Get data stored for an instance.''' + + if uzbl not in UZBLS: + add_instance(uzbl) + + return UZBLS[uzbl] + + +def myplugin_function(uzbl, *args, **kargs): + '''Custom plugin function which is exported by the __export__ list at the + top of the file for use by other functions/callbacks.''' + + print "My plugin function arguments:", args, kargs + + # Get the per-instance data object. + data = get_myplugin_dict(uzbl) + + # Function logic goes here. + + +def myplugin_event_parser(uzbl, args): + '''Parses MYPLUGIN_EVENT raised by uzbl or another plugin.''' + + print "Got MYPLUGIN_EVENT with arguments: %r" % args + + # Parsing logic goes here. + + +def init(uzbl): + '''The main function of the plugin which is used to attach all the event + hooks that are going to be used throughout the plugins life. This function + is called each time a UzblInstance() object is created in the event + manager.''' + + # Make a dictionary comprising of {"EVENT_NAME": handler, ..} to the event + # handler stack: + connects = { + 'INSTANCE_START': add_instance, + 'INSTANCE_EXIT': del_instance, + 'MYPLUGIN_EVENT': myplugin_event_parser, + } + + # And connect the dicts event handlers to the handler stack. + uzbl.connect_dict(connects) + + # Or connect a handler to an event manually and supply additional optional + # arguments: + + #uzbl.connect("MYOTHER_EVENT", myother_event_parser, True, limit=20) |