def set_product_image(self, image): self.default_image = image self.prod_image = get_image_from_bytes(self.default_image) img_width, img_height = scale_image(self.prod_image, self.shared_view.ADD_ITEM_IMG_SIZE) self.prod_image = self.prod_image.resize((img_width, img_height)) self.avatar_render = ImageTk.PhotoImage(self.prod_image) self.canvas_avatar.itemconfig(self.canvas_image_avatar, image=self.avatar_render) self.new_image = True
def _fill_container_with_products(self): self.frame_products = Frame(self.frame_scrollable) self.frame_products.pack(fill="both", expand=1) frame_sizer = Frame(self.frame_products, width=550) frame_sizer.pack() self.prods_images = [] self.prods_img_renders = [] self.product_selected = tk.IntVar() index = 0 for prod_id in self.user['selected_products_ids']: product = self.user['products'][f'{prod_id}'] frame_product = Frame(self.frame_products, relief="ridge", bd=2) frame_product.pack(fill="both", padx=self.shared_view.VERY_SMALL_PAD, pady=self.shared_view.VERY_SMALL_PAD) frame_product.focus() # Radio button frame_radio_button = Frame(frame_product) frame_radio_button.grid(row=0, column=0) product_radio_button = Radiobutton(frame_radio_button, variable=self.product_selected, value=index) product_radio_button.pack(fill="both", padx=(self.shared_view.SMALL_PAD, 0)) # Img frame_image = Frame(frame_product, relief="groove", bd=1) frame_image.grid(row=0, column=1, padx=(0, self.shared_view.SMALL_PAD), pady=self.shared_view.SMALL_PAD) self.prods_images.append(product['image']) img_width, img_height = scale_image(self.prods_images[index], self.shared_view.LIST_IMG_SIZE) self.prods_images[index] = self.prods_images[index].resize( (img_width, img_height)) self.prods_img_renders.append( ImageTk.PhotoImage(self.prods_images[index])) canvas_avatar = tk.Canvas(frame_image, width=self.shared_view.LIST_IMG_SIZE, height=self.shared_view.LIST_IMG_SIZE) canvas_avatar.create_image( (self.shared_view.LIST_IMG_SIZE // 2) + 1, (self.shared_view.LIST_IMG_SIZE // 2) + 1, image=self.prods_img_renders[index]) canvas_avatar.pack(fill="both") # Name frame_name = Frame(frame_product, relief="ridge", bd=1) frame_name.grid(row=0, column=2, padx=(0, self.shared_view.SMALL_PAD), pady=self.shared_view.SMALL_PAD) label_name = Label(frame_name, text=f"{product['product_name']}", font=self.shared_view.font_style_10_bold) label_name.pack(padx=self.shared_view.SMALL_PAD, pady=self.shared_view.SMALL_PAD) # GI rating frame_gi_rating = Frame(frame_product, relief="ridge", bd=1) frame_gi_rating.grid(row=0, column=3, padx=(0, self.shared_view.SMALL_PAD), pady=self.shared_view.SMALL_PAD) gi_rating_index = product['glycemic_index_rating'] label_gi_rating = Label( frame_gi_rating, text=f"{GI_RATING_OPTIONS[gi_rating_index]}", font=self.shared_view.font_style_10) label_gi_rating.pack(padx=self.shared_view.SMALL_PAD, pady=self.shared_view.SMALL_PAD) # Calories frame_calories = Frame(frame_product, relief="ridge", bd=1) frame_calories.grid(row=0, column=4, padx=(0, self.shared_view.SMALL_PAD), pady=self.shared_view.SMALL_PAD) frame_center = Frame(frame_calories) frame_center.pack() label_calories = Label(frame_center, text=f"{product['calories']} kcal/100g", font=self.shared_view.font_style_10) label_calories.pack(padx=self.shared_view.SMALL_PAD, pady=self.shared_view.SMALL_PAD) index += 1
def _fill_container_with_products(self): self.frame_products = Frame(self.frame_scrollable) self.frame_products.pack(fill="both", expand=1) frame_sizer = Frame(self.frame_products, width=550) frame_sizer.pack() self.prods_images = list() self.prods_img_renders = list() self.product_selected = tk.IntVar() prod_id = 0 size = len(self.products_ids_list ) if self.products_ids_list is not None else 0 for i in range(0, size): dish_prod = self.user_products[f'{self.products_ids_list[i]}'] frame_product = Frame(self.frame_products, relief="ridge", bd=2) frame_product.pack(fill="both", padx=self.shared_view.VERY_SMALL_PAD, pady=self.shared_view.VERY_SMALL_PAD) frame_product.focus() # Radio button frame_radio_button = Frame(frame_product) frame_radio_button.grid(row=0, column=0) product_radio_button = Radiobutton(frame_radio_button, variable=self.product_selected, value=prod_id) product_radio_button.pack(fill="both", padx=(self.shared_view.SMALL_PAD, 0)) # Img frame_image = Frame(frame_product, relief="groove", bd=1) frame_image.grid(row=0, column=1, padx=(0, self.shared_view.SMALL_PAD), pady=self.shared_view.SMALL_PAD) self.prods_images.append(dish_prod['image']) img_width, img_height = scale_image(self.prods_images[prod_id], self.shared_view.LIST_IMG_SIZE) self.prods_images[prod_id] = self.prods_images[prod_id].resize( (img_width, img_height)) self.prods_img_renders.append( ImageTk.PhotoImage(self.prods_images[prod_id])) canvas_avatar = tk.Canvas(frame_image, width=self.shared_view.LIST_IMG_SIZE, height=self.shared_view.LIST_IMG_SIZE) canvas_avatar.create_image( (self.shared_view.LIST_IMG_SIZE // 2) + 1, (self.shared_view.LIST_IMG_SIZE // 2) + 1, image=self.prods_img_renders[prod_id]) canvas_avatar.pack(fill="both") # Name frame_name = Frame(frame_product, relief="ridge", bd=1) frame_name.grid(row=0, column=2, padx=(0, self.shared_view.SMALL_PAD), pady=self.shared_view.SMALL_PAD) label_name = Label(frame_name, text=f"{dish_prod['product_name']}", font=self.shared_view.font_style_10_bold) label_name.pack(padx=self.shared_view.SMALL_PAD, pady=self.shared_view.SMALL_PAD) # GI rating frame_gi_rating = Frame(frame_product, relief="ridge", bd=1) frame_gi_rating.grid(row=0, column=3, padx=(0, self.shared_view.SMALL_PAD), pady=self.shared_view.SMALL_PAD) gi_rating_index = dish_prod['glycemic_index_rating'] label_gi_rating = Label( frame_gi_rating, text=f"{GI_RATING_OPTIONS[gi_rating_index]}", font=self.shared_view.font_style_10) label_gi_rating.pack(padx=self.shared_view.SMALL_PAD, pady=self.shared_view.SMALL_PAD) # Grammage frame_grammage = Frame(frame_product, relief="ridge", bd=1) frame_grammage.grid(row=0, column=4, padx=(0, self.shared_view.SMALL_PAD), pady=self.shared_view.SMALL_PAD) label_grammage = Label(frame_grammage, text=f"{self.products_grammage_list[i]} g", font=self.shared_view.font_style_10) label_grammage.pack(padx=self.shared_view.SMALL_PAD, pady=self.shared_view.SMALL_PAD) # Calories frame_calories = Frame(frame_product, relief="ridge", bd=1) frame_calories.grid(row=0, column=5, padx=(0, self.shared_view.SMALL_PAD), pady=self.shared_view.SMALL_PAD) frame_center = Frame(frame_calories) frame_center.pack() calories = int( (dish_prod['calories'] * int(self.products_grammage_list[i])) / 100) label_calories = Label(frame_center, text=f"{calories} kcal", font=self.shared_view.font_style_10) label_calories.pack(padx=self.shared_view.SMALL_PAD, pady=self.shared_view.SMALL_PAD) prod_id += 1
def _create_entries(self): # Name label_frame = LabelFrame(self.frame_main, text="Nazwa nowego produktu:", font=self.shared_view.font_style_10_bold) label_frame.pack(fill=tk.BOTH, expand=1) frame_name = ttk.Frame(label_frame) frame_name.pack(fill=tk.BOTH, padx=self.shared_view.SMALL_PAD, pady=self.shared_view.SMALL_PAD) self.entry_name = tk.Entry(frame_name, font=self.shared_view.font_style_12) self.entry_name.pack(fill=tk.BOTH, padx=self.shared_view.SMALL_PAD, pady=self.shared_view.SMALL_PAD) self.entry_name.insert(0, f'{self.default_name}') # GI rating label_frame = LabelFrame(self.frame_main, text="Stopień indeksu glikemicznego:", font=self.shared_view.font_style_10_bold) label_frame.pack(fill=tk.BOTH, expand=1, pady=(self.shared_view.NORMAL_PAD, 0)) frame_gi_rating = ttk.Frame(label_frame) frame_gi_rating.pack(fill=tk.BOTH, padx=self.shared_view.SMALL_PAD, pady=self.shared_view.SMALL_PAD) gi_rating_options_list = GI_RATING_OPTIONS_LIST self.gi_rating_value = tk.StringVar( value=gi_rating_options_list[self.default_ig_rating]) gi_option_menu = tk.OptionMenu(frame_gi_rating, self.gi_rating_value, *gi_rating_options_list) gi_option_menu.config(font=self.shared_view.font_style_12) gi_option_menu.pack(fill=tk.BOTH, padx=self.shared_view.SMALL_PAD, pady=(self.shared_view.SMALL_PAD, self.shared_view.SMALL_PAD)) # Calories label_frame = LabelFrame(self.frame_main, text="Liczba kalorii na 100 gram:", font=self.shared_view.font_style_10_bold) label_frame.pack(fill=tk.BOTH, expand=1, pady=(self.shared_view.SMALL_PAD, 0)) frame_calories = ttk.Frame(label_frame) frame_calories.pack(fill=tk.BOTH, padx=self.shared_view.SMALL_PAD, pady=self.shared_view.SMALL_PAD) self.entry_calories = tk.Entry(frame_calories, font=self.shared_view.font_style_12) self.entry_calories.pack(fill=tk.BOTH, padx=self.shared_view.SMALL_PAD, pady=self.shared_view.SMALL_PAD) self.entry_calories.insert(0, f'{self.default_calories}') # Image label_frame = LabelFrame(self.frame_main, text="Zdjęcie produktu:", font=self.shared_view.font_style_10_bold) label_frame.pack(fill=tk.BOTH, pady=(self.shared_view.SMALL_PAD, 0)) frame_image = ttk.Frame(label_frame) frame_image.pack(fill=tk.BOTH, padx=self.shared_view.SMALL_PAD, pady=self.shared_view.SMALL_PAD) if self.default_image is None: self.default_image = convert_to_binary_data(IMG_PATH_NO_IMAGE) self.prod_image = get_image_from_bytes(self.default_image) else: self.prod_image = self.default_image img_width, img_height = scale_image(self.prod_image, self.shared_view.ADD_ITEM_IMG_SIZE) self.prod_image = self.prod_image.resize((img_width, img_height)) self.canvas_avatar = tk.Canvas( frame_image, width=self.shared_view.ADD_ITEM_IMG_SIZE, height=self.shared_view.ADD_ITEM_IMG_SIZE) self.avatar_render = ImageTk.PhotoImage(self.prod_image) self.canvas_image_avatar = self.canvas_avatar.create_image( (self.shared_view.ADD_ITEM_IMG_SIZE / 2) + 1, (self.shared_view.ADD_ITEM_IMG_SIZE / 2) + 1, image=self.avatar_render) self.canvas_avatar.pack() self.btn_add_img = tk.Button(frame_image, text="Ustaw zdjęcie", width=self.shared_view.btn_size, font=self.shared_view.font_style_12) self.btn_add_img.pack(pady=(self.shared_view.NORMAL_PAD, 0))
def _create_entries(self): # Name label_frame = LabelFrame(self.frame_main, text="Nazwa nowego dania:", font=self.shared_view.font_style_10_bold) label_frame.pack(fill=tk.BOTH, expand=1, pady=0) frame_name = ttk.Frame(label_frame) frame_name.pack(fill=tk.BOTH, padx=self.shared_view.SMALL_PAD, pady=self.shared_view.SMALL_PAD) self.entry_name = tk.Entry(frame_name, font=self.shared_view.font_style_12) self.entry_name.pack(fill=tk.BOTH, padx=self.shared_view.SMALL_PAD, pady=self.shared_view.SMALL_PAD) self.entry_name.insert(0, f'{self.default_name}') # GI rating label_frame = LabelFrame(self.frame_main, text="Stopień indeksu glikemicznego:", font=self.shared_view.font_style_10_bold) label_frame.pack(fill=tk.BOTH, expand=1, pady=(self.shared_view.SMALL_PAD, 0)) frame_gi_rating = ttk.Frame(label_frame) frame_gi_rating.pack(fill=tk.BOTH, padx=self.shared_view.SMALL_PAD, pady=self.shared_view.SMALL_PAD) gi_rating_options_list = GI_RATING_OPTIONS_LIST self.gi_rating_value = tk.StringVar( value=gi_rating_options_list[self.default_ig_rating]) gi_option_menu = tk.OptionMenu(frame_gi_rating, self.gi_rating_value, *gi_rating_options_list) gi_option_menu.config(font=self.shared_view.font_style_12) gi_option_menu.pack(fill=tk.BOTH, padx=self.shared_view.SMALL_PAD, pady=(self.shared_view.SMALL_PAD, self.shared_view.SMALL_PAD)) # Products self.frame_container_products = LabelFrame( self.frame_main, text="Produkty:", font=self.shared_view.font_style_10_bold) self.frame_container_products.pack(fill="both", pady=(self.shared_view.SMALL_PAD, 0)) self.canvas_products = Canvas(self.frame_container_products, bd=0, highlightthickness=0, height=200) self.scrollbar_products = Scrollbar(self.frame_container_products, orient=VERTICAL, command=self.canvas_products.yview) self.frame_scrollable = Frame(self.canvas_products) self.frame_scrollable.bind( "<Configure>", lambda e: self.canvas_products.configure( scrollregion=self.canvas_products.bbox("all"))) self.canvas_products.create_window((0, 0), window=self.frame_scrollable, anchor="nw") self.canvas_products.configure( yscrollcommand=self.scrollbar_products.set) self.canvas_products.pack(side="left", fill="both", expand=1) self.scrollbar_products.pack(side="right", fill="y") # Products buttons self.frame_buttons = ttk.Frame(self.frame_main) self.frame_buttons.pack() self.btn_delete_prod = tk.Button(self.frame_buttons, text="Usuń produkt", width=self.shared_view.btn_size, font=self.shared_view.font_style_12) self.btn_delete_prod.pack(side='left', padx=(0, self.shared_view.NORMAL_PAD), pady=self.shared_view.SMALL_PAD) self.btn_edit_prod = tk.Button(self.frame_buttons, text="Edytuj produkt", width=self.shared_view.btn_size, font=self.shared_view.font_style_12) self.btn_edit_prod.pack(side='left', padx=(0, self.shared_view.NORMAL_PAD), pady=self.shared_view.SMALL_PAD) self.btn_add_prod = tk.Button(self.frame_buttons, text="Dodaj produkt", width=self.shared_view.btn_size, font=self.shared_view.font_style_12) self.btn_add_prod.pack(side='left', pady=self.shared_view.SMALL_PAD) # Image label_frame = LabelFrame(self.frame_main, text="Zdjęcie dania:", font=self.shared_view.font_style_10_bold) label_frame.pack(fill=tk.BOTH, pady=(self.shared_view.SMALL_PAD, 0)) frame_image = ttk.Frame(label_frame) frame_image.pack(fill=tk.BOTH, padx=self.shared_view.SMALL_PAD, pady=self.shared_view.SMALL_PAD) if self.default_image is None: self.default_image = convert_to_binary_data(IMG_PATH_NO_IMAGE) self.dish_image = get_image_from_bytes(self.default_image) else: self.dish_image = self.default_image img_width, img_height = scale_image(self.dish_image, self.shared_view.ADD_ITEM_IMG_SIZE) self.dish_image = self.dish_image.resize((img_width, img_height)) self.canvas_avatar = tk.Canvas( frame_image, width=self.shared_view.ADD_ITEM_IMG_SIZE, height=self.shared_view.ADD_ITEM_IMG_SIZE) self.avatar_render = ImageTk.PhotoImage(self.dish_image) self.canvas_image_avatar = self.canvas_avatar.create_image( (self.shared_view.ADD_ITEM_IMG_SIZE / 2) + 1, (self.shared_view.ADD_ITEM_IMG_SIZE / 2) + 1, image=self.avatar_render) self.canvas_avatar.pack() self.btn_add_img = tk.Button(frame_image, text="Ustaw zdjęcie", width=self.shared_view.btn_size, font=self.shared_view.font_style_12) self.btn_add_img.pack(pady=(self.shared_view.SMALL_PAD, 0))