-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmenu.py
More file actions
141 lines (122 loc) · 3.71 KB
/
Copy pathmenu.py
File metadata and controls
141 lines (122 loc) · 3.71 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
from serialization import Serialization
from fuel import Fuel
class Menu:
def __init__(self, station):
self.__station__ = station
def print_menu(self):
"""
Function that creates UI in terminal
"""
print("_______MENU_______\n")
print('[a]dd fuel')
print('[s]pent certain fuel from station')
print('[d]elete fuel')
print('[i]mport to JSON')
print('[e]xport from JSON')
print("[p]rint station")
print('[q]uit')
print("input option: ")
def start(self):
"""
Creates the UI of the station
"""
option = ''
while option != 'q':
self.print_menu()
option = input()
print('\n' * 80)
if option == 'a':
self.option_add()
elif option == 's':
self.option_spend()
elif option == 'd':
self.option_delete()
elif option == 'i':
self.option_save()
elif option == 'e':
self.option_load()
elif option == 'p':
self.option_print()
elif option == 'q':
print("BYE!")
pass
else:
print("Input menu option")
print('\n' * 3)
def option_add(self):
"""
Creates UI for adding new fuel type
"""
print("Input fuel name")
name = input()
if self.__station__.is_fuel(name):
print('Fuel already exist')
return
print("Input fuel tank")
tank = input()
try:
tank = int(tank)
except ValueError:
print("Tank must be a number!")
return
if type(tank) == int:
self.__station__.add_fuel_type(Fuel(name, tank))
print("Successfully added!")
else:
print("Tank must a number!")
def option_spend(self):
"""
Creates UI for spending fuel from certain fuel type
"""
self.option_print()
print("\n\nInput fuel name that you want to spend: ")
name = input()
if self.__station__.is_fuel(name):
print("Input spending volume")
volume = input()
try:
volume = int(volume)
except ValueError:
print("Volume must be a number!")
return
self.__station__.spend_fuel(name, volume)
print("Spent!")
else:
print("Fuel with name " + name + " not found")
def option_delete(self):
"""
Creates UI for deleting fuel type from station
"""
self.option_print()
print("\n\nInput fuel name that you want to delete: ")
name = input()
if self.__station__.is_fuel(name):
self.__station__.delete_fuel_type(name)
else:
print("Fuel with name " + name + " not found")
def option_load(self):
"""
Loads station from Json file
"""
s = Serialization()
self.__station__ = s.load()
print('Successfully imported')
def option_save(self):
"""
Saves station to Json file
"""
s = Serialization()
s.save(self.__station__)
print('Successfully exported')
def option_print(self):
"""
Creates UI with information about all fuel types
"""
print("#########")
if self.__station__.is_empty():
print("Station is empty")
else:
formatted_list = self.__station__.show_formatted_fuel_list()
for f in formatted_list:
print(f)
print("#########")