-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwatch_list_ui.py
64 lines (54 loc) · 1.75 KB
/
watch_list_ui.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
from watch_list import watch_list
import sys, os
class watch_list_ui:
wl = None
exit = None
def __init__(self):
self.wl = watch_list()
self.exit = False
#######################
## MENUS DEFINITIONS ##
#######################
menu_actions = {
'main': self.main_menu,
'1': self.view_list,
'2': self.add_ticker,
'3': self.remove_ticker,
'4': self.back,}
self.main_menu(menu_actions)
def main_menu(self, menu_actions):
os.system('clear')
print(' 1) view list')
print(' 2) add ticker')
print(' 3) remove ticker')
print(' 4) back')
choice = raw_input('|>> ')
self.run_menu(choice, menu_actions)
def run_menu(self, choice, menu_actions):
if choice == '':
menu_actions['main'](menu_actions)
else:
try:
menu_actions[choice]()
if self.exit is False:
menu_actions['main'](menu_actions)
except KeyError:
print('Invalid Selection: %s' % choice)
menu_actions['main'](menu_actions)
return
def view_list(self):
self.wl.print_list()
def add_ticker(self):
ticker = raw_input('enter ticker to add: ')
if (ticker == ''):
return
self.wl.add_ticker(ticker)
self.wl.save_list()
def remove_ticker(self):
ticker = raw_input('enter ticker to remove: ')
if (ticker == ''):
return
self.wl.remove_ticker(ticker)
self.wl.save_list()
def back(self):
self.exit = True