# HG changeset patch # User Alain Leufroy # Date 1639849284 -3600 # Sat Dec 18 18:41:24 2021 +0100 # Node ID f6f8c4ef49e81fa8afff6586fb2b556ad25dc2cb # Parent 582a0327dede03dcebda4fc1840631d88d45fb30 widget: allow users to maximize the focused pane Just enlarge the focused pane. Note: users can maximize the patch pane, and browse the tree with `alt+{up,down}`. diff --git a/lairucrem/config.py b/lairucrem/config.py --- a/lairucrem/config.py +++ b/lairucrem/config.py @@ -362,6 +362,7 @@ CMD_SCROLL_RIGHT = 'scroll right' CMD_SPLIT_HORIZONTALLY = 'split horizontally' CMD_SPLIT_VERTICALLY = 'split vertically' +CMD_MAXIMALIZE = 'maximalize' CURSOR_UP_NEXT_PACKED = 'up next packed' CURSOR_DOWN_NEXT_PACKED = 'down next packed' CURSOR_PAGE_UP_NEXT_PACKED = 'page up next packed' @@ -401,6 +402,7 @@ command_map['-'] = CMD_SPLIT_HORIZONTALLY command_map['|'] = CMD_SPLIT_VERTICALLY + command_map['='] = CMD_MAXIMALIZE command_map['ctrl f'] = CMD_FILTER command_map['/'] = CMD_SEARCH @@ -452,6 +454,7 @@ command_map['ctrl s'] = CMD_SPLIT_HORIZONTALLY command_map['ctrl v'] = CMD_SPLIT_VERTICALLY + command_map['ctrl t'] = CMD_MAXIMALIZE command_map['ctrl f'] = CMD_FILTER command_map['/'] = CMD_SEARCH @@ -501,6 +504,7 @@ command_map['meta 3'] = CMD_SPLIT_VERTICALLY command_map['meta 2'] = CMD_SPLIT_HORIZONTALLY + command_map['meta 1'] = CMD_MAXIMALIZE command_map['ctrl f'] = CMD_FILTER command_map['/'] = CMD_SEARCH diff --git a/lairucrem/widgets/mainwidget.py b/lairucrem/widgets/mainwidget.py --- a/lairucrem/widgets/mainwidget.py +++ b/lairucrem/widgets/mainwidget.py @@ -10,9 +10,10 @@ import urwid from urwid.canvas import CompositeCanvas from urwid.command_map import CURSOR_LEFT, CURSOR_RIGHT -from urwid.widget import delegate_to_widget_mixin +from urwid.widget import GIVEN, PACK, WEIGHT, delegate_to_widget_mixin from .. import config +from ..utils import apply_mixin from .utils import ANY, get_original_widget @@ -123,6 +124,46 @@ ]) +class _maximizable_contenxt_base: + + _maximized = False + + @property + def _focused_options(self): + raise NotImplementedError + + @property + def _unfocused_options(self): + raise NotImplementedError + + def toggle_maximize(self): + self._maximized = not(self._maximized) + self._modified() + + def __iter__(self): + if self._maximized: + for i, (widget, options) in enumerate(super().__iter__()): + if i == self._focus: + yield (widget, self._focused_options) + else: + yield (widget, self._unfocused_options) + return + for v in super().__iter__(): + yield v + + +class maximizable_columns_contents_mixin(_maximizable_contenxt_base): + + _focused_options = (WEIGHT, 1, False) + _unfocused_options = (GIVEN, 0, False) + + +class maximizable_pile_contents_mixin(_maximizable_contenxt_base): + + _focused_options = (WEIGHT, 1) + _unfocused_options = (GIVEN, 0) + + class packer(delegate_to_widget_mixin('_original_widget')): """Pack the given widgets horizontally (Columns)or vertically (Pile) depending on the screen size. @@ -153,8 +194,10 @@ assert self._orientation if self._orientation == config.HORIZONTAL: self._original_widget = urwid.Columns(self._widgets) + apply_mixin(self._original_widget.contents, maximizable_columns_contents_mixin) elif self._orientation == config.VERTICAL: self._original_widget = urwid.Pile(self._widgets) + apply_mixin(self._original_widget.contents, maximizable_pile_contents_mixin) self._invalidate() def _guess_orientation(self, size): @@ -167,6 +210,8 @@ key = super(packer, self).keypress(size, key) widget = self._original_widget command = self._command_map[key] + if command == config.CMD_MAXIMALIZE: + self._original_widget.contents.toggle_maximize() if command == config.CMD_SPLIT_HORIZONTALLY: self._orientation = config.VERTICAL self._update_container()