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(): """ Все, что происходит для каждой итерации цикла меню > опция > результат уходит сюда 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 application_loop(): user_options = { 'A': Option("Add a bookmark", commands.AddBookmarkCommand(), prep_call=get_add_data), 'B': Option("List bookmarks by Date", commands.ShowBookmarksCommand()), 'T': Option("List bookmarks by Title", commands.ShowBookmarksCommand(order_by="title")), 'D': Option("Delete a bookmark", commands.DeleteBookmardCommand(), prep_call=get_delete_data), 'G': Option("Import GitHub stars", commands.ImportGitHubStarsCommand(), prep_call=get_github_import_options), 'Q': Option("Quit", commands.QuitCommand()) } print_options(user_options) user_option = get_user_choice(user_options) user_option.choose() clear_screen()
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 loop(): # All the steps for showing/selecting options 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.DeleteBookmarksCommand()), 'Q': Option('Quit', commands.QuitCommand()), } clear_screen() 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 loop(): clear_screen() # All steps for showing and selecting options options = { "A": Option( "create heldpesk", commands.helpdeskTableCommand(), prep_call=get_new_heldpesk_data, ), "B": Option("SLA by ticketDate", commands.createSLACommand()), "T": Option("create Issue by ID", commands.createIssueCommand(order_by="IssueID")), "E": Option( "ServiceDesk Command", commands.createServiceDeskCommand(), prep_call=get_new_helpdesk_info, ), "D": Option( "Delete a helpdesk", commands.DeletehelpdeskCommand(), prep_call=get_heldesk_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")
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()
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_bookmark_edit_info, success_message="Bookmark edited successfully!", ), "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="Import {result} bookmarks from Github scuuess!", ), "Q": Option("Quit", commands.QuitCommand()), } while True: loop(options)