def __invoke(self, librarian, event, *args): args = list(args) if args and args[0]: if isinstance(args[0], dict): args[0] = SongWrapper(args[0]) elif isinstance(args[0], (set, list)): args[0] = ListWrapper(args[0]) for plugin in itervalues(self.__plugins): method_name = 'plugin_on_' + event.replace('-', '_') handler = getattr(plugin, method_name, None) def overridden(obj, name): return name in type(obj).__dict__ if overridden(plugin, method_name): try: handler(*args) except Exception: print_e("Error during %s on %s" % (method_name, type(plugin))) util.print_exc() if event not in ["removed", "changed"] and args: from quodlibet import app songs = args[0] if not isinstance(songs, (set, list)): songs = [songs] songs = filter(None, songs) check_wrapper_changed(librarian, app.window, songs)
def Menu(self, library, songs): songs = ListWrapper(songs) attrs = [ 'plugin_song', 'plugin_songs', 'plugin_album', 'plugin_albums' ] if len(songs) == 1: attrs.append('plugin_single_song') last = (songs and songs[-1]) or None for song in songs: if song.album_key != last.album_key: break last = song else: attrs.append('plugin_single_album') items = [] kinds = self.__plugins kinds.sort(key=lambda plugin: plugin.PLUGIN_ID) for Kind in kinds: usable = any(callable(getattr(Kind, s)) for s in attrs) if usable: try: items.append(Kind(songs, library)) except: print_e( "Couldn't initialise song plugin %s. Stack trace:" % Kind) errorhook() items = [i for i in items if i.initialized] if items: menu = Gtk.Menu() for item in items: try: menu.append(item) args = (library, songs) if item.get_submenu(): for subitem in item.get_submenu().get_children(): subitem.connect('activate', self.__on_activate, item, *args) else: item.connect('activate', self.__on_activate, item, *args) except: errorhook() item.destroy() menu.append(SeparatorMenuItem()) prefs = Gtk.MenuItem(label=_("Configure Plugins…")) prefs.connect("activate", lambda _: PluginWindow().show()) menu.append(prefs) else: menu = None return menu
def Menu(self, library, parent, songs): songs = ListWrapper(songs) parent = qltk.get_top_parent(parent) attrs = [ 'plugin_song', 'plugin_songs', 'plugin_album', 'plugin_albums' ] if len(songs) == 1: attrs.append('plugin_single_song') last = (songs and songs[-1]) or None for song in songs: if song.album_key != last.album_key: break last = song else: attrs.append('plugin_single_album') items = [] kinds = self.__plugins kinds.sort(key=lambda plugin: plugin.PLUGIN_ID) for Kind in kinds: usable = max([callable(getattr(Kind, s)) for s in attrs]) if usable: try: items.append(Kind(songs, library, parent)) except: print_e( "Couldn't initialise song plugin %s. Stack trace:" % Kind) print_exc() items = filter(lambda i: i.initialized, items) if items: menu = Gtk.Menu() for item in items: try: menu.append(item) args = (library, parent, songs) if item.get_submenu(): for subitem in item.get_submenu().get_children(): subitem.connect_object('activate', self.__handle, item, *args) else: item.connect('activate', self.__handle, *args) except: print_exc() item.destroy() else: menu = None return menu
def handle(self, plugin_id, library, parent, songs): """Start a song menu plugin directly without a menu""" for plugin in self.__plugins: if plugin.PLUGIN_ID == plugin_id: songs = ListWrapper(songs) try: plugin = plugin(songs, library, parent) except Exception: print_exc() else: self.__handle(plugin, library, parent, songs) return
def handle(self, plugin_id, library, parent, songs): """Start a song menu plugin directly without a menu""" parent = get_top_parent(parent) for plugin in self.__plugins: if plugin.PLUGIN_ID == plugin_id: songs = ListWrapper(songs) try: plugin = plugin(songs, library) except Exception: errorhook() else: self.__handle(plugin, plugin, library, songs, parent) return
def __invoke(self, librarian, event, *args): args = list(args) if args and args[0]: if isinstance(args[0], dict): args[0] = SongWrapper(args[0]) elif isinstance(args[0], (set, list)): args[0] = ListWrapper(args[0]) for plugin in self.__plugins.itervalues(): method_name = 'plugin_on_' + event.replace('-', '_') handler = getattr(plugin, method_name, None) if handler is not None: try: handler(*args) except Exception: util.print_exc() if event not in ["removed", "changed"] and args: from quodlibet import app songs = args[0] if not isinstance(songs, (set, list)): songs = [songs] songs = filter(None, songs) check_wrapper_changed(librarian, app.window, songs)
def test_none(self): wrapped = ListWrapper([None, None]) self.failUnless(len(wrapped) == 2) self.failUnlessEqual(wrapped, [None, None])
def test_empty_song(self): wrapped = ListWrapper([{}]) self.failUnless(len(wrapped) == 1) self.failIf(isinstance(wrapped[0], dict))
def test_empty(self): wrapped = ListWrapper([]) self.failUnlessEqual(wrapped, [])