예제 #1
0
class Menu(object):
    "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 "1: show notes, 2: search, 3: add, 4: modify, 5: quit"

    def run(self):
        "Display the menu and respond to choices"
        while True:
            self.display_menu()
            choice = raw_input("> ")
            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):
        pattern = raw_input("Search for: ")
        notes = self.notebook.search(pattern)
        self.show_notes(notes)

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

    def modify_note(self):
        note_id = int(raw_input("Enter a note id: "))
        if not self.notebook._find_note(note_id):
            return
        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):
        print "Thanks for using your notebook today."
        sys.exit()
예제 #2
0
class Menu(object):
    "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 "1: show notes, 2: search, 3: add, 4: modify, 5: quit"

    def run(self):
        "Display the menu and respond to choices"
        while True:
            self.display_menu()
            choice = raw_input("> ")
            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):
        pattern = raw_input("Search for: ")
        notes = self.notebook.search(pattern)
        self.show_notes(notes)

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

    def modify_note(self):
        note_id = int(raw_input("Enter a note id: "))
        if not self.notebook._find_note(note_id):
            return
        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):
        print "Thanks for using your notebook today."
        sys.exit()
예제 #3
0

# Exploring Notebook
print("\nLet's explore Notebook: ")
notebook = Notebook()

print('\nExploring some class methods: ')
print('method new_note: ')  # checking method new note
note2 = Note('Hello!', 'w')
notebook.new_note(note2.memo, note2.tags)
note3 = Note('Hi', 'world!')
notebook.new_note(note3.memo, note3.tags)
for note in notebook.notes:
    print(note.__dict__)
print('method _find_note: ')  # checking method find note
res = notebook._find_note(notebook.notes[1].id)
print(res.memo)
print('method modify_memo:')  # checking method modify memo
notebook.modify_memo(notebook.notes[1].id, 'Hey')
print(notebook.notes[1].memo)
print('method modify_tags: ')  # checking method modify tags
notebook.modify_tags(notebook.notes[1].id, 'wow')
print(notebook.notes[1].tags)
print('method search: ')  # checking method search
for note in notebook.search('w'):
    print(note.memo)

print('\nAll attributes of Notebook: ')
print(dir(Notebook))

print("\nDocumentation of notebook: ")
예제 #4
0
note_match2 = notee.match('Hello')
print('first note match function result(word: my note):', note_match)
print('first note match function result(word: Hello): ', note_match2)

notebook.new_note(notee.memo, notee.tags)  #сreating a new note
notebook.new_note(noteee.memo, noteee.tags)
notebook.new_note(note.memo, note.tags)
print('All notes in the notebook:')
for note in notebook.notes:
    print(note.__dict__)

print('Notebook notes: ')
print(notebook.notes)

print('Find the first note:')
find = notebook._find_note(notebook.notes[0].id)
print(find.memo)

print(
    'Example of using modifying memo, tags function(changing one memo and one tag):'
)
notebook.modify_memo(notebook.notes[0].id, 'Good bye')
notebook.modify_tags(notebook.notes[1].id, 'you with me')
for note in notebook.notes:
    print('note memo: ', note.memo)
    print('note tag: ', note.tags)

print('Example of using search function(word: Here):')
for note in notebook.search('Here'):
    print(note.memo)