def create_dish_menu(): categories = get_all_category() category_choices, category_title_to_id = get_elem_choices_and_title_to_id( categories) create_dish_questions = get_create_dish_questions(category_choices) clear_terminal() answer = prompt(create_dish_questions) selected_category = answer['category'] selected_category_id = category_title_to_id[selected_category] data = { "title": answer['title'], "recipe": answer['recipe'], "time": answer['time'], "calories": answer['calories'], "category": selected_category_id, "ingredients": { "amount": answer['amount'], "components": answer['components'] } } create_dish(data)
def view_dish_menu(selected_category_id=None, dishes=None): if dishes is None: dishes = get_dish_by_category_id(selected_category_id) if not len(dishes): return return_menu('Создайте блюда') view_dish_choices, dish_title_to_id = get_elem_choices_and_title_to_id( dishes) view_dish_questions = get_view_dish_questions(view_dish_choices) answer = prompt(view_dish_questions) selected_dish = answer['dish'] if selected_dish == "Назад": return back() selected_dish_id = dish_title_to_id[selected_dish] dish = get_dish_by_id(selected_dish_id) clear_terminal() print(f"Название: {dish.title}") print(f"Рецепт: {dish.recipe}") print(f"Время приготовления: {dish.time} минут") print(f"Калории: {dish.calories}") print(f"Категория: {dish.category.title}") print(f"Количество порций: {dish.ingredients.amount}") print(f"Ингредиенты блюда: {dish.ingredients.components}") answer = prompt([{ 'type': 'list', 'name': 'view', 'message': '', 'choices': ['Редактировать', 'Удалить', 'Назад'] }]) return VIEW_DISH_ANSWERS[answer['view']](dish)
def watching_loop(self, pthread_queue: queue.Queue): self.pthread_queue = pthread_queue clear_terminal() while True: s = pthread_queue.get() if s is STOP_WATCHING_QUEUE_MESSAGE: break sys.stdout.write(s.decode(ENCODING)) sys.stdout.flush() self.pthread_queue = None
def edit_menu(dish): clear_terminal() create_dish_questions = get_create_dish_questions( default_values=dish.serialize()) answer = prompt(create_dish_questions) edited_dish = { "title": answer['title'], "recipe": answer['recipe'], "time": answer['time'], "calories": answer['calories'] } edited_ingredients = { "amount": answer['amount'], "components": answer['components'] } edit_dish_by_id(dish.id, edited_dish) edit_ingredients_by_id(dish.ingredients, edited_ingredients)
def draw_panel(self): # Clear the terminal clear_terminal() r = '' for i in range(len(TABS)): if i == self.tab_index: r += f' [{TABS[i]}]' else: r += f' {TABS[i]} ' print(r) if self.picked_project is not None: print('') print( f'Press \'s\' for add/remove pointed script onto project {self.picked_project.get_name()}.' ) print('') list_of_tab = self.get_list_of_tab() if list_of_tab: for i in range(len(list_of_tab)): something = list_of_tab[i] card = something.to_card(i == self.vertical_index) # Special case when you are seeing the tab of scripts and there is a project picked. if self.tab_index == 2 and self.picked_project and something.get_name( ) in self.picked_project.get_config_scripts(): index = self.picked_project.get_config_scripts().index( something.get_name()) card = card.replace('( )', f'({index})') print(card, end='', flush=True) else: print('Empty.') print(HELPS[self.tab_index]) for log in self.extra_logs: print(log)
def main_menu(): answer = prompt(MAIN_MENU_QUESTIONS) clear_terminal() MAIN_MENU_ANSWERS[answer['main_menu']]() clear_terminal()
def create_category_menu(): clear_terminal() answer = prompt(CREATE_CATEGORY_QUESTIONS) create_category(answer)
def init_menus(): clear_terminal() work = True while work: main_menu()