comparison frontends/src/primitivus/profile_manager.py @ 1178:49d39b619e5d

primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
author Goffi <goffi@goffi.org>
date Mon, 08 Sep 2014 15:50:49 +0200
parents 344bbe6fd1de
children e3a9ea76de35
comparison
equal deleted inserted replaced
1177:a283968818da 1178:49d39b619e5d
52 52
53 #connect button 53 #connect button
54 connect_button = urwid.Button(_("Connect"), self.onConnectProfile) 54 connect_button = urwid.Button(_("Connect"), self.onConnectProfile)
55 55
56 #we now build the widget 56 #we now build the widget
57 body_content = urwid.SimpleListWalker([buttons_flow,self.list_profile,divider,self.login_wid, self.pass_wid, connect_button]) 57 list_walker = urwid.SimpleFocusListWalker([buttons_flow,self.list_profile,divider,self.login_wid, self.pass_wid, connect_button])
58 frame_body = urwid.ListBox(body_content) 58 frame_body = urwid.ListBox(list_walker)
59 frame = urwid.Frame(frame_body,urwid.AttrMap(urwid.Text(_("Profile Manager"),align='center'),'title')) 59 frame = urwid.Frame(frame_body,urwid.AttrMap(urwid.Text(_("Profile Manager"),align='center'),'title'))
60 self.main_widget = urwid.LineBox(frame) 60 self.main_widget = urwid.LineBox(frame)
61 urwid.WidgetWrap.__init__(self, self.main_widget) 61 urwid.WidgetWrap.__init__(self, self.main_widget)
62 62
63 def keypress(self, size, key): 63 def keypress(self, size, key):
64 if key == a_key['APP_QUIT']: 64 if key == a_key['APP_QUIT']:
65 self.host.onExit() 65 self.host.onExit()
66 raise urwid.ExitMainLoop() 66 raise urwid.ExitMainLoop()
67 elif key in (a_key['FOCUS_UP'], a_key['FOCUS_DOWN']):
68 focus_diff = 1 if key==a_key['FOCUS_DOWN'] else -1
69 list_box = self.main_widget.base_widget.body
70 current_focus = list_box.body.get_focus()[1]
71 if current_focus is None:
72 return
73 while True:
74 current_focus += focus_diff
75 if current_focus < 0 or current_focus >= len(list_box.body):
76 break
77 if list_box.body[current_focus].selectable():
78 list_box.set_focus(current_focus, 'above' if focus_diff == 1 else 'below')
79 list_box._invalidate()
80 return
67 return super(ProfileManager, self).keypress(size, key) 81 return super(ProfileManager, self).keypress(size, key)
68 82
69 def __refillProfiles(self): 83 def __refillProfiles(self):
70 """Update the list of profiles""" 84 """Update the list of profiles"""
71 profiles = self.host.bridge.getProfilesList() 85 profiles = self.host.bridge.getProfilesList()