comparison 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
comparison
equal deleted inserted replaced
93:900014ae36b8 94:66b65ed9baf2
24 24
25 from urwid.util import is_mouse_press #XXX: is_mouse_press is not included in urwid in 1.0.0 25 from urwid.util import is_mouse_press #XXX: is_mouse_press is not included in urwid in 1.0.0
26 from .keys import action_key_map as a_key 26 from .keys import action_key_map as a_key
27 27
28 FOCUS_KEYS = (a_key['FOCUS_SWITCH'], a_key['FOCUS_UP'], a_key['FOCUS_DOWN']) 28 FOCUS_KEYS = (a_key['FOCUS_SWITCH'], a_key['FOCUS_UP'], a_key['FOCUS_DOWN'])
29
30
31 def getFocusDirection(key, inversed=False):
32 """Return direction and rotate boolean depending on key
33 @param key: one of FOCUS_KEYS
34 @param inversed: inverse directions if True
35 @return (tuple): (direction, rotate) where
36 - direction is 1 or -1
37 - rotate is False if we should stop at the begin/end of the widgets list
38 """
39 if not inversed:
40 direction = 1 if key in (a_key['FOCUS_SWITCH'], a_key['FOCUS_UP']) else -1
41 else:
42 direction = -1 if key in (a_key['FOCUS_SWITCH'], a_key['FOCUS_DOWN']) else 1
43 rotate = key == a_key['FOCUS_SWITCH']
44 return direction, rotate
29 45
30 46
31 class AdvancedEdit(urwid.Edit): 47 class AdvancedEdit(urwid.Edit):
32 """Edit box with some custom improvments 48 """Edit box with some custom improvments
33 new chars: 49 new chars:
1117 1133
1118 return urwid.CanvasJoin(render) 1134 return urwid.CanvasJoin(render)
1119 1135
1120 1136
1121 class FocusFrame(urwid.Frame): 1137 class FocusFrame(urwid.Frame):
1122 """Frame-like which manage 'tab' key""" 1138 """Frame-like which manage SàT Focus Keys"""
1123 1139
1124 def keypress(self, size, key): 1140 def keypress(self, size, key):
1125 ret = super(FocusFrame, self).keypress(size, key) 1141 ret = super(FocusFrame, self).keypress(size, key)
1126 if not ret: 1142 if not ret:
1127 return 1143 return
1128 1144
1129 if key in FOCUS_KEYS: 1145 if key in FOCUS_KEYS:
1130 direction = 1 if key in (a_key['FOCUS_SWITCH'], a_key['FOCUS_UP']) else -1 1146 direction, rotate = getFocusDirection(key, inversed=True)
1131 rotate = key == a_key['FOCUS_SWITCH']
1132 1147
1133 selectables = [] # keep positions which exists and have a selectable widget 1148 selectables = [] # keep positions which exists and have a selectable widget
1134 for position in reversed(self): 1149 for position in reversed(self):
1135 if self.contents[position][0].selectable(): 1150 if self.contents[position][0].selectable():
1136 selectables.append(position) 1151 selectables.append(position)