diff options
author | pazz <patricktotzke@gmail.com> | 2011-06-03 09:45:05 +0100 |
---|---|---|
committer | pazz <patricktotzke@gmail.com> | 2011-06-03 09:45:05 +0100 |
commit | 84c43327beba5718aeb80dbdc80fc247ab8c4262 (patch) | |
tree | 91fbf2a5357ec83e17e9e6a66f0bef298990765e /alot | |
parent | 7efd5f34f344c519bc46309dc55eb85491a1ce00 (diff) |
arrows in single thread buffer
Diffstat (limited to 'alot')
-rw-r--r-- | alot/buffer.py | 48 | ||||
-rw-r--r-- | alot/widgets.py | 60 |
2 files changed, 79 insertions, 29 deletions
diff --git a/alot/buffer.py b/alot/buffer.py index 3819d23d..d0770b96 100644 --- a/alot/buffer.py +++ b/alot/buffer.py @@ -21,6 +21,8 @@ import urwid import widgets import command from walker import IteratorWalker +import logging +from itertools import izip_longest class Buffer: @@ -171,9 +173,6 @@ class SingleThreadBuffer(Buffer): def __init__(self, ui, thread): self.message_count = thread.get_total_messages() self.thread = thread - self.messages = list() - for (m,r) in thread.get_messages().items(): - self._build_pile(self.messages, m, r) self.rebuild() Buffer.__init__(self, ui, self.body, 'thread') self.bindings = {} @@ -181,29 +180,36 @@ class SingleThreadBuffer(Buffer): def __str__(self): return '%s, (%d)' % (self.thread.subject, self.message_count) - def _build_pile(self, acc, msg, replies, depth=0): - acc.append((depth, msg)) + def _build_pile(self, acc, childcount, msg, replies, parent, depth=0): + acc.append((parent, depth, msg)) + childcount[parent] += 1 for (m,r) in replies.items(): - self._build_pile(acc, m, r, depth+1) + if m not in childcount: + childcount[m] = 0 + self._build_pile(acc, childcount, m, r, msg, depth+1) def rebuild(self): - msgs = list() - for (num, (depth, m)) in enumerate(self.messages, 1): + messages = list() + childcount = {None: 0} + for (m,r) in self.thread.get_messages().items(): + childcount[None] += 1 + if m not in childcount: + childcount[m] = 0 + self._build_pile(messages, childcount, m, r, None) + logging.info('>>> %s'%(childcount)) + msglines = list() + for (num, (p, depth, m)) in enumerate(messages): if 'unread' in m.get_tags(): m.remove_tags(['unread']) - mwidget = widgets.MessageWidget(m, depth=depth, folded=True) - if (num % 2 == 0): - attr = 'messagesummary_even' - else: - attr = 'messagesummary_odd' - # a spacer of width 0 breaks urwid.Columns - if depth == 0: - line = urwid.AttrMap(urwid.Columns([mwidget]), attr, 'messagesummary_focus') - else: - spacer = urwid.Text((' ' * depth) + u'\u2514\u25b6') - line = urwid.AttrMap(urwid.Columns([('fixed', depth+3, spacer), mwidget]), attr, 'messagesummary_focus') - msgs.append(line) - self.body = urwid.ListBox(msgs) + childcount[p] -=1 + mwidget = widgets.MessageWidget(m, even=(num % 2 == 0), + folded=True, depth=depth, + bars_at=[], + siblings_follow=childcount[p] + ) + msglines.append(mwidget) + logging.info('>>> %s'%(childcount)) + self.body = urwid.ListBox(msglines) def get_selected_message(self): (messagewidget, size) = self.body.get_focus() diff --git a/alot/widgets.py b/alot/widgets.py index 5e5bace3..8771c0b3 100644 --- a/alot/widgets.py +++ b/alot/widgets.py @@ -17,6 +17,7 @@ along with notmuch. If not, see <http://www.gnu.org/licenses/>. Copyright (C) 2011 Patrick Totzke <patricktotzke@gmail.com> """ import email +import urwid from urwid import Text from urwid import Edit from urwid import Pile @@ -26,6 +27,7 @@ from urwid import WidgetWrap from urwid import ListBox from urwid import SimpleListWalker from datetime import datetime +import logging import settings from helper import shorten @@ -176,10 +178,14 @@ class PromptWidget(AttrMap): class MessageWidget(WidgetWrap): - def __init__(self, message, depth=0, folded=True): + def __init__(self, message, even=False, folded=True, depth=0, bars_at=[], + siblings_follow=False): self.message = message self.depth = depth - self.sumw = MessageSummaryWidget(self.message) + self.bars_at = bars_at + self.siblings_follow = siblings_follow + self.even = even + self.sumw = self._build_sum_widget() self.headerw = None self.bodyw = None self.displayed_list = [self.sumw] @@ -188,24 +194,62 @@ class MessageWidget(WidgetWrap): self.body = Pile(self.displayed_list) WidgetWrap.__init__(self, self.body) + def _build_sum_widget(self): + sumw = MessageSummaryWidget(self.message) + if self.even: + attr = 'messagesummary_even' + else: + attr = 'messagesummary_odd' + # a spacer of width 0 breaks urwid.Columns + cols = [] + bc = list() # box_columns + if self.depth > 0: + bc.append(0) + cols.append(self._get_spacer()) + if self.siblings_follow: + arrowhead = u'\u251c\u25b6' + else: + arrowhead = u'\u2514\u25b6' + cols.append(('fixed', 2, Text(arrowhead))) + cols.append(sumw) + line = urwid.AttrMap(urwid.Columns(cols, box_columns=bc), attr, 'messagesummary_focus') + return line + + def rebuild(self): self.body = Pile(self.displayed_list) self._w = self.body def _get_spacer(self): - if self.depth: - return urwid.Text((' ' * self.depth) + u'\u2514\u25b6') - else: - return None + prefixchars = [] + for i in range(self.depth): + if i in self.bars_at: + c = u'\u2502' + else: + c = ' ' + prefixchars.append(('fixed', 1, urwid.SolidFill(c))) + + spacer = urwid.Columns(prefixchars, box_columns=range(self.depth)) + return ('fixed', self.depth, spacer) def get_header_widget(self): if not self.headerw: - self.headerw = MessageHeaderWidget(self.message.get_email()) + cols = [MessageHeaderWidget(self.message.get_email())] + bc = list() + if self.depth: + cols.insert(0,self._get_spacer()) + bc.append(0) + self.headerw = urwid.Columns(cols, box_columns = bc) return self.headerw def get_body_widget(self): if not self.bodyw: - self.bodyw = MessageBodyWidget(self.message.get_email()) + cols = [MessageBodyWidget(self.message.get_email())] + bc = list() + if self.depth: + cols.insert(0,self._get_spacer()) + bc.append(0) + self.bodyw = urwid.Columns(cols, box_columns = bc) return self.bodyw def toggle_header(self): |