def start_load(self): """Loads a list from a file. :return: null """ # Request filename. line_y, line_x = util.center_start(self._list_height-2, self._list_width-2, 1, 16) self._list_display.addstr(line_y+4, 1, ' '*(self._list_width-2)) self._list_display.addstr(line_y+4, line_x, "Enter filename: ") self._list_display.refresh() # Get filename curses.echo() filename = self._list_display.getstr().decode(encoding="utf-8") filename = 'shopping_lists/data/' + filename curses.noecho() # Try to load list, and recursively call start_command if the file isn't loaded. try: new_list = Recipe.create_from_file(filename) # Add ingredients to the shopping list. new_list.add_to(self._shopping_list) # Alert user that list was updated.. line_y, line_x = util.center_start(self._list_height-2, self._list_width-2, 1, len(filename)+13) self._list_display.addstr(line_y+5, line_x, "{} fully loaded".format(filename)) self._list_display.refresh() except (FileNotFoundError, IsADirectoryError): # Alert user that file was not found. line_y, line_x = util.center_start(self._list_height-2, self._list_width-2, 1, 13) self._list_display.addstr(line_y+5, line_x, "File not found.") self._list_display.refresh() # Retry getting a command self.start_shopping_list()
def add_recipe(self, filename): """Load a recipe and add it to the shopping list. :param filename: the recipe (located in saved_recipes) to be loaded :return: null """ # Add the directory name to the filename. filename = 'saved_recipes/' + filename new_recipe = Recipe.create_from_file(filename) # Add ingredients to the shopping list. new_recipe.add_to(self._shopping_list) # Alert user that list was updated. self._list_display.addstr(self._list_height-2, 1, "{} fully loaded".format(filename)) self._list_display.refresh()