Permalink
Browse files

tutorial: update menu example to follow menu1

--HG--
branch : feature-sphinx
  • Loading branch information...
1 parent 84dc944 commit 8e5536379edf3902f6d183215292a3e859ba5d74 @wardi wardi committed Aug 10, 2012
Showing with 8 additions and 7 deletions.
  1. +8 −7 docs/tutorial/menu.py
View
@@ -3,27 +3,28 @@
inventory = set()
class MenuButton(urwid.Button):
- def __init__(self, text, callback):
- super(MenuButton, self).__init__("", callback)
- self._w = urwid.AttrMap(urwid.SelectableIcon(text, 1),
+ def __init__(self, caption, callback):
+ super(MenuButton, self).__init__("")
+ urwid.connect_signal(self, 'click', callback)
+ self._w = urwid.AttrMap(urwid.SelectableIcon(caption, 1),
None, focus_map='reversed')
class SubMenu(urwid.WidgetWrap):
def __init__(self, title, menu):
super(SubMenu, self).__init__(
- MenuButton(u" > go to " + title, self.pressed))
+ MenuButton(u" > go to " + title, self.clicked))
self.menu = menu
- def pressed(self, button):
+ def clicked(self):
loop.widget = self.menu
class Thing(urwid.WidgetWrap):
def __init__(self, name):
super(Thing, self).__init__(
- MenuButton(u" * take " + name, self.pressed))
+ MenuButton(u" * take " + name, self.clicked))
self.name = name
- def pressed(self, button):
+ def clicked(self):
self._w = urwid.Text(u" - " + self.name + " (taken)")
inventory.add(self.name)
if inventory >= set([u'sugar', u'lemon', u'jug']):

0 comments on commit 8e55363

Please sign in to comment.