diff options
author | Anton Khirnov <anton@khirnov.net> | 2021-02-10 10:23:29 +0100 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2021-02-10 10:23:29 +0100 |
commit | 90e4d88cd4883dd015a511d7f8e1e7e09e062ac4 (patch) | |
tree | 8901d6223a4ec0e56bfee601f94d0f25060df8b7 | |
parent | 78d8f8b9147473be5bed287edd64042b3f90210f (diff) |
buffers/search: do not pass dbman into IterWalker
Use functools.partial to keep the widget construction logic out of
IterWalker, since it should not handle such details.
-rw-r--r-- | alot/buffers/search.py | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/alot/buffers/search.py b/alot/buffers/search.py index 20c0ae47..700ce69f 100644 --- a/alot/buffers/search.py +++ b/alot/buffers/search.py @@ -3,6 +3,7 @@ # For further details see the COPYING file import asyncio +from functools import partial import urwid @@ -18,7 +19,8 @@ class IterWalker(urwid.ListWalker): ThreadlineWidget widgets for displaying """ - _dbman = None + _threads = None + _wgt_factory = None _iter_done = False @@ -29,9 +31,9 @@ class IterWalker(urwid.ListWalker): _focus = None - def __init__(self, threads, dbman): - self._threads = threads - self._dbman = dbman + def __init__(self, threads, wgt_factory): + self._threads = threads + self._wgt_factory = wgt_factory self._tids = [] self._wgts = {} @@ -51,7 +53,7 @@ class IterWalker(urwid.ListWalker): # make sure an exception while constructing the widget does not get # swallowed by urwid try: - self._wgts[pos] = ThreadlineWidget(self._tids[pos], self._dbman) + self._wgts[pos] = self._wgt_factory(self._tids[pos]) except (KeyError, IndexError, TypeError) as e: raise ValueError('Exception while constructing threadline widget') from e @@ -163,9 +165,10 @@ class SearchBuffer(Buffer): self._result_count = None self._thread_count = None - threads = self.dbman.get_threads(self.querystring, self.sort_order, - exclude_tags) - threadlist = IterWalker(threads, self.dbman) + threads = self.dbman.get_threads(self.querystring, self.sort_order, + exclude_tags) + wgt_factory = partial(ThreadlineWidget, dbman = self.dbman) + threadlist = IterWalker(threads, wgt_factory) # check that the query is well-formed try: |