Exemple #1
0
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. Modify Note
5. Quit
""")

    def run(self):
        while true:
            self.display_menu()
            choice = input("Enter an option:")
            action = self.choices.get(str(choice))
            if action:
                action()
            else:
                print("{0} is not a valid choice".format(choice))

    def show_notes(self, notes=None):
        if not notes:
            notes = self.notebook.notes
        for note in notes:
            print("{0}: {1}\n{2}".format(note.id, note.tags, note.memo))

    def search_notes(self):
        ifilter = raw_input("Search for:")
        notes = self.notebook.search(ifilter)
        self.show_notes(notes)

    def add_note(self):
        memo = raw_input("Enter a memo:")
        print(memo)
        self.notebook.new_note(memo)
        print("Your note has been added.")

    def modify_note(self):
        note_id = raw_input("Enter a note id:")
        memo = raw_input("Enter a memo:")
        tags = raw_input("Enter tags:")
        if memo:
            self.notebook.modify_memo(note_id, memo)
        if tags:
            self.notebook.modify_tags(note_id, tags)

    def quit(self):
        sys.exit(0)
Exemple #2
0
class Menu:
	'''Display a menu and respond to choices when run'''
	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. Modify Note
		5. Quit
		""")
		
	def run(self):
		"""Display the menu and respond to choices"""
		while True:
			self.display_menu()
			choice = input("Enter an option: ")
			action = self.choices.get(choice)
			if action:
				action()
			else:
				print("{0} is not a valid choice", format(choice))
	def show_notes(self, notes=None):
		if not notes:
			notes = self.notebook.notes
		for note in notes:
			print("{0}: {1}\n {2}". format(note.id, note.tags, note.memo))
	def search_notes(self):
		filter = input("Search for: ")
		notes = self.notebook.search(filter)
		self.show_notes(notes)
	def add_note(self):
		memo = input("Enter a memo: ")
		self.notebook.new_note(memo)
		print("Your note has been added")
		
	def modify_note(self):
		if = input("Enter a note id: ")
		memo = input("Enter a memo;  ")
		tags = input("Enter tags: ")
		if memo:
			self.notebook.modify_memo(id, memo)
		if tags:
			self.notebook.modify_tags(id, tags)
	def quit(self):
		print("Thank you for using your notebook today")
		sys.exit(0)
if __name__ == '__main__':
	Menu().run()
class Menu:
    """Display a menu and respond to choices when run."""

    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. Modify Note
            5. Quit
              """)

    def run(self):
        """Display the menu and respond to choices."""
        while True:
            self.display_menu()
            choice = input('Enter an option: ')
            action = self.choices.get(choice)
            if action:
                action()
            else :
                print(f'{choice} is not a valid option')

    def show_notes(self, notes=None)-> List:
        """displays all the notes in the notebook"""
        if not notes:
            notes = self.notebook.notes
        for note in notes:
            print(f'{note.id}: {note.tags}\n{note.memo}')

    def search_notes(self):
        """search for a note in the notebook"""
        filter = str(input('search for:'))
        note = self.notebook.search(filter)
        self.show_notes(note)

    def add_note(self):
        """Add a new note"""
        memo = str(input('Enter a memo:'))
        tags = str(input('Enter a tag:'))
        self.notebook.new_note(memo, tags)
        print('You have added a new note')

    def modify_note(self):
        """Modify an existing note"""
        id = input('Enter a note id:')
        memo = str(input('Enter a memo:'))
        tags = str(input('Enter a tag:'))
        if memo:
            self.notebook.modify_memo(id, memo)
        if tags:
            self.notebook.modify_tags(id, tags)

    def quit(self):
        print('Thank you for using the notebook today')
        sys.exit(0)
Exemple #4
0
class Menu:
    def __init__(self):
        self.notebook = NoteBook()
        self.choices = {
            '1': self.show_notes,
            '2': self.search_notes,
            '3': self.add_notes,
            '4': self.modify_note,
            '5': self.quit
        }

    def display_menu(self):
        print("""
            Notebook Menu
            1. to show all notes
            2. Search
            3. ADD NEW NOTES
            4. Modify
            5. QUIT
            """)

    def run(self):
        while True:
            self.display_menu()
            choice = input('hey pick an option: ')
            action = self.choices.get(choice)

            if action:
                action()
            else:
                print("{0} is not a valid choice".format(choice))

    def show_notes(self, notes=None):
        if not notes:
            notes = self.notebook.notes

        for note in notes:
            print("{0}: {1}\n{2}".format(note.id, note.tags.note.memo))

    def search_notes(self):
        filter = input('sEARCH FOR: ')
        notes = self.notebook.search(filter)
        self.show_notes(notes)

    def add_notes(self):
        memo = input('Type in your memo: ')
        self.notebook.new_note(memo)
        print('Your note has been added')

    def modify_note(self):
        id = input('Enter id here: ')
        memo = input('Modify notes: ')
        tags = input('modify tags: ')

        if memo:
            self.notebook.modify_memo(id, memo)
        if tags:
            self.notebook.modify_tags(id, tags)

    def quit(self):
        print('Thank you for using my Notebook')
        sys.exit(0)
Exemple #5
0
class Menu(object):
    """简单的提供一个菜单接口并允许用户输入他们的选择"""
    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 diaplay_menu(self):
        print('''
            NoteBook Menu


        1. Ahow all Notes
        2. Search Notes
        3. Add Note
        4. Modify Note
        5. Quit
            ''')

    def run(self):
        '''列出所有choice并调用相应的action'''
        while True:
            self.diaplay_menu()
            choice = input("Enter an option:")
            action = self.choices.get(choice)
            if action:
                action()
            else:
                print('{0} is not a valid choice'.format(choice))

    def show_notes(self, notes=None):
        if not notes:
            notes = self.notebook.notes
        for note in notes:
            print("{0}: {1}\n{2}".format(note.id, note.tags, note.memo))

    def search_notes(self):
        filter = input("Search for:")
        notes = self.notebook.search(filter)
        self.show_notes(notes)

    def add_note(self):
        memo = input("Enter a memo")
        self.notebook.new_note(memo)
        print("Your note has been added")

    def modify_note(self):
        id = input("Enter a note id")
        memo = input("Enter a memo")
        tags = input("Enter tags")
        if memo:
            self.notebook.modify_memo(id, memo)
        if tags:
            self.notebook.modify_tags(id, tags)

    def quit(self):
        print("Thank you for using your notebook today. ")
        sys.exit(0)