comparison urwid_satext/sat_widgets.py @ 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
comparison
equal deleted inserted replaced
95:ca9a77f3b53e 96:44fc94b0fe18
1140 render.append((urwid.SolidCanvas(" "*cols_left, size[0], 1),False,False,cols_left)) 1140 render.append((urwid.SolidCanvas(" "*cols_left, size[0], 1),False,False,cols_left))
1141 1141
1142 return urwid.CanvasJoin(render) 1142 return urwid.CanvasJoin(render)
1143 1143
1144 1144
1145 class FocusPile(urwid.Pile):
1146 """A Pile Widget which manage SàT Focus keys"""
1147 _focus_inversed = False
1148
1149 def keypress(self, size, key):
1150 ret = super(FocusPile, self).keypress(size, key)
1151 if not ret:
1152 return
1153
1154 if key in FOCUS_KEYS:
1155 direction, rotate = getFocusDirection(key, inversed = self._focus_inversed)
1156 max_pos = len(self.contents) - 1
1157 new_pos = self.focus_position + direction
1158 if rotate:
1159 if new_pos > max_pos:
1160 new_pos = 0
1161 elif new_pos < 0:
1162 new_pos = max_pos
1163 try:
1164 self.focus_position = new_pos
1165 except IndexError:
1166 pass
1167
1168 return key
1169
1170
1145 class FocusFrame(urwid.Frame): 1171 class FocusFrame(urwid.Frame):
1146 """Frame-like which manage SàT Focus Keys""" 1172 """Frame-like which manage SàT Focus Keys"""
1147 1173
1148 def keypress(self, size, key): 1174 def keypress(self, size, key):
1149 ret = super(FocusFrame, self).keypress(size, key) 1175 ret = super(FocusFrame, self).keypress(size, key)