Fix keybindings.
[matthijs/upstream/mobilegtd.git] / src / gui / gui.py
index 9f0175e66ed7761a17e4f25bc405ecaba5e41494..16fa606231e83a71551335f45b6546c3933a2ea3 100644 (file)
@@ -173,7 +173,10 @@ class View(object):
         # Two helper functions
         def shortcut_prefix(key_name):
             short = key_shortname(key_name)
-            return '[%s]' % short if short else '   '
+            if short:
+                return '[%s]' % short
+            else:
+                return '   '
 
         def do_entry((text, callback, key_name)):
             key = get_key(key_name)
@@ -204,8 +207,8 @@ class ListView(View):
     def __init__(self):
         super(ListView, self).__init__()
         self.current_index = None
-        self.items_cache = []
-        self.set_view(appuifw.Listbox([], self.entry_selected))
+        self.items_cache = self.items()
+        self.set_view(appuifw.Listbox(self.items_cache, self.entry_selected))
         self.view.bind(EKeyUpArrow,lambda: self.arrow_key_pressed(-1))
         self.view.bind(EKeyDownArrow,lambda: self.arrow_key_pressed(1))
 
@@ -361,13 +364,19 @@ class WidgetBasedListView(ListView):
         # Determine the current menu based on the methods available on
         # the selected widget and on ourselves.
         menu_items = []
+        def make_callback(f):
+            # This is rather complicated, but loops don't have their own
+            # scope, so putting do_callback inside the loop would not
+            # capture the value of function, but only a reference to the
+            # loop variable (always evaluating to the final value...)
+            def do_callback():
+                f()
+                self.update()
+            return do_callback
         for function in applicable_functions(self.current_widget(),self.binding_map)+\
             applicable_functions(self,self.binding_map):
             (key,description) = self.binding_map[function.__name__]
-            def do_callback():
-                function()
-                self.update()
-            menu_items.append((description, do_callback, key))
+            menu_items.append((description, make_callback(function), key))
         menu_items += super(WidgetBasedListView, self).menu_items()
         return menu_items