diff options
Diffstat (limited to 'docs/write_hooks.rst')
-rw-r--r-- | docs/write_hooks.rst | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/docs/write_hooks.rst b/docs/write_hooks.rst index dd60367b7..a088a3ed3 100644 --- a/docs/write_hooks.rst +++ b/docs/write_hooks.rst @@ -23,10 +23,9 @@ All Hooks should start with something like this: :: __version__ = "0.1" __description__ = "Does really cool stuff" __config__ = [ ("activated" , "bool" , "Activated" , "True" ) ] - __threaded__ = ["downloadFinished"] __author_name__ = ("Me") __author_mail__ = ("me@has-no-mail.com") - + All meta-data is defined in the header, you need at least one option at ``__config__`` so the user can toggle your hook on and off. Dont't overwrite the ``init`` method if not neccesary, use ``setup`` instead. @@ -35,7 +34,7 @@ Using the Config We are taking a closer look at the ``__config__`` parameter. You can add more config values as desired by adding tuples of the following format to the config list: ``("name", "type", "description", "default value")``. -When everything went right you can access the config values with ``self.getConfig(name)`` and ``self.setConfig(name,value``. +When everything went right you can access the config values with ``self.getConfig(name)`` and ``self.setConfig(name, value``. Interacting on Events @@ -65,9 +64,6 @@ A basic excerpt would look like: :: def downloadFinished(self, pyfile): print "A Download just finished." -Another important feature to mention can be seen at the ``__threaded__`` parameter. Function names listed will be executed -in a thread, in order to not block the main thread. This should be used for all kind of longer processing tasks. - Another and more flexible and powerful way is to use event listener. All hook methods exists as event and very useful additional events are dispatched by the core. For a little overview look at :class:`HookManager <module.HookManager.HookManager>`. Keep in mind that you can define own events and other people may listen on them. @@ -81,7 +77,7 @@ It requires a `dict` that maps event names to function names or a `list` of func """ Your Hook code here. """ - event_map = {"downloadFinished" : "doSomeWork", + event_map = {"downloadFinished": "doSomeWork", "allDownloadsFnished": "someMethod", "coreReady": "initialize"} @@ -117,7 +113,7 @@ Sounds complicated but is very easy to do. Just use the ``Expose`` decorator: :: """ Your Hook code here. """ - + @Expose def invoke(self, arg): print "Invoked with", arg @@ -158,5 +154,5 @@ Usable with: :: Example ------- Sorry but you won't find an example here ;-) - + Look at :file:`module/plugins/hooks` and you will find plenty examples there. |