X-Git-Url: https://git.stderr.nl/gitweb?p=matthijs%2Fupstream%2Fmobilegtd.git;a=blobdiff_plain;f=src%2Fgui%2Fgui.py;fp=src%2Fgui%2Fgui.py;h=16fa606231e83a71551335f45b6546c3933a2ea3;hp=50c6d3138205afa063b40c753a808496bc1b5160;hb=388b56b12cc8e7cc17b33efdcb108aa279be3b1b;hpb=52b4ce227fb84cfee8312d2d92a8ff7215c80c32 diff --git a/src/gui/gui.py b/src/gui/gui.py index 50c6d31..16fa606 100644 --- a/src/gui/gui.py +++ b/src/gui/gui.py @@ -364,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