From 84c43327beba5718aeb80dbdc80fc247ab8c4262 Mon Sep 17 00:00:00 2001 From: pazz Date: Fri, 3 Jun 2011 09:45:05 +0100 Subject: arrows in single thread buffer --- alot/buffer.py | 48 +++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-) (limited to 'alot/buffer.py') 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() -- cgit v1.2.3