summaryrefslogtreecommitdiff
path: root/alot/widgets
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2020-05-07 15:18:04 +0200
committerAnton Khirnov <anton@khirnov.net>2020-05-07 15:18:04 +0200
commit006c5211f34096392d887ce3ef647ff20823490d (patch)
treed769bb9ac29727c4df1cf3044edf1c5ec6480e6e /alot/widgets
parent2cd2c4dfa147806c45a3654ed6fb79c6a4d8f9f4 (diff)
widgets/thread: refactor/simplify message summary widget
Diffstat (limited to 'alot/widgets')
-rw-r--r--alot/widgets/thread.py52
1 files changed, 26 insertions, 26 deletions
diff --git a/alot/widgets/thread.py b/alot/widgets/thread.py
index 2088bc39..631d6abe 100644
--- a/alot/widgets/thread.py
+++ b/alot/widgets/thread.py
@@ -17,56 +17,49 @@ class MessageSummaryWidget(urwid.WidgetWrap):
one line summary of a :class:`~alot.db.message.Message`.
"""
- def __init__(self, message, odd):
+ _text = None
+
+ def __init__(self, message, attr, attr_focus):
"""
:param message: a message
:type message: alot.db.Message
- :param odd: odd entry in a pile of messages? Used for theming.
- :type odd: bool
"""
- self.message = message
- self.odd = odd
- if odd:
- attr = settings.get_theming_attribute('thread', 'summary', 'odd')
- else:
- attr = settings.get_theming_attribute('thread', 'summary', 'even')
- focus_att = settings.get_theming_attribute('thread', 'summary',
- 'focus')
- cols = []
-
- sumstr = self.__str__()
- txt = urwid.Text(sumstr)
- cols.append(txt)
+ self._text = self._build_text(message)
+ cols = [urwid.Text(self._text)]
if settings.get('msg_summary_hides_threadwide_tags'):
thread_tags = message.thread.get_tags(intersection=True)
outstanding_tags = set(message.get_tags()).difference(thread_tags)
- tag_widgets = sorted(TagWidget(t, attr, focus_att)
+ tag_widgets = sorted(TagWidget(t, attr, attr_focus)
for t in outstanding_tags)
else:
- tag_widgets = sorted(TagWidget(t, attr, focus_att)
+ tag_widgets = sorted(TagWidget(t, attr, attr_focus)
for t in message.get_tags())
for tag_widget in tag_widgets:
if not tag_widget.hidden:
cols.append(('fixed', tag_widget.width(), tag_widget))
- line = urwid.AttrMap(urwid.Columns(cols, dividechars=1), attr,
- focus_att)
+
+ line = urwid.AttrMap(urwid.Columns(cols, dividechars=1),
+ attr, attr_focus)
super().__init__(line)
- def __str__(self):
+ def _build_text(self, msg):
try:
- subj = self.message.headers['Subject']
+ subj = msg.headers['Subject']
except KeyError:
subj = ''
subj = re.sub(r'\n\s+', r' ', ','.join(subj))
- author, address = self.message.get_author()
- date = self.message.get_datestring()
- rep = '%s: %s' % (author if author != '' else address, subj)
+ author, address = msg.get_author()
+ rep = '%s: %s' % (author if author != '' else address, subj)
+ date = msg.get_datestring()
if date is not None:
rep += " (%s)" % date
return rep
+ def __str__(self):
+ return self._text
+
def selectable(self):
return True
@@ -531,7 +524,14 @@ class ThreadNode(urwid.WidgetWrap):
_have_next_sibling = None
def __init__(self, msg, thread, pos, indent):
- msg_summary = MessageSummaryWidget(msg, pos & 1)
+ if pos & 1:
+ attr = settings.get_theming_attribute('thread', 'summary', 'odd')
+ else:
+ attr = settings.get_theming_attribute('thread', 'summary', 'even')
+
+ attr_focus = settings.get_theming_attribute('thread', 'summary', 'focus')
+
+ msg_summary = MessageSummaryWidget(msg, attr, attr_focus)
if msg.depth == 0:
wgt = msg_summary