changeset 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 a283968818da
children 9a85836f0d45
files frontends/src/primitivus/profile_manager.py
diffstat 1 files changed, 16 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/primitivus/profile_manager.py	Sat Sep 06 17:34:26 2014 +0200
+++ b/frontends/src/primitivus/profile_manager.py	Mon Sep 08 15:50:49 2014 +0200
@@ -54,8 +54,8 @@
         connect_button = urwid.Button(_("Connect"), self.onConnectProfile)
 
         #we now build the widget
-        body_content = urwid.SimpleListWalker([buttons_flow,self.list_profile,divider,self.login_wid, self.pass_wid, connect_button])
-        frame_body = urwid.ListBox(body_content)
+        list_walker = urwid.SimpleFocusListWalker([buttons_flow,self.list_profile,divider,self.login_wid, self.pass_wid, connect_button])
+        frame_body = urwid.ListBox(list_walker)
         frame = urwid.Frame(frame_body,urwid.AttrMap(urwid.Text(_("Profile Manager"),align='center'),'title'))
         self.main_widget = urwid.LineBox(frame)
         urwid.WidgetWrap.__init__(self, self.main_widget)
@@ -64,6 +64,20 @@
         if key == a_key['APP_QUIT']:
             self.host.onExit()
             raise urwid.ExitMainLoop()
+        elif key in (a_key['FOCUS_UP'], a_key['FOCUS_DOWN']):
+            focus_diff = 1 if key==a_key['FOCUS_DOWN'] else -1
+            list_box = self.main_widget.base_widget.body
+            current_focus = list_box.body.get_focus()[1]
+            if current_focus is None:
+                return
+            while True:
+                current_focus += focus_diff
+                if current_focus < 0 or current_focus >= len(list_box.body):
+                    break
+                if list_box.body[current_focus].selectable():
+                    list_box.set_focus(current_focus, 'above' if focus_diff == 1 else 'below')
+                    list_box._invalidate()
+                    return
         return super(ProfileManager, self).keypress(size, key)
 
     def __refillProfiles(self):