summaryrefslogtreecommitdiff
path: root/alot/walker.py
diff options
context:
space:
mode:
Diffstat (limited to 'alot/walker.py')
-rw-r--r--alot/walker.py30
1 files changed, 20 insertions, 10 deletions
diff --git a/alot/walker.py b/alot/walker.py
index e4264103..cfefc9e6 100644
--- a/alot/walker.py
+++ b/alot/walker.py
@@ -1,20 +1,30 @@
# Copyright (C) 2011-2012 Patrick Totzke <patricktotzke@gmail.com>
+# Copyright © 2018 Dylan Baker
# This file is released under the GNU GPL, version 3 or a later revision.
# For further details see the COPYING file
import logging
import urwid
-class PipeWalker(urwid.ListWalker):
- """urwid.ListWalker that reads next items from a pipe and wraps them in
- `containerclass` widgets for displaying
+class IterableWalker(urwid.ListWalker):
- Attributes that should be considered publicly readable:
- :attr lines: the lines obtained from the pipe
- :type lines: list(`containerclass`)
+ """An urwid walker for iterables.
+
+ Works like ListWalker, except it takes an iterable object instead of a
+ concrete type. This allows for lazy operations of very large sequences of
+ data, such as a sequences of threads with certain notmuch tags.
+
+ :param iterable: An iterator of objects to walk over
+ :type iterable: Iterable[T]
+ :param containerclass: An urwid widget to wrap each object in
+ :type containerclass: urwid.Widget
+ :param reverse: Reverse the order of the iterable
+ :type reverse: bool
+ :param **kwargs: Forwarded to container class.
"""
- def __init__(self, pipe, containerclass, reverse=False, **kwargs):
- self.pipe = pipe
+
+ def __init__(self, iterable, containerclass, reverse=False, **kwargs):
+ self.iterable = iterable
self.kwargs = kwargs
self.containerclass = containerclass
self.lines = []
@@ -71,10 +81,10 @@ class PipeWalker(urwid.ListWalker):
try:
# the next line blocks until it can read from the pipe or
# EOFError is raised. No races here.
- next_obj = self.pipe.recv()
+ next_obj = next(self.iterable)
next_widget = self.containerclass(next_obj, **self.kwargs)
self.lines.append(next_widget)
- except EOFError:
+ except StopIteration:
logging.debug('EMPTY PIPE')
next_widget = None
self.empty = True