comparison urwid_satext/sat_widgets.py @ 98:8bf5a35450f0

Fixed getFocusDirection direction when inversed, and FocusFrame focus order.
author Goffi <goffi@goffi.org>
date Mon, 08 Sep 2014 18:10:30 +0200
parents 8f5afab948a0
children b2fee87c1d5a
comparison
equal deleted inserted replaced
97:8f5afab948a0 98:8bf5a35450f0
37 - rotate is False if we should stop at the begin/end of the widgets list 37 - rotate is False if we should stop at the begin/end of the widgets list
38 """ 38 """
39 if not inversed: 39 if not inversed:
40 direction = 1 if key in (a_key['FOCUS_SWITCH'], a_key['FOCUS_UP']) else -1 40 direction = 1 if key in (a_key['FOCUS_SWITCH'], a_key['FOCUS_UP']) else -1
41 else: 41 else:
42 direction = -1 if key in (a_key['FOCUS_SWITCH'], a_key['FOCUS_DOWN']) else 1 42 direction = -1 if key in (a_key['FOCUS_SWITCH'], a_key['FOCUS_UP']) else 1
43 rotate = key == a_key['FOCUS_SWITCH'] 43 rotate = key == a_key['FOCUS_SWITCH']
44 return direction, rotate 44 return direction, rotate
45 45
46 46
47 class AdvancedEdit(urwid.Edit): 47 class AdvancedEdit(urwid.Edit):
1171 return key 1171 return key
1172 1172
1173 1173
1174 class FocusFrame(urwid.Frame): 1174 class FocusFrame(urwid.Frame):
1175 """Frame-like which manage SàT Focus Keys""" 1175 """Frame-like which manage SàT Focus Keys"""
1176 ordered_positions = ('footer', 'body', 'header')
1176 1177
1177 def keypress(self, size, key): 1178 def keypress(self, size, key):
1178 ret = super(FocusFrame, self).keypress(size, key) 1179 ret = super(FocusFrame, self).keypress(size, key)
1179 if not ret: 1180 if not ret:
1180 return 1181 return
1181 1182
1182 if key in FOCUS_KEYS: 1183 if key in FOCUS_KEYS:
1183 direction, rotate = getFocusDirection(key, inversed=True) 1184 direction, rotate = getFocusDirection(key)
1184 1185
1185 selectables = [] # keep positions which exists and have a selectable widget 1186 positions = [pos for pos in self.ordered_positions if pos in self]
1186 for position in reversed(self): 1187 selectables = [pos for pos in positions if self.contents[pos][0].selectable()] # keep positions which exists and have a selectable widget
1187 if self.contents[position][0].selectable():
1188 selectables.append(position)
1189 if not selectables: 1188 if not selectables:
1190 # no widget is selectable, we just return 1189 # no widget is selectable, we just return
1191 return 1190 return
1192 idx = selectables.index(self.focus_position) + direction 1191 idx = selectables.index(self.focus_position) + direction
1193 if not rotate and (idx < 0 or idx >= len(selectables)): 1192 if not rotate and (idx < 0 or idx >= len(selectables)):