Ejemplo n.º 1
0
    def Add_Meal_Button_Click(self, event): #click method for component ID=5
        pass
        # >>>>>>insert any user code below this comment for section "compID=5"
        # replace, delete, or comment-out the following
        print("executed method Add_Meal_Button_Click")

        add_meal_popup = Input_Popup("new_meal", parent=self.master)

        self.Add_Meal_Button.configure(state=DISABLED)
        self.master.wait_window(add_meal_popup.popup_window)
        self.Add_Meal_Button.configure(state=NORMAL)

        meal_data = add_meal_popup.get_rv_data()

        if "name" in meal_data and meal_data["name"]:
            new_meal = Meal(meal_data["name"])
            self.meals.append(new_meal)

            self.Listbox_1.delete(0, 'end')

            new_meal_idx = self.populate_meals(meal_data["name"])

            self.Listbox_1.select_set(new_meal_idx)
            self.selected_meal = new_meal
            self.populate_ingredients()
        else:
            print("no input")
Ejemplo n.º 2
0
    def Listbox_3_Double_Click(self, event):  # click method for component ID=1
        pass

        current_instruction = self.Listbox_3.get(self.Listbox_3.curselection()[0])

        edit_instruction_data = {
            'current_instruction': current_instruction
        }
        edit_instruction_popup = Input_Popup("edit_instruction", parent=self.master, data=edit_instruction_data)
        self.master.wait_window(edit_instruction_popup.popup_window)
        instruction_data = edit_instruction_popup.get_rv_data()

        if "instruction" not in instruction_data:
            return

        self.selected_meal.update_instruction(current_instruction, instruction_data["instruction"])
        self.populate_instructions()
Ejemplo n.º 3
0
    def build_custom_meal_plan(self, start_date, weeks, days_needed):
        custom_meal_data = {
            'start_date': start_date,
            'weeks': weeks,
            'days_needed': days_needed,
            'meals': self.meals
        }

        custom_meal_popup = Input_Popup("custom_meal_plan", parent=self.master, data=custom_meal_data)
        self.master.wait_window(custom_meal_popup.popup_window)

        meal_data = custom_meal_popup.get_rv_data()

        meal_dates = None

        if "meal_dates" in meal_data and meal_data["meal_dates"]:
            meal_dates = meal_data["meal_dates"]

        return meal_dates
Ejemplo n.º 4
0
    def Listbox_1_Double_Click(self, event):  # click method for component ID=1
        pass

        print("executed method Listbox_1_Double_Click")

        edit_meal_data = {
            "meal_name": self.selected_meal.meal_name
        }

        edit_meal_popup = Input_Popup("edit_meal", parent=self.master, data=edit_meal_data)

        self.master.wait_window(edit_meal_popup.popup_window)

        meal_data = edit_meal_popup.get_rv_data()

        if "name" in meal_data and meal_data["name"]:
            self.selected_meal.meal_name = meal_data["name"]
            self.Listbox_1.delete(0, 'end')
            self.populate_meals()
        else:
            print("no input")
Ejemplo n.º 5
0
    def Add_Instruction_Button_Click(self, event): #click method for component ID=13
        pass
        # >>>>>>insert any user code below this comment for section "compID=13"
        # replace, delete, or comment-out the following
        print("executed method Add_Instruction_Button_Click")
        done = False

        position = None
        while not done:
            if not self.selected_meal:
                messagebox.showwarning("Oops", "Please select a meal before adding an instruction.",
                                       parent=self.master)
                return

            popup_data = {}

            if position:
                popup_data.update({"position": position})

            add_instruction_popup = Input_Popup("new_instruction", parent=self.master)

            self.Add_Instruction_Button.configure(state=DISABLED)
            self.master.wait_window(add_instruction_popup.popup_window)
            self.Add_Instruction_Button.configure(state=NORMAL)

            instruction_data = add_instruction_popup.get_rv_data()

            if "position" in instruction_data:
                position = instruction_data["position"]

            if "done" in instruction_data and instruction_data["done"]:
                break

            if "instruction" in instruction_data and instruction_data["instruction"]:
                self.selected_meal.add_instruction(instruction_data["instruction"])
                self.populate_instructions()
            else:
                print("no input")
                done = True
Ejemplo n.º 6
0
    def Listbox_2_Double_Click(self, event):  # click method for component ID=1
        pass

        print("executed method Listbox_2_Double_Click")

        ingredient_parts = self.Listbox_2.get(self.Listbox_2.curselection()[0]).split(" - ")
        self.quantities.sort(key=float)

        edit_ingredient_data ={
            "ingredient": ingredient_parts[0],
            "quantity": ingredient_parts[1],
            "unit": ingredient_parts[2],
            "ingredients": self.all_ingredients,
            "unit_types": self.all_unit_types,
            "quantities": self.quantities
        }

        edit_ingredient_popup = Input_Popup("edit_ingredient", parent=self.master, data=edit_ingredient_data)

        self.master.wait_window(edit_ingredient_popup.popup_window)

        ingredient_data = edit_ingredient_popup.get_rv_data()

        if "unit_type" in ingredient_data and ingredient_data["unit_type"] and "quantity" in ingredient_data and ingredient_data["quantity"]:
            if ingredient_data["unit_type"] not in self.all_unit_types:
                self.all_unit_types.append(ingredient_data["unit_type"])
                self.all_unit_types.sort()

            if ingredient_data["quantity"] not in self.quantities:
                self.quantities.append(ingredient_data["quantity"])
                self.quantities.sort(key=float)

            self.selected_meal.update_ingredient(ingredient_parts[0], quantity=ingredient_data["quantity"], unit=ingredient_data["unit_type"])

            self.populate_ingredients()
        else:
            print("no input")
Ejemplo n.º 7
0
    def Add_Ingredient_Button_Click(self, event): #click method for component ID=7
        pass
        # >>>>>>insert any user code below this comment for section "compID=7"
        # replace, delete, or comment-out the following
        print("executed method Add_Ingredient_Button_Click")
        done = False

        position = None
        while not done:
            if not self.selected_meal:
                messagebox.showwarning("Oops", "Please select a meal before adding an ingredient.",
                                       parent=self.master)
                return

            self.quantities = [x for x in self.quantities if x.isnumeric()]
            self.quantities.sort(key=float)

            popup_data = {
                "ingredients": self.all_ingredients,
                "unit_types": self.all_unit_types,
                "quantities": self.quantities
            }

            if position:
                popup_data.update({"position": position})

            add_ingredient_popup = Input_Popup("new_ingredient", parent=self.master, data=popup_data)

            self.master.wait_window(add_ingredient_popup.popup_window)

            ingredient_data = add_ingredient_popup.get_rv_data()

            if "position" in ingredient_data:
                position = ingredient_data["position"]

            if "done" in ingredient_data and ingredient_data["done"]:
                break

            if "ingredient" in ingredient_data and ingredient_data["ingredient"] and "unit_type" in ingredient_data and ingredient_data["unit_type"] and "quantity" in ingredient_data and ingredient_data["quantity"]:
                if ingredient_data["ingredient"] not in self.all_ingredients:
                    self.all_ingredients.append(ingredient_data["ingredient"])
                    self.all_ingredients.sort()

                if ingredient_data["unit_type"] not in self.all_unit_types:
                    self.all_unit_types.append(ingredient_data["unit_type"])
                    self.all_unit_types.sort()

                if ingredient_data["quantity"] not in self.quantities:
                    self.quantities.append(ingredient_data["quantity"])
                    try:
                        self.quantities.sort(key=float)
                    except:
                        messagebox.showwarning("Oops", "You must enter a number for quantity", parent=self.master)
                        continue

                if ingredient_data["ingredient"] in self.selected_meal.ingredient_names:
                    existing_ingredient = None
                    for x in self.selected_meal.ingredients:
                        if x["name"] == ingredient_data["ingredient"]:
                            existing_ingredient = x
                            break

                    if ingredient_data["unit_type"] == existing_ingredient["unit"]:
                        quantity = str(float(ingredient_data["quantity"]) + float(existing_ingredient["quantity"]))
                        if float(quantity).is_integer():
                            quantity = str(int(float(quantity)))

                        update = messagebox.askyesno("Oops", f"Found existing ingredient '{ingredient_data['ingredient']}' with the same unit type.\n\nCurrent quantity: {existing_ingredient['quantity']}\nUpdated quantity: {quantity}\n\nDo you want to update the existing quantity?", parent=self.master)

                        if update:
                            self.selected_meal.update_ingredient(ingredient_data["ingredient"], quantity,
                                                                 ingredient_data["unit_type"])
                        else:
                            try:
                                quantity = str(float(ingredient_data["quantity"]))
                                if float(quantity).is_integer():
                                    quantity = str(int(float(quantity)))
                            except:
                                messagebox.showwarning("Oops", "You must enter a number for quantity", parent=self.master)
                                continue

                            replace = messagebox.askyesno("Oops", f"Found existing ingredient '{ingredient_data['ingredient']}' with the same unit type.\n\nCurrent quantity: {existing_ingredient['quantity']}\nNew quantity: {quantity}\n\nDo you want to replace the existing quantity?",
                                                   parent=self.master)

                            if replace:
                                self.selected_meal.update_ingredient(ingredient_data["ingredient"], quantity,
                                                                     ingredient_data["unit_type"])

                    else:
                        messagebox.showwarning("Oops", f"Found existing ingredient '{ingredient_data['ingredient']}' but with different unit type.\n\nPrevious Unit Type: {existing_ingredient['unit']}\nNew Unit Type: {ingredient_data['unit_type']}\n\nThe ingredient will NOT be added",
                                               parent=self.master)
                        return
                else:
                    try:
                        quantity = str(float(ingredient_data["quantity"]))
                        if float(quantity).is_integer():
                            quantity = str(int(float(quantity)))
                    except:
                        messagebox.showwarning("Oops", "You must enter a number for quantity", parent=self.master)
                        continue
                    self.selected_meal.add_ingredient(ingredient_data["ingredient"], quantity, unit=ingredient_data["unit_type"])

                self.populate_ingredients()
                done = add_ingredient_popup.done
            else:
                print("no input")
                done = True