From 0b9265d815eccf8c594941437a0d0ed307fae9bb Mon Sep 17 00:00:00 2001 From: Jeffrey Aylesworth Date: Sun, 29 Aug 2010 09:38:20 -0400 Subject: [PATCH] add an event listener --- beets/events.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/beets/events.py b/beets/events.py index 6650b93ff..61958d8b4 100644 --- a/beets/events.py +++ b/beets/events.py @@ -12,3 +12,20 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +#All the handlers for the event system. +#Each key of the dictionary should contain a list of functions to be called +#for any event. Functions will be called in the order they were added. +handlers = { } + +def addEventListener(event, function): + """Adds an event listener to call function() when the specified event + (as a string) happens. The parameters passed to function will vary + depending on what event occured. + + The function should respond to named parameters. function(**kwargs) will + trap all arguments in a dictionary.""" + global handlers + + if event not in handlers: + handlers[event] = [ ] #Empty list to store the handlers + handlers[event].append(function)