From b190bf2980ce8944bdf2620e2c6442559712fdc2 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 30 Dec 2020 20:50:35 +0100 Subject: buffers/thread: allow changing weights of the tree/message split --- alot/buffers/thread.py | 24 +++++++++++++++--------- alot/commands/thread.py | 18 +++++++++++++++++- alot/defaults/default.bindings | 2 ++ 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/alot/buffers/thread.py b/alot/buffers/thread.py index 31dcb89f..1e751f1a 100644 --- a/alot/buffers/thread.py +++ b/alot/buffers/thread.py @@ -57,11 +57,8 @@ class ThreadBuffer(Buffer): attr, attr_focus) self.body = urwid.Pile([ - # 0 is a dummy value and is overridden later rebuild() - ('weight', 0, self._msgtree_deco), - # fixed weight for the message body - # TODO: should it depend on the message body length (or perhaps something else)? - ('weight', 50, cur_msg_deco), + ('weight', 0.5, self._msgtree_deco), + ('weight', 0.5, cur_msg_deco), ]) urwid.connect_signal(self._msgtree_widget.body, "modified", self._update_cur_msg) @@ -124,15 +121,24 @@ class ThreadBuffer(Buffer): self._msg_widgets.append(msg_wgt) list_walker.append(wgt) - # the weight given to the thread-tree widget is equal to the number of + # the weight given to the thread-tree widget is proportional to the number of # messages in it plus 1 (for surrounding decoration), up to the limit of - # 50 (when it is equal to the message body widget) - tree_weight = min(len(self._msg_widgets) + 1, 50) - self.body.contents[0] = (self._msgtree_deco, ('weight', tree_weight)) + # 49 messages, when it is equal to the message body widget + tree_weight = min(0.01 * (len(self._msg_widgets) + 1), 0.5) + self.msgtree_weight = tree_weight if len(self._msg_widgets) > 0: self._cur_msg_holder.original_widget = self._msg_widgets[0] + @property + def msgtree_weight(self): + return self.body.contents[0][1][1] + @msgtree_weight.setter + def msgtree_weight(self, weight): + weight = min(1.0, max(weight, 0.0)) + self.body.contents[0] = (self.body.contents[0][0], ('weight', weight)) + self.body.contents[1] = (self.body.contents[1][0], ('weight', 1.0 - weight)) + def get_selected_message_position(self): """Return position of focussed message in the thread tree.""" return self._msgtree_widget.focus_position diff --git a/alot/commands/thread.py b/alot/commands/thread.py index bc1cc1a4..9d67456b 100644 --- a/alot/commands/thread.py +++ b/alot/commands/thread.py @@ -522,12 +522,16 @@ class EditNewCommand(Command): MODE, 'fold', help='change message folding level', arguments=[(['fold'], {'action': cargparse.ValidatedStoreAction, 'validator': cargparse.is_int_or_pm})]) +@registerCommand( + MODE, 'weight', help='change weight of the thread tree', + arguments=[(['weight'], {'action': cargparse.ValidatedStoreAction, + 'validator': cargparse.is_int_or_pm})]) class ChangeDisplaymodeCommand(Command): repeatable = True def __init__(self, query=None, raw=None, all_headers=None, - indent=None, fold = None, **kwargs): + indent=None, fold = None, weight = None, **kwargs): """ :param query: notmuch query string used to filter messages to affect :type query: str @@ -547,6 +551,7 @@ class ChangeDisplaymodeCommand(Command): self.all_headers = all_headers self.indent = indent self.fold = fold + self.weight = weight Command.__init__(self, **kwargs) def apply(self, ui): @@ -567,6 +572,17 @@ class ChangeDisplaymodeCommand(Command): tbuffer.rebuild() ui.update() + if self.weight is not None: + new_weight = tbuffer.msgtree_weight + if self.weight == '+': + new_weight += 0.1 + elif self.weight == '-': + new_weight -= 0.1 + else: + new_weight = self.weight + + tbuffer.msgtree_weight = new_weight + logging.debug('matching lines %s...', self.query) if self.query is None: msg_wgts = [tbuffer.get_selected_message_widget()] diff --git a/alot/defaults/default.bindings b/alot/defaults/default.bindings index 9d743d63..39bf4acf 100644 --- a/alot/defaults/default.bindings +++ b/alot/defaults/default.bindings @@ -65,6 +65,8 @@ q = exit enter = select [ = indent - ] = indent + + { = weight - + } = weight + 'g f' = togglesource H = toggleheaders P = print --all --separately --add_tags -- cgit v1.2.3