582a0327dede — Alain Leufroy 2 years ago
widget: allow users to specify the default orientation

Related to https://todo.sr.ht/~alainl/lairucrem/4
3 files changed, 20 insertions(+), 2 deletions(-)

M lairucrem/config.py
M lairucrem/widgets/mainwidget.py
M lairucrem/widgets/utils.py
M lairucrem/config.py +7 -0
@@ 334,6 334,13 @@ TOPIC_NAME_REGEXP = re.compile('.*\x02(.
 HORIZONTAL = 'horizontal'
 VERTICAL = 'vertical'
 
+# Split orientation of the main widget. One of:
+# - None: orientation depends on the screen size
+# - HORIZONTAL: tree and diff panes are horizontally packed
+# - VERTICAL: tree and diff panes are vertically packed
+DEFAULT_MAIN_VIEW = None
+
+
 CMD_FILTER = 'filter'
 CMD_SEARCH = 'search'
 CMD_REFRESH = 'refresh'

          
M lairucrem/widgets/mainwidget.py +5 -2
@@ 13,7 13,7 @@ from urwid.command_map import CURSOR_LEF
 from urwid.widget import delegate_to_widget_mixin
 
 from .. import config
-from .utils import get_original_widget
+from .utils import ANY, get_original_widget
 
 
 class popuplauncher(urwid.PopUpLauncher):

          
@@ 132,10 132,13 @@ class packer(delegate_to_widget_mixin('_
         return True
 
     def __init__(self, widgets):
-        self._orientation = None
+        self._orientation = config.DEFAULT_MAIN_VIEW
         self._widgets = widgets
         self._original_widget = None
         self._previous_size = None
+        if self._orientation:
+            self._previous_size = ANY
+            self._update_container()
 
     def render(self, size, focus):
         """render the widget"""

          
M lairucrem/widgets/utils.py +8 -0
@@ 90,3 90,11 @@ def get_original_widget(widget):
         widget = inner
         inner = getattr(widget, 'original_widget', None)
     return widget
+
+
+class Any:
+
+    def __eq__(self, _dummy):
+        return True
+
+ANY = Any()