docs/whitespace and change register_listener to a class method

This commit is contained in:
Adrian Sampson 2011-04-09 13:15:19 -07:00
parent dae0d650f8
commit 565257988a
3 changed files with 19 additions and 11 deletions

4
NEWS
View file

@ -1,5 +1,9 @@
1.0b8
-----
* Added a new plugin event, "imported_album", which is called every
time an album is added to the library. (Thanks, Lugoues!)
* A new plugin method, register_listener, is an imperative alternative
to the @listen decorator (Thanks again, Lugoues!)
* In path formats, $albumartist now falls back to $artist (as well as
the other way around).
* Fix adding individual tracks in BPD.

View file

@ -64,12 +64,16 @@ class BeetsPlugin(object):
pass
listeners = None
def register_listener(self, event, func):
if self.listeners is None:
self.listeners = defaultdict(list)
self.listeners[event].append(func)
@classmethod
def register_listener(cls, event, func):
"""Add a function as a listener for the specified event. (An
imperative alternative to the @listen decorator.)
"""
if cls.listeners is None:
cls.listeners = defaultdict(list)
cls.listeners[event].append(func)
@classmethod
def listen(cls, event):
"""Decorator that adds a function as an event handler for the

View file

@ -532,9 +532,9 @@ def apply_choices(lib, copy, write, art, delete, progress):
# Write the database after each album.
lib.save()
#annouce that we added an album
# Announce that we've added an album.
plugins.send('album_imported', album=albuminfo)
# Finally, delete old files.
if copy and delete:
new_paths = [os.path.realpath(item.path) for item in items]
@ -565,10 +565,10 @@ def simple_import(lib, paths, copy, delete, resume):
album = lib.add_album(items, True)
lib.save()
#annouce that we added an album
# Announce that we added an album.
plugins.send('album_imported', album=album)
if resume is not False:
progress_set(toppath, path)