8e69a26afabb — Alain Leufroy 11 months ago
main packer widget: preserve a little bit more the preferred user orientation

for example, on a small screen size, if the user specify HORIZONTAL,
when the screen is reduced, we preserve the horizontal orientation.
2 files changed, 18 insertions(+), 1 deletions(-)

M lairucrem/widgets/mainwidget.py
M lairucrem/widgets/utils.py
M lairucrem/widgets/mainwidget.py +6 -1
@@ 224,8 224,13 @@ class packer(delegate_to_widget_mixin('_
         self._pile_widget.contents.toggle_maximize(value)
 
     def _guess_orientation(self, size):
+        old_cols = self._previous_size[0] if self._previous_size else ANY
         cols = size[0]
-        self._orientation = config.HORIZONTAL if cols > 160 else config.VERTICAL
+        # Note: `not (x <= y)` because of Any which always answers True
+        if cols > 160 and cols > old_cols:
+            self._orientation = config.HORIZONTAL
+        if cols <= 160 and cols < old_cols:
+            self._orientation = config.VERTICAL
 
     def keypress(self, size, key):
         """Process pressed key"""

          
M lairucrem/widgets/utils.py +12 -0
@@ 97,4 97,16 @@ class Any:
     def __eq__(self, _dummy):
         return True
 
+    __le__ = __eq__
+    __lt__ = __eq__
+    __gt__ = __eq__
+    __ge__ = __eq__
+
+    def __getitem__(self, _dummy):
+        return self
+
+    def __getattr__(self, _dummy):
+        return self
+
+
 ANY = Any()