# HG changeset patch # User Goffi # Date 1410183745 -7200 # Node ID 66b65ed9baf2f3785f5e6ba0c735690147c112f0 # Parent 900014ae36b815b795a2eb3eeef7a1a8ebcb9327 focus direction and rotate boolean are now gotten from getFocusDirection diff -r 900014ae36b8 -r 66b65ed9baf2 urwid_satext/sat_widgets.py --- 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):