-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.py
42 lines (32 loc) · 1.13 KB
/
menu.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import urwid
class Selectable(urwid.WidgetWrap):
def __init__(self, *param, **kw):
self._selectable = True
text = urwid.Text(*param, **kw)
text = urwid.AttrMap(text, None, 'reversed')
urwid.WidgetWrap.__init__(self, text)
def selectable(self):
return True
def keypress(self, size, key):
self.text = "%s-%s" % (size, key)
return key
class Menu(urwid.WidgetWrap):
def __init__(self, master=None, caption="", items=[]):
self.master = master
self.items = items
self.content = urwid.SimpleListWalker(
[urwid.Text(caption)] +\
[Selectable(item) for item in self.items])
self.listbox = listbox = urwid.ListBox(self.content)
urwid.WidgetWrap.__init__(self, listbox)
def up(self, size):
return self.listbox.keypress(size, "up")
def down(self, size):
return self.listbox.keypress(size, "down")
def update(self, input):
#print input
if input in ("q", "Q"):
#print "exit"
urwid.ExitMainLoop()
# FIXME Doesn't exit
return True