diff options
author | Patrick Totzke <patricktotzke@gmail.com> | 2013-03-03 14:27:59 +0000 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2013-03-03 14:27:59 +0000 |
commit | 2d49e49319f5639246bcfcd67dc2f710f138d2a2 (patch) | |
tree | 9a0c7eeb3c9bdbbcb63ecedc128bda6eca68cdcd /alot/widgets/thread.py | |
parent | 0acb9239f4c20906c50e7dc8378c537cf43f2739 (diff) |
remove deprecated thread.MessageWidget
Diffstat (limited to 'alot/widgets/thread.py')
-rw-r--r-- | alot/widgets/thread.py | 235 |
1 files changed, 0 insertions, 235 deletions
diff --git a/alot/widgets/thread.py b/alot/widgets/thread.py index 679245c4..dc5d34be 100644 --- a/alot/widgets/thread.py +++ b/alot/widgets/thread.py @@ -10,247 +10,12 @@ import logging from alot.settings import settings from alot.db.utils import decode_header from alot.helper import tag_cmp -from alot.widgets.globals import HeadersList from alot.widgets.globals import TagWidget from alot.widgets.globals import AttachmentWidget from alot.foreign.urwidtrees import Tree, SimpleTree, CollapsibleTree from alot.db.utils import extract_body -class MessageWidget(urwid.WidgetWrap): - """ - Flow widget that renders a :class:`~alot.db.message.Message`. - """ - #TODO: atm this is heavily bent to work nicely with ThreadBuffer to display - #a tree structure. A better way would be to keep this widget simple - #(subclass urwid.Pile) and use urwids new Tree widgets - def __init__(self, message, even=False, folded=True, raw=False, - all_headers=False, depth=0, bars_at=[]): - """ - :param message: the message to display - :type message: alot.db.Message - :param even: use messagesummary_even theme for summary - :type even: bool - :param folded: fold message initially - :type folded: bool - :param raw: show message source initially - :type raw: bool - :param all_headers: show all headers initially - :type all_headers: bool - :param depth: number of characters to shift content to the right - :type depth: int - :param bars_at: defines for each column of the indentation whether to - use a vertical bar instead of a space. - :type bars_at: list(bool) - """ - self.message = message - self.mail = self.message.get_email() - - self.depth = depth - self.bars_at = bars_at - self.even = even - self.folded = folded - self.show_raw = raw - self.show_all_headers = all_headers - - # define subwidgets that will be created on demand - self.sumline = None - self.headerw = None - self.attachmentw = None - self.bodyw = None - self.sourcew = None - - # set available and to be displayed headers - self._all_headers = list(set(self.mail.keys())) - displayed = settings.get('displayed_headers') - self._filtered_headers = [k for k in displayed - if k.lower() == 'tags' or k in self.mail] - self._displayed_headers = None - - bars = settings.get_theming_attribute('thread', 'arrow_bars') - self.arrow_bars_att = bars - heads = settings.get_theming_attribute('thread', 'arrow_heads') - self.arrow_heads_att = heads - logging.debug(self.arrow_heads_att) - - self.rebuild() # this will build self.pile - urwid.WidgetWrap.__init__(self, self.pile) - - def get_focus(self): - return self.pile.get_focus() - - def rebuild(self): - self.sumline = self._build_sum_line() - if not self.folded: # only if already unfolded - self.displayed_list = [self.sumline] - if self.show_raw: - srcw = self._get_source_widget() - self.displayed_list.append(srcw) - else: - hw = self._get_header_widget() - aw = self._get_attachment_widget() - bw = self._get_body_widget() - if hw: - self.displayed_list.append(hw) - if aw: - self.displayed_list.append(aw) - self.displayed_list.append(bw) - else: - self.displayed_list = [self.sumline] - self.pile = urwid.Pile(self.displayed_list) - self._w = self.pile - - def _build_sum_line(self): - """creates/returns the widget that displays the summary line.""" - self.sumw = MessageSummaryWidget(self.message, even=self.even) - cols = [] - bc = list() # box_columns - if self.depth > 1: - bc.append(0) - spacer = self._get_spacer(self.bars_at[1:-1]) - cols.append(spacer) - if self.depth > 0: - if self.bars_at[-1]: - arrowhead = [(self.arrow_bars_att, u'\u251c'), - (self.arrow_heads_att, u'\u25b6')] - else: - arrowhead = [(self.arrow_bars_att, u'\u2514'), - (self.arrow_heads_att, u'\u25b6')] - cols.append(('fixed', 2, urwid.Text(arrowhead))) - cols.append(self.sumw) - line = urwid.Columns(cols, box_columns=bc) - return line - - def _get_header_widget(self): - """creates/returns the widget that displays the mail header""" - all_shown = (self._all_headers == self._displayed_headers) - - if self.headerw and (self.show_all_headers == all_shown): - return self.headerw - - if self.show_all_headers: - self._displayed_headers = self._all_headers - else: - self._displayed_headers = self._filtered_headers - - mail = self.message.get_email() - # normalize values if only filtered list is shown - norm = not (self._displayed_headers == self._all_headers) - - #build lines - lines = [] - for key in self._displayed_headers: - logging.debug('want header: %s' % (key)) - if key in mail: - if key.lower() in ['cc', 'bcc', 'to']: - values = mail.get_all(key) - values = [decode_header(v, normalize=norm) for v in values] - lines.append((key, ', '.join(values))) - else: - for value in mail.get_all(key): - dvalue = decode_header(value, normalize=norm) - lines.append((key, dvalue)) - elif key.lower() == 'tags': - logging.debug('want tags header') - values = [] - for t in self.message.get_tags(): - tagrep = settings.get_tagstring_representation(t) - if t is not tagrep['translated']: - t = '%s (%s)' % (tagrep['translated'], t) - values.append(t) - lines.append((key, ', '.join(values))) - - key_att = settings.get_theming_attribute('thread', 'header_key') - value_att = settings.get_theming_attribute('thread', 'header_value') - gaps_att = settings.get_theming_attribute('thread', 'header') - cols = [HeadersList(lines, key_att, value_att, gaps_att)] - bc = list() - if self.depth: - cols.insert(0, self._get_spacer(self.bars_at[1:])) - bc.append(0) - cols.insert(1, self._get_arrowhead_aligner()) - bc.append(1) - self.headerw = urwid.Columns(cols, box_columns=bc) - return self.headerw - - def _get_attachment_widget(self): - if self.message.get_attachments() and not self.attachmentw: - lines = [] - for a in self.message.get_attachments(): - cols = [AttachmentWidget(a)] - bc = list() - if self.depth: - cols.insert(0, self._get_spacer(self.bars_at[1:])) - bc.append(0) - cols.insert(1, self._get_arrowhead_aligner()) - bc.append(1) - lines.append(urwid.Columns(cols, box_columns=bc)) - self.attachmentw = urwid.Pile(lines) - return self.attachmentw - - def _get_body_widget(self): - """creates/returns the widget that displays the mail body""" - if not self.bodyw: - cols = [MessageBodyWidget(self.message.get_email())] - bc = list() - if self.depth: - cols.insert(0, self._get_spacer(self.bars_at[1:])) - bc.append(0) - cols.insert(1, self._get_arrowhead_aligner()) - bc.append(1) - self.bodyw = urwid.Columns(cols, box_columns=bc) - return self.bodyw - - def _get_source_widget(self): - """creates/returns the widget that displays the mail body""" - if not self.sourcew: - cols = [urwid.Text(self.message.get_email().as_string())] - bc = list() - if self.depth: - cols.insert(0, self._get_spacer(self.bars_at[1:])) - bc.append(0) - cols.insert(1, self._get_arrowhead_aligner()) - bc.append(1) - self.sourcew = urwid.Columns(cols, box_columns=bc) - return self.sourcew - - def _get_spacer(self, bars_at): - prefixchars = [] - length = len(bars_at) - for b in bars_at: - if b: - c = u'\u2502' - else: - c = ' ' - prefixchars.append(('fixed', 1, urwid.SolidFill(c))) - - spacer = urwid.Columns(prefixchars, box_columns=range(length)) - spacer = urwid.AttrMap(spacer, self.arrow_bars_att) - return ('fixed', length, spacer) - - def _get_arrowhead_aligner(self): - if self.message.has_replies(): - aligner = u'\u2502' - else: - aligner = ' ' - aligner = urwid.SolidFill(aligner) - return ('fixed', 1, urwid.AttrMap(aligner, self.arrow_bars_att)) - - def selectable(self): - return True - - def keypress(self, size, key): - return self.pile.keypress(size, key) - - def get_message(self): - """get contained :class`~alot.db.message.Message`""" - return self.message - - def get_email(self): - """get contained :class:`email <email.Message>`""" - return self.message.get_email() - - class MessageSummaryWidget(urwid.WidgetWrap): """ one line summary of a :class:`~alot.db.message.Message`. |