def _save_edit(self, ingredient_name: str, ingredient_quantity: float, ingredient_unit_type: str, kroger_upc: str, kroger_quantity: float, edit_window: Toplevel): """ Saves the contents from the edit window """ ingredient_dict: dict = { 'ingredient_id': self.ingredient['ingredient_id'], 'ingredient_name': ingredient_name, 'ingredient_quantity': ingredient_quantity, 'ingredient_unit_type': ingredient_unit_type, 'kroger_upc': kroger_upc, 'kroger_quantity': kroger_quantity, } root: 'View' = self.winfo_toplevel() # Packaging for controller payload: dict = { 'change': 'update_ingredient', 'parameter': ingredient_dict } ret = root.controller.edit_recipe(self.recipe_id, payload) if ret[0] != 0: error_message(ret) else: # Updating labels self.name_label.config(text=ingredient_name) self.iquantity_label.config(text=ingredient_quantity) self.mtype_label.config(text=ingredient_unit_type) self.kroger_upc.config(text=kroger_upc) self.kroger_quantity.config(text=kroger_quantity) self.ingredient = ingredient_dict edit_window.destroy()
def _save(self, recipe_title: str, iquant: float, mtype: str, kupc: str, kquant: float, new_window: Toplevel): """ Saves the newly created ingredient """ # Requesting ingredient creation through Controller ingredient_dict: dict = { 'ingredient_name': recipe_title, 'ingredient_quantity': iquant, 'ingredient_unit_type': mtype, 'kroger_upc': kupc, 'kroger_quantity': kquant } root: 'View' = self.winfo_toplevel() ret = root.controller.edit_recipe(self.recipe['recipe_id'], { 'change': 'add_ingredient', 'parameter': ingredient_dict }) if ret[0] != 0: error_message(ret) else: new_ingredient_id = ret[1]['ingredient_id'] ingredient_dict['ingredient_id'] = new_ingredient_id new_component: IngredientComponent = IngredientComponent( self, 0, self.ing_index, self.recipe['recipe_id'], ingredient_dict) self.ing_index += 1 self.ingredient_components[new_ingredient_id] = new_component # Updating canvas size self.parent.dsf.resize() new_window.destroy()
def _delete_recipe(self, confirmation_window: Toplevel): confirmation_window.destroy() # Checking for selected recipe recipe_id: int = self.DetailScrollFrame.visible_frame.recipe_id ret = self.controller.delete_recipe(recipe_id) if ret[0] == -1: error_message(ret) return self.SelectionScrollFrame.delete_recipe(recipe_id) self.DetailScrollFrame.delete_recipe()
def _new_recipe(self): # Requesting new recipe from the controller ret = self.controller.new_recipe() if ret[0] == -1: error_message(ret) else: new_recipe: dict = ret[1] active_recipe: 'DetailFrame' = self.DetailScrollFrame.visible_frame # pulled for select's benefit self.DetailScrollFrame.new_recipe(new_recipe) self.SelectionScrollFrame.add_recipe(active_recipe, new_recipe) print(ret)
def _save_notes(self): """ Pulls the contents of the text widget and sends them to be saved. """ notes = self.text_widget.get('1.0', END) # Save attempt with Model here root: 'View' = self.winfo_toplevel() note_dict: dict = {'recipe_notes': notes} payload: dict = {'change': 'update_notes', 'parameter': note_dict} ret = root.controller.edit_recipe(self.recipe_id, payload) if ret[0] != 0: error_message(ret) else: self.note_string = notes
def _delete_ingredient(self, confirmation_window: Toplevel): confirmation_window.destroy() # Ask controller to perform the deletion root: 'View' = self.winfo_toplevel() payload: dict = { 'change': 'delete_ingredient', 'parameter': { 'ingredient_id': self.ingredient['ingredient_id'] } } ret = root.controller.edit_recipe(self.recipe_id, payload) if ret[0] != 0: error_message(ret) else: # Successfully deleted ingredient from DB self.parent.ingredient_components.pop( self.ingredient['ingredient_id']) self.destroy()
def _update_name(self, new_name: str, edit_window: Toplevel): # Requesting change with controller root: 'View' = self.winfo_toplevel() ret = root.controller.edit_recipe(self.recipe_id, { 'change': 'rename_recipe', 'parameter': new_name }) if ret[0] != 0: error_message(ret[1]) print(ret) else: self.recipe_name = new_name self.label.configure(text=self.recipe_name) # Updating SelectFrame select_frame: 'SelectFrame' = root.SelectionScrollFrame.select_frames[ self.recipe_id] select_frame.label.configure(text=self.recipe_name) edit_window.destroy()
def _delete_confirmation(self): if self.SelectionScrollFrame.highlighted_frame is None: print('No recipe is currently selected') error_message('No recipe is currently selected') return recipe_title: str = self.SelectionScrollFrame.highlighted_frame.recipe[ 'recipe_title'] """ Opens a dialog box allowing user to confirm/deny proper usage of the delete button """ new_window: Toplevel = Toplevel(height=300, width=300) name_label: Label = Label(new_window, text=f'delete {recipe_title}?') name_label.grid(column=0, row=0, columnspan=2) ok_button: Button = Button( new_window, text='Confirm', command=lambda: self._delete_recipe(new_window)) ok_button.grid(column=0, row=1) cancel_button: Button = Button(new_window, text='Cancel', command=lambda: new_window.destroy()) cancel_button.grid(column=1, row=1)
def _load_cart(self): ret = self.controller.load_cart() if ret[0] != 0: error_message(ret)