diff options
author | Anton Khirnov <anton@khirnov.net> | 2020-04-23 14:33:51 +0200 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2020-04-23 14:33:51 +0200 |
commit | cb069bdeab97bbe4be47e2a0041e5a4a404796fd (patch) | |
tree | 73c8bf673496cc09f9eb81f45f0f19bd21ad724d /alot/buffers | |
parent | aa2d9e486219aff9abb9c113ba3e3de19cbda3db (diff) |
ui: rewrite notification/status bar handling
Do not recreate all the widgets on every update, just update the widget
contents.
Make the statusbar update async, since some calls to get_info() can take
a long time (especially noticeable for counting threads for searches
with many results).
Diffstat (limited to 'alot/buffers')
-rw-r--r-- | alot/buffers/search.py | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/alot/buffers/search.py b/alot/buffers/search.py index 15e9f41f..7d327f23 100644 --- a/alot/buffers/search.py +++ b/alot/buffers/search.py @@ -87,7 +87,9 @@ class SearchBuffer(Buffer): """shows a result list of threads for a query""" modename = 'search' - threads = [] + + _result_count_val = None + _thread_count_val = None def __init__(self, ui, initialquery='', sort_order=None): self.dbman = ui.dbman @@ -95,8 +97,6 @@ class SearchBuffer(Buffer): self.querystring = initialquery default_order = settings.get('search_threads_sort_order') self.sort_order = sort_order or default_order - self.result_count = 0 - self.thread_count = 0 self.proc = None # process that fills our pipe self.rebuild() Buffer.__init__(self, ui, self.body) @@ -104,15 +104,26 @@ class SearchBuffer(Buffer): def __str__(self): formatstring = '[search] for "%s" (%d message%s in %d thread%s)' return formatstring % (self.querystring, - self.result_count, 's' if self.result_count > 1 else '', - self.thread_count, 's' if self.thread_count > 1 else '') + self._result_count, 's' if self._result_count > 1 else '', + self._thread_count, 's' if self._thread_count > 1 else '') + + @property + def _result_count(self): + if self._result_count_val is None: + self._result_count_val = self.dbman.count_messages(self.querystring) + return self._result_count_val + @property + def _thread_count(self): + if self._thread_count_val is None: + self._thread_count_val = self.dbman.count_threads(self.querystring) + return self._thread_count_val def get_info(self): info = {} info['querystring'] = self.querystring - info['result_count'] = self.result_count - info['thread_count'] = self.thread_count - info['result_count_positive'] = 's' if self.result_count > 1 else '' + info['result_count'] = self._result_count + info['thread_count'] = self._thread_count + info['result_count_positive'] = 's' if info['result_count'] > 1 else '' return info def cleanup(self): @@ -134,9 +145,10 @@ class SearchBuffer(Buffer): if exclude_tags: exclude_tags = [t for t in exclude_tags.split(';') if t] + self._result_count_val = None + self._thread_count_val = None + try: - self.result_count = self.dbman.count_messages(self.querystring) - self.thread_count = self.dbman.count_threads(self.querystring) self.pipe, self.proc = self.dbman.get_threads(self.querystring, self.sort_order, exclude_tags) |