From: W. Trevor King Date: Tue, 3 Aug 2010 15:16:36 +0000 (-0400) Subject: Fix NoteIndexList.index implementation and add NoteIndexList.items X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=505af0ca38636f595b19cf7f9bed82f29512a401;p=hooke.git Fix NoteIndexList.index implementation and add NoteIndexList.items --- diff --git a/hooke/playlist.py b/hooke/playlist.py index ed05b35..8444c9a 100644 --- a/hooke/playlist.py +++ b/hooke/playlist.py @@ -52,8 +52,13 @@ class NoteIndexList (list): """ pass - def index(self): - return self._index + def index(self, value=None, *args, **kwargs): + """Extend `list.index`, returning the current index if `value` + is `None`. + """ + if value == None: + return self._index + return super(NoteIndexList, self).index(value, *args, **kwargs) def current(self): if len(self) == 0: @@ -74,10 +79,20 @@ class NoteIndexList (list): def previous(self): self.jump(self._index - 1) + def items(self, reverse=False): + """Iterate through `self` calling `_setup_item` on each item + before yielding. + """ + items = self + if reverse == True: + items = reversed(self) + for item in items: + self._setup_item(item) + yield item + def filter(self, keeper_fn=lambda item:True, *args, **kwargs): c = copy.deepcopy(self) - for item in reversed(c): - c._setup_item(item) + for item in c.items(reverse=True): if keeper_fn(item, *args, **kwargs) != True: c.remove(item) try: # attempt to maintain the same current item