예제 #1
0
    def getRecipe(self) -> Recipe:
        title = self.lineRecipeName.displayText()
        servings = self.spnServings.value()
        prep = self.spnPrepTime.value()
        cook = self.spnCookTime.value()
        directions = self.txtEDirections.toPlainText()
        ingredients = {}
        for i in range(self.vbox.count()):
            ingredient: IngredientEditor = self.vbox.itemAt(i).widget()
            units = ingredient.comboUnits.currentText()
            amount = ingredient.dspnAmount.value()
            if units == 'count':
                quantity = Quantity.count(amount)
            else:
                quantity = Quantity.of(amount, units)

            name = ingredient.lineIngredientName.displayText()
            ingredients[name] = quantity
        flags = RecipeFlags.NONE
        if self.chkDF.isChecked(): flags |= RecipeFlags.DAIRYFREE
        if self.chkGF.isChecked(): flags |= RecipeFlags.GLUTENFREE
        if self.chkHealthy.isChecked(): flags |= RecipeFlags.HEALTHY
        if self.chkNoAlcohol.isChecked(): flags |= RecipeFlags.NONALCOHOLIC
        if self.chkVeg.isChecked(): flags |= RecipeFlags.VEGETARIAN
        if self.chkVegan.isChecked(): flags |= RecipeFlags.VEGAN

        return Recipe(title=title,
                      servings=servings,
                      prep=prep,
                      cook=cook,
                      ingredients=ingredients,
                      directions=directions,
                      flags=flags)
예제 #2
0
    NONALCOHOLIC = auto()
    HEALTHY = auto()


class Recipe(NamedTuple):
    title: str
    servings: str
    prep: int
    cook: int
    ingredients: Dict[str, Quantity]
    directions: str
    flags: RecipeFlags


guac = Recipe(
    title='Guacamole',
    ingredients={
        'avocado': Quantity.count(4),
        'roma tomato': Quantity.count(2),
        'onion': Quantity.count(0.5),
        'lime': Quantity.count(2),
        'jalapeño': Quantity.count(1),
        'cilantro': Quantity.count(0.5),
        'salt': Quantity.of(2, 'tsp')
    },
    directions='Combine ingredients in a bowl. Chill before serving.',
    servings=8,
    prep=20,
    cook=0,
    flags=RecipeFlags.GLUTENFREE | RecipeFlags.DAIRYFREE | RecipeFlags.VEGAN
    | RecipeFlags.NONALCOHOLIC | RecipeFlags.VEGETARIAN)