-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_menu.py
79 lines (67 loc) · 2.32 KB
/
main_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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"""
Class for creating and handling the main menu.
"""
from participants import ConfigureParticipants
from spouses import ConfigureSpouses
from pick_kringle import pickKringle
from helpers import Helpers
import sys
class MainMenu(object):
""" Create and manage main menu. """
participants = False
spouses = False
menu_items = []
error_message = ''
def __init__(self):
self.check_participants()
self.check_spouses()
self.create_menu()
def check_participants(self):
participants = ConfigureParticipants()
if participants:
self.participants = True;
def check_spouses(self):
self.spouses = ConfigureSpouses().is_configured()
def create_menu(self):
if self.participants:
self.menu_items.append('List participants')
self.menu_items.append('Add participants')
self.menu_items.append('Edit participants')
if self.spouses:
self.menu_items.append('Edit spouses')
else:
self.menu_items.append('Add spouses')
self.show_menu()
def show_menu(self):
self.menu_items.append('Exit')
Helpers().clear()
Helpers().get_header()
print self.error_message
for index, item in enumerate(self.menu_items):
print '%i) %s' % (index + 1, item)
option = int(input('Enter the item number: '))
self.confirm_selection(option)
def confirm_selection(self, option):
item_count = len(self.menu_items)
if option > item_count:
self.error_message = 'Invalid menu option'
else:
self.action(option - 1)
def action(self, option):
action = self.menu_items[option]
if action == 'List participants':
Helpers().clear()
Helpers().get_header()
ConfigureParticipants().list()
raw_input('Press "Enter" to continue.')
Helpers().restart()
elif action == 'Add participants':
ConfigureParticipants().add_additional()
elif action == 'Edit participants':
ConfigureParticipants().edit()
elif action == 'Edit spouses':
ConfigureSpouses().edit()
elif action == 'Add spouses':
ConfigureSpouses().prepare_to_add()
else:
sys.exit(0)