def loop(): """ Все, что происходит для каждой итерации цикла меню > опция > результат уходит сюда Returns: """ clear_screen() options = OrderedDict({ 'A': Option('Add a bookmark', commands.AddBookmarkCommand(), prep_call=get_new_bookmark_data), 'B': Option('List bookmarks by date', commands.ListBookmarksCommand()), 'T': Option('List bookmarks by title', commands.ListBookmarksCommand(order_by='title')), 'D': Option('Delete a bookmark', commands.DeleteBookmarkCommand(), prep_call=get_bookmark_id_for_deletion), 'Q': Option('Quit', commands.QuitCommand()), }) print_options(options) chosen_option = get_option_choice(options) clear_screen() chosen_option.choose() # Предлагает нажать ENTER и просматривает результат перед продолжением работы(_означает «неиспользуемое значение») _ = input('Press ENTER to return to menu')
def loop(): clear_screen() options = OrderedDict({ 'A': Option('Add a bookmark', commands.AddBookmarkCommand(), prep_call=get_new_bookmark_data), 'B': Option('List bookmarks by date', commands.ListBookmarksCommand()), 'T': Option('List bookmarks by title', commands.ListBookmarksCommand(order_by='title')), 'E': Option('Edit a bookmark', commands.EditBookmarkCommand(), prep_call=get_new_bookmark_info), 'D': Option('Delete a bookmark', commands.DeleteBookmarkCommand(), prep_call=get_bookmark_id_for_deletion), 'G': Option('Import GitHub stars', commands.ImportGitHubStarsCommand(), prep_call=get_github_import_options), 'Q': Option('Quit', commands.QuitCommand()), }) print_options(options) chosen_option = get_option_choice(options) clear_screen() chosen_option.choose() _ = input('Press ENTER to return to menu')
def loop(): options = { 'A': Option('Add a book', commands.AddBookmarkCommand(), prep_call=get_new_bookmark_data, success_message='Bookmark added!'), 'B': Option('List bookmarks by date', commands.ListBookmarksCommand()), 'T': Option('List bookmarks by title', commands.ListBookmarksCommand(order_by='title')), 'E': Option('Edit a bookmark', commands.EditBookmarkCommand(), prep_call=get_new_bookmark_info, success_message='Bookmark updated!'), 'D': Option('Delete a bookmark', commands.DeleteBookmarkCommand(), prep_call=get_bookmark_id_for_deletion, success_message='Bookmark deleted!'), 'G': Option( 'Import Github stars', commands.ImportGithubStarsCommand(), prep_call=get_github_import_options, success_message='Imported {result} bookmarks from starred repos!'), 'Q': Option('Quit', commands.QuitCommand()) } print_options(options) chosen_option = get_option_choice(options) clear_screen() chosen_option.choose()
def loop(): options = OrderedDict({ 'A': Option('Add Bookmark', commands.AddBookmarkCommand(), prep_call=get_new_bookmark_data), 'B': Option('List bookmarks by date', commands.ListBookmarksCommand()), 'T': Option('List bookmarks by title', commands.ListBookmarksCommand(order_by='title')), 'D': Option('Delete a bookmark', commands.DeleteBookmarkCommand(), get_bookmark_id_for_deletion), 'Q': Option('Quit', commands.QuitCommand()) }) clear_screen() print_options(options) choice = get_option_choice(options) clear_screen() choice.choose() _ = input('Press enter to return to main menu')
def loop(): clear_screen() options=OrderedDict({ 'A':Option('Add a Bookmark',commands.AddBookmarkCommand(),prep_call=get_new_bookmark_data), 'B':Option('List Bookmarks by Date',commands.ListBookmarksCommand()), 'T':Option('List BookMark by Title',commands.ListBookmarksCommand(order_by='title')), 'D':Option('Delete a BookMark',commands.DeleteBookmarkCommand(),prep_call=get_bookmark_id_for_deletion), 'Q':Option('Quit',commands.QuitCommand()), }) print_options(options) chosen_option=get_option_choice(options) clear_screen() chosen_option.choose() _=input('Press Enter to return to Menu')
def for_listings_only(): options = { 'A': Option('Add a bookmark', commands.AddBookmarkCommand()), 'B': Option('List bookmarks by date', commands.ListBookmarksCommand()), 'T': Option('List bookmarks by title', commands.ListBookmarksCommand(order_by='title')), 'D': Option('Delete a bookmark', commands.DeleteBookmarkCommand()), 'Q': Option('Quit', commands.QuitCommand()), } print_options(options)
def loop(): clear_screen() # All steps for showing and selecting options # https://www.w3schools.com/python/python_dictionaries.asp options = { "A": Option( "Add a bookmark", commands.AddBookmarkCommand(), prep_call=get_new_bookmark_data, ), "B": Option("List bookmarks by date", commands.ListBookmarksCommand()), "T": Option("List bookmarks by title", commands.ListBookmarksCommand(order_by="title")), "E": Option( "Edit a bookmark", commands.EditBookmarkCommand(), prep_call=get_new_bookmark_info, ), "D": Option( "Delete a bookmark", commands.DeleteBookmarkCommand(), prep_call=get_bookmark_id_for_deletion, ), "G": Option( "Import GitHub stars", commands.ImportGitHubStarsCommand(), prep_call=get_github_import_options, ), "Q": Option("Quit", commands.QuitCommand()), } print_options(options) chosen_option = get_option_choice(options) clear_screen() chosen_option.choose() _ = input("Press ENTER to return to menu")
def test_print_options(self): optionsTest = { "A": Option( "Add a bookmark", commands.AddBookmarkCommand(), prep_call=get_new_bookmark_data, ), "B": Option("List bookmarks by date", commands.ListBookmarksCommand()), "T": Option("List bookmarks by title", commands.ListBookmarksCommand(order_by="title")), "E": Option( "Edit a bookmark", commands.EditBookmarkCommand(), prep_call=get_new_bookmark_info, ), "D": Option( "Delete a bookmark", commands.DeleteBookmarkCommand(), prep_call=get_bookmark_id_for_deletion, ), "G": Option( "Import GitHub stars", commands.ImportGitHubStarsCommand(), prep_call=get_github_import_options, ), "Q": Option("Quit", commands.QuitCommand()), } capturedOutput = io.StringIO() sys.stdout = capturedOutput print_options(optionsTest) sys.stdout = sys.__stdout__ print('Captured', capturedOutput.getvalue())
def loop(): options = { 'A': Option('Add a bookmark', commands.AddBookmarkCommand(), prep_call=get_new_bookmark_data, success_message='Bookmark Added!'), 'B': Option('List bookmarks by date', commands.ListBookmarksCommand()), 'T': Option('List bookmarks by title', commands.ListBookmarksCommand(order_by='title')), 'D': Option('Delete a bookmark', commands.DeleteBookmarkCommand(), prep_call=get_bookmark_id_for_deletion, success_message='Bookmark deleted!'), 'G': Option( 'Import Github stars', commands.getGSCommand(), prep_call=get_github_import_options, success_message='Imported {result} bookmarks from starred repos!'), 'Q': Option('Quit', commands.QuitCommand()), } clear_screen() print('Welcome to Bark!') print_options(options) chosen_option = get_option_choice(options) clear_screen() chosen_option.choose() # <- ????? _ = input('Press ENTER to return to menu')
def test_option_choice_is_valid(self): optionsTest = { "A": Option( "Add a bookmark", commands.AddBookmarkCommand(), prep_call=get_new_bookmark_data, ), "B": Option("List bookmarks by date", commands.ListBookmarksCommand()), "T": Option("List bookmarks by title", commands.ListBookmarksCommand(order_by="title")), "E": Option( "Edit a bookmark", commands.EditBookmarkCommand(), prep_call=get_new_bookmark_info, ), "D": Option( "Delete a bookmark", commands.DeleteBookmarkCommand(), prep_call=get_bookmark_id_for_deletion, ), "G": Option( "Import GitHub stars", commands.ImportGitHubStarsCommand(), prep_call=get_github_import_options, ), "Q": Option("Quit", commands.QuitCommand()), } validChoice = option_choice_is_valid("A", optionsTest) self.assertEqual(validChoice, True, "Should be true if the value is true")
def get_bookmark_id_for_deletion(bookmark_id): commands.DeleteBookmarkCommand() prep_call = bookmark_id return jsonify({'result': True})
print('Invalid choice') choice = input("Choose an option: ") return options[choice.upper()] def print_options(options): for shortcut, option in options.items(): print(f'({shortcut}){option}') print() if __name__ == "__main__": commands.CreateBookmarksTableCommand().execute() options = { 'A': Option('Add a bookmark', commands.AddBookmarkCommand()), 'B': Option('List bookmarks by date', commands.ListBookmarksCommand()), 'T': Option('List bookmarks by title', commands.ListBookmarksCommand(order_by='title')), 'D': Option('Delete a bookmark', commands.DeleteBookmarkCommand()), 'Q': Option('Quit', commands.QuitCommand()), } print_options(options) chosen_option = get_option_choice(options) chosen_option.choose()
user_option.choose() input('Press ENTER to return to menu') print() if __name__ == '__main__': clear_screen() print('Welcome to bark!\n') command = commands.CreateBookmarksTableCommand() command.execute() options = { 'a': Option('Add a bookmark', commands.AddBookmarkCommand(), prep_call=get_new_bookmark_data), 'b': Option('List bookmarks by date', commands.ListBookmarkCommand()), 'c': Option('List bookmarks by title', commands.ListBookmarkCommand(order_by='title')), 'd': Option('Delete a bookmark', commands.DeleteBookmarkCommand(), prep_call=get_bookmark_id_for_deletion), 'q': Option('Quit', commands.QuitCommand()) } loop()