Example #1
0
 def remove_recipe(self):
     book = RecipeBook(self.database)
     recipe, r_id, index = book.select_recipe(self.index, self.id_list)
     d = ModalWindow(
         self, "Delete Recipe",
         "Are you sure you want to delete {}?".format(recipe[0][1]))
     d.modalWindow.focus()
     self.wait_window(d.modalWindow)
     if d.choice == 'Yes':
         book.delete(r_id)
         book.close()
         self.id_list.remove(r_id)
         self.populate()
     else:
         book.close()
Example #2
0
 def edit_recipe(self):
     book = RecipeBook(self.database)
     recipe, r_id, self.index = book.select_recipe(self.index, self.id_list)
     book.close()
     w = RecipeCreationWindow(Toplevel(self), self.manager, self.database,
                              self.root, recipe)
     w.master.focus()
     self.wait_window(w.master)
     if w.final != None:
         old_id = w.old_id
         book = RecipeBook(self.database)
         book.cursor.execute(
             """
             SELECT r.id
             FROM Recipe r
             WHERE r.name = ?
             """, [w.final])
         r_id = book.cursor.fetchone()[0]
         book.close()
         self.manager.my_gui.repopulate(old_id, r_id)
Example #3
0
    def populate(self):
        self.canvas.yview(MOVETO, 0)
        self.canvas.xview(MOVETO, 0)
        book = RecipeBook(self.database)
        recipe, r_id, self.index = book.select_recipe(self.index, self.id_list)
        book.close()
        name = recipe[0][1] if r_id and recipe[0] else "<Name>"
        description = recipe[0][2] if r_id and recipe[0] else "<Description>"
        directions = recipe[0][3] if r_id and recipe[0] else "<Directions>"
        servings = recipe[0][4] if r_id and recipe[0] else "<Servings>"
        if r_id and recipe[0] and int(servings) == 0:
            servings = "-"
        notes = recipe[0][5] if r_id and recipe[0] else "<Notes>"
        prep_time = recipe[0][6] if r_id and recipe[0] else "<Prep Time>"
        cook_time = recipe[0][7] if r_id and recipe[0] else "<Cook Time>"
        ingredients = []
        if r_id and recipe:
            for i in sorted(recipe[1], key=lambda tup: tup[3]):
                ingredients.append(i)
        else:
            ingredients.append(
                ("<Amount>", "<Unit>", "<Ingredient>", "<Order>"))

        self.name_label.destroy()
        self.name_label = Label(self.frame,
                                text=name,
                                bg="white",
                                font=("Times", 18, "bold"),
                                wraplength=self.canvas_width)
        self.name_label.grid(row=0, column=0, columnspan=6, sticky=W)
        self.serv_label.config(text="Serves {}    ".format(servings))
        self.prep_label.config(text="    Prep: {} min.    ".format(prep_time))
        self.cook_label.config(text="    Cook: {} min.".format(cook_time))
        self.desc_label.destroy()
        self.desc_label = Label(self.frame,
                                text=description,
                                bg="white",
                                font=("Times", 12, "italic"),
                                justify=LEFT,
                                wraplength=self.canvas_width)
        self.desc_label.grid(row=2, column=0, columnspan=6, sticky=W)
        for i in self.ingr_label_list:
            i[0].destroy()
            i[1].destroy()
            i[2].destroy()
        row = 5
        self.ingr_label_list = []
        for i in ingredients:
            if r_id and recipe:
                prec = 1e4
                amount = (int(i[0]), int(float(i[0]) * prec) % prec / prec)
                val = None
                for frac in [(.5, "1/2"), (.25, "1/4"), (.125, "1/8"),
                             (.333, "1/3"), (.3333, "1/3"), (.3334, "1/3"),
                             (.75, "3/4"), (.0625, "1/16"), (.666, "2/3"),
                             (.6666, "2/3"), (.6667, "2/3")]:
                    if amount[1] == frac[0]:
                        val = "{}  {}".format(
                            amount[0], frac[1]) if amount[0] else frac[1]
                if i[0] == 0:
                    val = "-"
            else:
                val = i[0]
            self.ingr_label_list.append(
                (Label(self.frame,
                       text=(val if val else str(amount[0])),
                       bg="white",
                       font=("Times", 10, ""),
                       justify=LEFT,
                       wraplength=80),
                 Label(self.frame,
                       text=i[1],
                       bg="white",
                       font=("Times", 10, ""),
                       justify=LEFT,
                       wraplength=135),
                 Label(self.frame,
                       text=i[2],
                       bg="white",
                       font=("Times", 10, ""),
                       justify=LEFT,
                       wraplength=135)))
            self.ingr_label_list[row - 5][0].grid(row=row,
                                                  column=0,
                                                  sticky=W + N)
            self.ingr_label_list[row - 5][1].grid(row=row,
                                                  column=1,
                                                  sticky=W + N)
            self.ingr_label_list[row - 5][2].grid(row=row,
                                                  column=2,
                                                  columnspan=2,
                                                  sticky=W + N)
            row += 1
        self.blank_label_2.destroy()
        self.blank_label_2 = Label(self.frame, text="", bg="white", height=1)
        self.blank_label_2.grid(row=row, column=1, sticky=W)
        self.dir_label_title.destroy()
        self.dir_label_title = Label(self.frame,
                                     text="Directions",
                                     bg="white",
                                     font=("Times", 12, "bold"))
        self.dir_label_title.grid(row=row + 1,
                                  column=0,
                                  columnspan=3,
                                  sticky=W)
        self.dir_label.destroy()
        self.dir_label = Label(self.frame,
                               text=directions,
                               bg="white",
                               font=("Times", 10, ""),
                               justify=LEFT,
                               wraplength=self.canvas_width)
        self.dir_label.grid(row=row + 2, column=0, columnspan=3, sticky=W)
        self.blank_label_3.destroy()
        self.blank_label_3 = Label(self.frame, text="", bg="white", height=1)
        self.blank_label_3.grid(row=row + 3, column=1, sticky=W)
        self.note_label_title.destroy()
        self.note_label_title = Label(self.frame,
                                      text="Notes",
                                      bg="white",
                                      font=("Times", 12, "bold"))
        self.note_label_title.grid(row=row + 4,
                                   column=0,
                                   columnspan=3,
                                   sticky=W)
        self.note_label.destroy()
        self.note_label = Label(self.frame,
                                text=notes,
                                bg="white",
                                font=("Times", 10, ""),
                                justify=LEFT,
                                wraplength=self.canvas_width)
        self.note_label.grid(row=row + 5, column=0, columnspan=3, sticky=W)