Exemple #1
0
    def get_recipes_for_date( self, date):
        self.db.query( "SELECT time, no_portions, " +
            "recipe.recipe_no, recipe_name FROM recipe_plan_temp, recipe " +
            "WHERE date = '" + date + "' AND " +
            "recipe_plan_temp.recipe_no = recipe.recipe_no")
        result = self.db.get_result()

        recipe_list = []
        for time, num_portions, recipe_num, recipe_desc in result:
            recipe = gnutr.Recipe()
            recipe.time = str( time)
            recipe.num_portions = num_portions
            recipe.num = recipe_num
            recipe.desc = recipe_desc
            recipe_list.append( recipe)
        return recipe_list
Exemple #2
0
    def get_recipe(self):
        r = gnutr.Recipe()
        (r.desc,r.num_serv,r.cat_desc,r.prep_desc) = self.grab_window()

        if not r.desc:
            gnutr.Dialog('error', 'No recipe name is defined.', self.parent)
            return None

        if not r.num_serv:
            gnutr.Dialog('error', 
"""The number of servings is not defined,
or is not a number.""", self.parent)
            return None

        r.cat_num = self.store.cat_desc2num[r.cat_desc]
        r.ingr_list = self.get_ingredient_list()
        return r
Exemple #3
0
    def get_recipe(self):
        recipe = gnutr.Recipe()
        recipe.num_serv = self.ui.num_serv_entry.get_text()
        recipe.desc = self.ui.recipe_entry.get_text()
        recipe.cat_desc = self.ui.category_combo.get_active_text()

        start = self.ui.text_buffer.get_start_iter()
        end = self.ui.text_buffer.get_end_iter()
        recipe.prep_desc = self.ui.text_buffer.get_text(start, end, True)

        if not recipe.desc:
            gnutr.Dialog('error', 'No recipe name is defined.', self.parent)
            return None

        if not recipe.num_serv:
            gnutr.Dialog(
                'error', """The number of servings is not defined,
or is not a number.""", self.parent)
            return None

        recipe.cat_num = self.store.cat_desc2num[recipe.cat_desc]
        recipe.ingr_list = self.get_ingredient_list()
        return recipe
    def on_response(self, w, r, d=None):
        if r == gtk.RESPONSE_HELP:
            help.open('')

        elif r == gtk.RESPONSE_OK:
            recipe = gnutr.Recipe()
            model, iter = self.ui.selection.get_selected()
            if not iter:
                gnutr.Dialog('warn',
                             'A recipe must be selected from the list.')
                return

            recipe.desc = model.get_value(iter, 0)
            recipe.num = model.get_value(iter, 1)
            if not recipe.desc or not recipe.num:
                return

            # FIXME: this should be recipe_win.py and
            # plan_win.py
            if self.view == gnutr_consts.RECIPE:
                self.db.query(
                    "SELECT no_serv, category_no FROM " +
                    "recipe WHERE recipe_no = {0:d}".format(recipe.num))
                recipe.num_serv, recipe.cat_num = self.db.get_row_result()
                recipe.cat_desc = self.store.cat_num2desc[recipe.cat_num]

                self.db.query("SELECT prep_desc FROM preparation WHERE " +
                              "recipe_no = {0:d}".format(recipe.num))
                recipe.prep_desc = self.db.get_single_result()

                self.db.query(
                    "SELECT amount, Msre_Desc, NDB_No FROM " +
                    "ingredient WHERE recipe_no = {0:d}".format(recipe.num))
                ingr_list = self.db.get_result()

                recipe.ingr_list = []
                for amount, msre_desc, food_num in ingr_list:
                    ingr = gnutr.Ingredient()
                    ingr.amount = amount
                    ingr.food_num = food_num
                    ingr.food_desc = self.store.fd_num2desc[food_num]
                    ingr.msre_desc = msre_desc
                    recipe.ingr_list.append(ingr)

                self.app.base_win.recipe.update(recipe)
                self.ui.dialog.hide()

            elif self.view == gnutr_consts.PLAN:
                try:
                    recipe.num_portions = \
                        float(self.ui.num_serv_entry.get_text())
                except ValueError:
                    gnutr.Dialog('error',
                                 'The number of portions must be specified.')
                    return

                self.ui.dialog.hide()
                self.app.base_win.plan.add_recipe(recipe)

        elif r == 1:
            desc = self.ui.recipe_entry.get_text()
            if not desc or len(desc) == 0:
                return
            dlg = gnutr.Dialog(
                'question',
                'You are about to delete a recipe from the database.\n' +
                'Are you sure you want to do this?')
            reply = dlg.run()
            if reply == gtk.RESPONSE_YES:
                self.app.base_win.recipe.delete_recipe(desc)
                model, iter = self.ui.selection.get_selected()
                if not iter:
                    return
                model.remove(iter)
                self.ui.recipe_entry.set_text('')
                dlg.destroy()
            else:
                dlg.destroy()

        elif r == gtk.RESPONSE_CANCEL:
            self.ui.treemodel.clear()
            self.ui.dialog.hide()