-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.py
More file actions
71 lines (58 loc) · 1.67 KB
/
menu.py
File metadata and controls
71 lines (58 loc) · 1.67 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
import sys
from notes import Notebook
class Menu:
def __init__(self):
self.notebook = Notebook()
self.choices = {
'1':self.show_notes,
'2':self.search_notes,
'3':self.add_note,
'4':self.modify_note,
'5':self.quit,
}
def display_menu(self):
print(
"""
Notebook Menu
1.Show all Notes
2.Search Notes
3.Add Note
4.Modufy note
5.Quit
"""
)
def run(self):
while True:
self.display_menu()
choice = input('Enter an option: ')
action = self.choices.get(choice)
if action:
action()
else:
print(f'{choice} in not a valid option.')
def show_notes(self, notres=None):
if not notres:
notes = self.notebook.notes
for note in notes:
print(f'{note.id}:{note.title}\n{note.data}')
def search_notes(self):
filter = input('Enter filter: ')
notes = self.notebook.search(filter)
self.show_notes(notes)
def add_note(self):
data = input('Enter note data: ')
self.notebook.new_note(data)
print('Note added successfully.')
def modify_note(self):
id = input('Enter note id: ')
data = input('Enter a new data: ')
title = input('Enter a new title: ')
if data:
self.notebook.modify_data(id, data)
if title:
self.notebook.modify_title(id, title)
def quit(self):
print('Thank you for using the notebook.')
sys.exit()
if __name__ == '__main__':
Menu().run()