5d9f7c4ee5c7 — Alain Leufroy 2 years ago
widget: refactorization
1 files changed, 10 insertions(+), 5 deletions(-)

M lairucrem/widgets/mainwidget.py
M lairucrem/widgets/mainwidget.py +10 -5
@@ 140,20 140,25 @@ class packer(delegate_to_widget_mixin('_
     def render(self, size, focus):
         """render the widget"""
         if self._previous_size != size:
-            self._update_container(size)
+            self._guess_orientation(size)
+            self._update_container()
         self._previous_size = size
         return super(packer, self).render(size, focus)
 
-    def _update_container(self, size):
+    def _update_container(self):
         """update the main container depending on the given size"""
+        if self._orientation == 'horizontal':
+            self._original_widget = urwid.Columns(self._widgets)
+        elif self._orientation == 'vertical':
+            self._original_widget = urwid.Pile(self._widgets)
+        self._invalidate()
+
+    def _guess_orientation(self, size):
         cols = size[0]
         if cols > 160 and self._orientation != 'horizontal':
-            self._original_widget = urwid.Columns(self._widgets)
             self._orientation = 'horizontal'
         elif cols < 160 and self._orientation != 'vertical':
-            self._original_widget = urwid.Pile(self._widgets)
             self._orientation = 'vertical'
-        # only when screen size change, so mainloop has already invalidate self
 
     def keypress(self, size, key):
         """Process pressed key"""