예제 #1
0
    def on_response(self, w, resp, d=None):
        if not hasattr(self, 'food_srch_res_dlg'):
            import food_srch_res_dlg
            self.food_srch_res_dlg = \
            food_srch_res_dlg.FoodSrchResDlg(self.app)
            self.food_srch_res_dlg.ui.dialog.connect('hide', self.on_hide)

        if resp == gtk.RESPONSE_HELP:
            help.open('')

        elif resp == gtk.RESPONSE_OK:
            page = self.ui.notebook.get_current_page()
            if page == 0:
                match_list = self.search_by_text()
                if not match_list:
                    gnutr.Dialog('warn', 'No matching foods.')
                    return
            else:
                match_list = self.search_by_nutrient()
                if not match_list:
                    gnutr.Dialog('warn', 'No matching foods.')
                    return
            self.food_srch_res_dlg.show(match_list, self.view)

        elif resp == gtk.RESPONSE_CANCEL or resp == gtk.RESPONSE_DELETE_EVENT:
            if hasattr(self, 'food_srch_res_dlg'):
                self.food_srch_res_dlg.ui.dialog.hide()
            self.ui.dialog.hide()
예제 #2
0
    def on_response( self, w, resp, d=None):
        if not hasattr( self, 'food_srch_res_dlg'):
            import food_srch_res_dlg
            self.food_srch_res_dlg = \
            food_srch_res_dlg.FoodSrchResDlg( self.app)
            self.food_srch_res_dlg.ui.dialog.connect( 'hide', self.on_hide)

        if resp == gtk.RESPONSE_HELP:
            help.open( '')
            
        elif resp == gtk.RESPONSE_OK:
            page = self.ui.notebook.get_current_page()
            if page == 0:
                match_list = self.search_by_text()
                if not match_list:
                    gnutr.Dialog( 'warn', 'No matching foods.')
                    return
            else:
                match_list = self.search_by_nutrient()
                if not match_list:
                    gnutr.Dialog( 'warn', 'No matching foods.')
                    return
            self.food_srch_res_dlg.show( match_list, self.view)

        elif resp == gtk.RESPONSE_CANCEL or resp == gtk.RESPONSE_DELETE_EVENT:
            if hasattr( self, 'food_srch_res_dlg'):
                self.food_srch_res_dlg.ui.dialog.hide()
            self.ui.dialog.hide()
예제 #3
0
 def on_response( self, w, r, d=None):
     if r == gtk.RESPONSE_HELP:
         help.open( '')
     elif r == gtk.RESPONSE_OK:
         try:
             self.recipe.num_portions = \
                 float( self.ui.num_serv_entry.get_text())
         except ValueError:
             gnutr.Dialog( 'error', 
                 'The number of portions must be a number.')
         self.app.base_win.plan.replace_recipe( self.recipe)
         self.ui.dialog.hide()
     elif r == gtk.RESPONSE_CANCEL or r == gtk.RESPONSE_DELETE_EVENT:
         self.ui.dialog.hide()
예제 #4
0
 def on_response(self, w, r, d=None):
     if r == gtk.RESPONSE_HELP:
         help.open('')
     elif r == gtk.RESPONSE_OK:
         try:
             self.recipe.num_portions = \
                 float(self.ui.num_serv_entry.get_text())
         except ValueError:
             gnutr.Dialog('error',
                          'The number of portions must be a number.')
         self.app.base_win.plan.replace_recipe(self.recipe)
         self.ui.dialog.hide()
     elif r == gtk.RESPONSE_CANCEL or r == gtk.RESPONSE_DELETE_EVENT:
         self.ui.dialog.hide()
예제 #5
0
    def on_response( self, w, r, d=None):
        if r == gtk.RESPONSE_HELP:
            help.open( '')

        elif r == gtk.RESPONSE_OK:
            (model, iter) = self.ui.selection.get_selected()
            if not iter:
                return

            food_num = model.get_value( iter, 1)

            if not food_num in self.store.fd_num2desc:
                return

            ingr = gnutr.Ingredient()
            ingr.food_num = food_num
            ingr.food_desc = self.store.fd_num2desc[ ingr.food_num]

            if self.view_type != gnutr_consts.FOOD:
                try:
                    ingr.amount = float( self.ui.amount_entry.get_text())
                except ValueError:
                    gnutr.Dialog( 'error', 'The amount must be a number.')

            if (self.view_type == gnutr_consts.PLAN or
                    self.view_type == gnutr_consts.RECIPE):
                ingr.msre_desc = self.ui.combo.get_active_text()
                ingr.msre_num = self.store.msre_desc2num[ ingr.msre_desc]

            if self.view_type == gnutr_consts.PLAN:
                self.ui.dialog.hide()
                self.app.base_win.plan.add_food( ingr)
                self.ui.tree.clear()
            elif self.view_type == gnutr_consts.RECIPE:
                self.app.base_win.recipe.add_ingredient( ingr)
            else:
                self.app.base_win.food.update( ingr)

            if self.view_type != gnutr_consts.PLAN:
                self.ui.dialog.hide()
                self.ui.tree.clear()

        elif r == gtk.RESPONSE_CANCEL or r == gtk.RESPONSE_DELETE_EVENT:
            self.ui.dialog.hide()
            self.ui.tree.clear()
예제 #6
0
    def on_response( self, w, r, d=None):
        if r == gtk.RESPONSE_CANCEL or r == gtk.RESPONSE_DELETE_EVENT: 
            self.ui.dialog.hide()

        elif r == 1:    #save
            goal_list = []
            for nutr in self.ui.nutr_list:
                try:
                    val = float( nutr.entry.get_text())
                except:
                    gnutr.Dialog( 'error', 
                        'Save Failed: A nutrient goal entry\nis not a number.')
                    return
                goal_list.append( ( nutr.num, val))
            self.save_goal( goal_list)

        elif r == gtk.RESPONSE_HELP:
            help.open( '')
예제 #7
0
    def on_response(self, w, response_id, d=None):
        if response_id == gtk.RESPONSE_HELP:
            help.open('')
        if response_id == gtk.RESPONSE_OK:
            try:
                self.ingr.amount = float(self.ui.amount_entry.get_text())
            except ValueError:
                gnutr.Dialog('error', 'The amount must be a number.')
            self.ingr.msre_desc = self.ui.combo.get_active_text()

            if self.view == gnutr_consts.RECIPE:
                self.app.base_win.recipe.replace_ingredient(self.ingr)
            else:
                self.app.base_win.plan.replace_food(self.ingr)
            self.ui.dialog.hide()

        if response_id == gtk.RESPONSE_CANCEL:
            self.ui.dialog.hide_all()
예제 #8
0
    def on_response( self, w, r, d=None):
        if r == gtk.RESPONSE_HELP:
            help.open( '')
        elif r == gtk.RESPONSE_OK:
            result_list = self.get_search_match()
            if not result_list:
                gnutr.Dialog( 'warn', 'No recipe found.')
                return

            if not hasattr( self, 'recipe_srch_res_dlg'):
                import recipe_srch_res_dlg
                self.recipe_srch_res_dlg = \
                    recipe_srch_res_dlg.RecipeSrchResDlg( self.app)
                self.recipe_srch_res_dlg.ui.dialog.connect( 'hide', 
                    self.on_hide)
            self.recipe_srch_res_dlg.show( result_list, gnutr_consts.RECIPE)
        elif r == gtk.RESPONSE_CANCEL or r == gtk.RESPONSE_DELETE_EVENT:
            self.ui.dialog.hide()
예제 #9
0
    def on_response(self, w, r, d=None):
        if r == gtk.RESPONSE_HELP:
            help.open('')
        elif r == gtk.RESPONSE_OK:
            result_list = self.get_search_match()
            if not result_list:
                gnutr.Dialog('warn', 'No recipe found.')
                return

            if not hasattr(self, 'recipe_srch_res_dlg'):
                import recipe_srch_res_dlg
                self.recipe_srch_res_dlg = \
                    recipe_srch_res_dlg.RecipeSrchResDlg(self.app)
                self.recipe_srch_res_dlg.ui.dialog.connect(
                    'hide', self.on_hide)
            self.recipe_srch_res_dlg.show(result_list, gnutr_consts.RECIPE)
        elif r == gtk.RESPONSE_CANCEL or r == gtk.RESPONSE_DELETE_EVENT:
            self.ui.dialog.hide()
예제 #10
0
    def on_response(self, w, r, d=None):
        if r == gtk.RESPONSE_HELP:
            help.open("")

        elif r == gtk.RESPONSE_OK:
            (model, iter) = self.ui.selection.get_selected()
            if not iter:
                return

            food_num = model.get_value(iter, 1)

            if not food_num in self.store.fd_num2desc:
                return

            ingr = gnutr.Ingredient()
            ingr.food_num = food_num
            ingr.food_desc = self.store.fd_num2desc[ingr.food_num]

            if self.view_type != gnutr_consts.FOOD:
                try:
                    ingr.amount = float(self.ui.amount_entry.get_text())
                except ValueError:
                    gnutr.Dialog("error", "The amount must be a number.")

            if self.view_type == gnutr_consts.PLAN or self.view_type == gnutr_consts.RECIPE:
                ingr.msre_desc = self.ui.combo.get_active_text()
                ingr.msre_num = self.store.msre_desc2num[ingr.msre_desc]

            if self.view_type == gnutr_consts.PLAN:
                self.ui.dialog.hide()
                self.app.base_win.plan.add_food(ingr)
                self.ui.tree.clear()
            elif self.view_type == gnutr_consts.RECIPE:
                self.app.base_win.recipe.add_ingredient(ingr)
            else:
                self.app.base_win.food.update(ingr)

            if self.view_type != gnutr_consts.PLAN:
                self.ui.dialog.hide()
                self.ui.tree.clear()

        elif r == gtk.RESPONSE_CANCEL or r == gtk.RESPONSE_DELETE_EVENT:
            self.ui.dialog.hide()
            self.ui.tree.clear()
예제 #11
0
    def on_response( self, w, response_id, d=None):
        if response_id == gtk.RESPONSE_HELP:
            help.open( '')
        if response_id == gtk.RESPONSE_OK:
            try:
                self.ingr.amount = float( self.ui.amount_entry.get_text())
            except ValueError:
                gnutr.Dialog( 'error', 'The amount must be a number.')
            self.ingr.msre_desc = self.ui.combo.get_active_text()
            self.ingr.msre_num = self.store.msre_desc2num[self.ingr.msre_desc]

            if self.view == gnutr_consts.RECIPE:
                self.app.base_win.recipe.replace_ingredient( self.ingr)
            else:
                self.app.base_win.plan.replace_food( self.ingr)
            self.ui.dialog.hide()

        if response_id == gtk.RESPONSE_CANCEL:
            self.ui.dialog.hide_all()
예제 #12
0
    def on_response( self, w, r, d=None):
        if r == gtk.RESPONSE_HELP:
            help.open( '')
            
        elif r == 1:
            start_date = self.ui.start_date.entry.get_text()
            end_date = self.ui.end_date.entry.get_text()
            if self.start_later_than_end( start_date, end_date):
                gnutr.Dialog( 'error', 'The start date is later\n' +
                    'than the end date.')
                return

            avg = self.ui.avg_rad_button.get_active()
            result = self.compute( start_date, end_date, avg)
            if not hasattr( self, 'nutr_composition_dlg'):
                import nutr_composition_dlg
                self.nutr_composition_dlg = \
                    nutr_composition_dlg.NutrCompositionDlg()
            self.nutr_composition_dlg.show( nutr_list=result)

        elif r == gtk.RESPONSE_CANCEL or r == gtk.RESPONSE_DELETE_EVENT:
            self.ui.dialog.hide()
예제 #13
0
    def on_response( self, w, r, d=None):
        if r == gtk.RESPONSE_HELP:
            help.open( '')

        elif r == gtk.RESPONSE_OK:
            if not hasattr( self, 'recipe_srch_res_dlg'):
                import recipe_srch_res_dlg
                self.recipe_srch_res_dlg = \
                    recipe_srch_res_dlg.RecipeSrchResDlg( self.app)
                self.recipe_srch_res_dlg.ui.dialog.connect( 'hide', 
                    self.on_hide)

            if not hasattr( self, 'food_srch_res_dlg'):
                import food_srch_res_dlg
                self.food_srch_res_dlg = \
                    food_srch_res_dlg.FoodSrchResDlg( self.app)
                self.food_srch_res_dlg.ui.dialog.connect( 'hide', 
                    self.on_hide)

            num = self.ui.notebook.get_current_page()
            if num == 0:# recipe
                srch_list = self.recipe_srch_dlg.get_search_match()
                if not srch_list: 
                    return
                self.recipe_srch_res_dlg.show( srch_list, gnutr_consts.PLAN)
            elif num == 1:  # food by text
                srch_list = self.food_srch_dlg.search_by_text()
                if not srch_list: 
                    return
                self.food_srch_res_dlg.show( srch_list, gnutr_consts.PLAN)
            else:   # food by nutrient
                srch_list = self.food_srch_dlg.search_by_text()
                if not srch_list: 
                    return
                self.food_srch_res_dlg.show( srch_list, gnutr_consts.PLAN)

        elif r == gtk.RESPONSE_CANCEL or r == gtk.RESPONSE_DELETE_EVENT:
            self.ui.dialog.hide()
예제 #14
0
    def on_response(self, w, r, d=None):
        if r == gtk.RESPONSE_HELP:
            help.open('')

        elif r == 1:
            start_date = self.ui.start_date.entry.get_text()
            end_date = self.ui.end_date.entry.get_text()
            if self.start_later_than_end(start_date, end_date):
                gnutr.Dialog(
                    'error',
                    'The start date is later\n' + 'than the end date.')
                return

            avg = self.ui.avg_rad_button.get_active()
            result = self.compute(start_date, end_date, avg)
            if not hasattr(self, 'nutr_composition_dlg'):
                import nutr_composition_dlg
                self.nutr_composition_dlg = \
                    nutr_composition_dlg.NutrCompositionDlg()
            self.nutr_composition_dlg.show(nutr_list=result)

        elif r == gtk.RESPONSE_CANCEL or r == gtk.RESPONSE_DELETE_EVENT:
            self.ui.dialog.hide()
예제 #15
0
    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 = '%d'" %( 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 = '%d'" %( recipe.num))
                recipe.prep_desc = self.db.get_single_result()

                self.db.query( "SELECT amount, msre_no, fd_no FROM " +
                    "ingredient WHERE recipe_no = '%d'" 
                    %( recipe.num))
                ingr_list = self.db.get_result()

                recipe.ingr_list = []
                for amount, msre_num, food_num in ingr_list:
                    ingr = gnutr.Ingredient()
                    ingr.amount = amount
                    ingr.food_num = food_num
                    ingr.msre_num = msre_num
                    ingr.food_desc = self.store.fd_num2desc[ food_num]
                    ingr.msre_desc = self.store.msre_num2desc[ msre_num]
                    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()
예제 #16
0
 def on_response( self, w, r, d=None):
     if r == gtk.RESPONSE_HELP:
         help.open( '')
     if r == gtk.RESPONSE_CANCEL or r == gtk.RESPONSE_DELETE_EVENT:
         self.ui.dialog.hide()
예제 #17
0
 def on_manual_activate(self, w, d=None):
     help.open('')
예제 #18
0
 def on_manual_activate( self, w, d=None):
     help.open( '')
예제 #19
0
    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()