-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.py
executable file
·44 lines (34 loc) · 1.07 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
43
44
class Menu:
def __init__(self, description):
self.options = []
self.name = "Menu"
self.options = []
self.lastchoice = -1
self.name = description
def addoption(self, description, f):
assert(isinstance(description, str))
assert(len(self.options) < 9)
self.options.append([description, f])
def start(self):
while True:
print "-" * len(self.name)
print self.name
print "-" * len(self.name)
i = 1
for o in self.options:
print "[%d] - %s" % (i, o[0])
i += 1
print
print "[0] - Exit"
c = raw_input("Choice [%d]: " % (self.lastchoice+1))
if len(c) == 0:
ci = self.lastchoice
else:
ci = int(c)-1
if ci == -1:
self.lastchoise = -1
return
if ci < 0 or ci >= len(self.options):
continue
self.lastchoice = ci
self.options[ci][1]()