# 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