From: W. Trevor King Date: Tue, 18 May 2010 16:35:22 +0000 (-0400) Subject: Allow extra arguments to NoteIndexList.filter's filter_fn X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=824c27233638e4f877bfb5fef2070af1bff625f6;p=hooke.git Allow extra arguments to NoteIndexList.filter's filter_fn --- diff --git a/hooke/playlist.py b/hooke/playlist.py index ca38b4e..336c344 100644 --- a/hooke/playlist.py +++ b/hooke/playlist.py @@ -62,10 +62,10 @@ class NoteIndexList (list): def previous(self): self.jump(self._index - 1) - def filter(self, keeper_fn=lambda item:True): + def filter(self, keeper_fn=lambda item:True, *args, **kwargs): c = copy.deepcopy(self) for item in reversed(c): - if keeper_fn(item) != True: + if keeper_fn(item, *args, **kwargs) != True: c.remove(item) try: # attempt to maintain the same current item c._index = c.index(self.current()) diff --git a/hooke/plugin/playlist.py b/hooke/plugin/playlist.py index 01d24b7..21a6419 100644 --- a/hooke/plugin/playlist.py +++ b/hooke/plugin/playlist.py @@ -274,7 +274,8 @@ class FilterCommand (Command): self.arguments.append( Argument(name='filter', type='function', optional=False, help=""" -Function returning `True` for "good" curves. `filter(curve) -> True/False`. +Function returning `True` for "good" curves. +`filter(curve, hooke, inqueue, outqueue, params) -> True/False`. """.strip())) def _run(self, hooke, inqueue, outqueue, params): @@ -282,7 +283,8 @@ Function returning `True` for "good" curves. `filter(curve) -> True/False`. filter_fn = params['filter'] else: filter_fn = self.filter_fn - p = params['playlist'].filter(filter_fn) + p = params['playlist'].filter(filter_fn, + hooke=hooke, inqueue=inqueue, outqueue=outqueue, params=params) hooke.playlists.add(p) outqueue.put(p) @@ -292,5 +294,5 @@ class NoteFilterCommand (FilterCommand): def __init__(self, plugin): super(NoteFilterCommand, self).__init__( plugin, name='note filter playlist', - filter_fn=lambda curve : \ + filter_fn=lambda curve, hooke, inqueue, outqueue, params : \ 'note' in curve.info and curve.info['note'] != None)