changeset 96:44fc94b0fe18

new FocusPile widget: a Pile which manage FOCUS_KEYS
author Goffi <goffi@goffi.org>
date Mon, 08 Sep 2014 15:42:25 +0200
parents ca9a77f3b53e
children 8f5afab948a0
files urwid_satext/sat_widgets.py
diffstat 1 files changed, 26 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/urwid_satext/sat_widgets.py	Mon Sep 08 15:42:25 2014 +0200
+++ b/urwid_satext/sat_widgets.py	Mon Sep 08 15:42:25 2014 +0200
@@ -1142,6 +1142,32 @@
         return urwid.CanvasJoin(render)
 
 
+class FocusPile(urwid.Pile):
+    """A Pile Widget which manage SàT Focus keys"""
+    _focus_inversed = False
+
+    def keypress(self, size, key):
+        ret = super(FocusPile, self).keypress(size, key)
+        if not ret:
+            return
+
+        if key in FOCUS_KEYS:
+            direction, rotate = getFocusDirection(key, inversed = self._focus_inversed)
+            max_pos = len(self.contents) - 1
+            new_pos = self.focus_position + direction
+            if rotate:
+                if new_pos > max_pos:
+                    new_pos = 0
+                elif new_pos < 0:
+                    new_pos = max_pos
+            try:
+                self.focus_position = new_pos
+            except IndexError:
+                pass
+
+        return key
+
+
 class FocusFrame(urwid.Frame):
     """Frame-like which manage SàT Focus Keys"""