Mercurial > urwid-satext
diff urwid_satext/sat_widgets.py @ 94:66b65ed9baf2
focus direction and rotate boolean are now gotten from getFocusDirection
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 08 Sep 2014 15:42:25 +0200 |
parents | b447a9c6f1d3 |
children | ca9a77f3b53e |
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 @@ -28,6 +28,22 @@ FOCUS_KEYS = (a_key['FOCUS_SWITCH'], a_key['FOCUS_UP'], a_key['FOCUS_DOWN']) +def getFocusDirection(key, inversed=False): + """Return direction and rotate boolean depending on key + @param key: one of FOCUS_KEYS + @param inversed: inverse directions if True + @return (tuple): (direction, rotate) where + - direction is 1 or -1 + - rotate is False if we should stop at the begin/end of the widgets list + """ + if not inversed: + direction = 1 if key in (a_key['FOCUS_SWITCH'], a_key['FOCUS_UP']) else -1 + else: + direction = -1 if key in (a_key['FOCUS_SWITCH'], a_key['FOCUS_DOWN']) else 1 + rotate = key == a_key['FOCUS_SWITCH'] + return direction, rotate + + class AdvancedEdit(urwid.Edit): """Edit box with some custom improvments new chars: @@ -1119,7 +1135,7 @@ class FocusFrame(urwid.Frame): - """Frame-like which manage 'tab' key""" + """Frame-like which manage SàT Focus Keys""" def keypress(self, size, key): ret = super(FocusFrame, self).keypress(size, key) @@ -1127,8 +1143,7 @@ return if key in FOCUS_KEYS: - direction = 1 if key in (a_key['FOCUS_SWITCH'], a_key['FOCUS_UP']) else -1 - rotate = key == a_key['FOCUS_SWITCH'] + direction, rotate = getFocusDirection(key, inversed=True) selectables = [] # keep positions which exists and have a selectable widget for position in reversed(self):