def populate_entity_details(cls, pframe: tk.Tk, e: entity.Entity): mframe = tk.Frame( pframe, bg=COLOR_RIGHT_BG, ) mframe.pack(side=tk.LEFT, expand=True, fill='y') rframe = tk.Frame( pframe, bg=COLOR_RIGHT_BG, ) rframe.pack(side=tk.RIGHT, expand=True, fill='both') if e is None: tk.Label( pframe, text="Please select a option", bg=COLOR_RIGHT_BG, ).pack(side=tk.TOP) return img_format = tk.StringVar() name_var = tk.StringVar() res_w_var = tk.StringVar() res_h_var = tk.StringVar() size_min_kb = tk.StringVar() size_max_kb = tk.StringVar() name_var.set(e.get_name()) fmt = e.get_export_options() img_format.set(fmt.get_format().name) res_w_var.set(str(fmt.get_resolution()[0])) res_h_var.set(str(fmt.get_resolution()[1])) size_min_kb.set(str(fmt.get_size_min_kb())) size_max_kb.set(str(fmt.get_size_max_kb())) def save_details(): cls.update_entity( e, name=name_var.get(), fmt=img_format.get(), w_str=res_w_var.get(), h_str=res_h_var.get(), sz_min_str=size_min_kb.get(), sz_max_str=size_max_kb.get(), ) # TODO: We should have auto save for entities. tk.Button( mframe, text='Save', command=save_details, borderwidth=ui.FRAME_BORDER, ).pack(side=tk.TOP) tk.Button( mframe, text='Add Image', command=partial(cls.add_image_in_entity, e), borderwidth=ui.FRAME_BORDER, ).pack(side=tk.TOP) tk.Entry( mframe, textvariable=name_var, borderwidth=ui.FRAME_BORDER, ).pack(side=tk.TOP) tk.Label( mframe, text="resolution WxH", borderwidth=ui.FRAME_BORDER, bg=COLOR_RIGHT_BG, ).pack(side=tk.TOP) tk.Entry( mframe, textvariable=res_w_var, borderwidth=ui.FRAME_BORDER, ).pack(side=tk.TOP) tk.Entry( mframe, textvariable=res_h_var, borderwidth=ui.FRAME_BORDER, ).pack(side=tk.TOP) tk.Label( mframe, text="quality min_size max_size in KB", borderwidth=ui.FRAME_BORDER, bg=COLOR_RIGHT_BG, ).pack(side=tk.TOP) tk.Entry( mframe, textvariable=size_min_kb, borderwidth=ui.FRAME_BORDER, ).pack(side=tk.TOP) tk.Entry( mframe, textvariable=size_max_kb, borderwidth=ui.FRAME_BORDER, ).pack(side=tk.TOP) drop = tk.OptionMenu( mframe, img_format, *[fmt.name for fmt in e.get_allowed_fmts()], ) drop.pack(side=tk.TOP) scrollview_bar = tk.Scrollbar(rframe, orient='vertical') scrollview_bar.pack( side=tk.RIGHT, fill='y', ) scrollview_canvas = tk.Canvas( rframe, yscrollcommand=scrollview_bar.set, bg=COLOR_RIGHT_BG, ) scrollview_canvas.pack(side=tk.RIGHT, fill='y') scrollview_frame = ttk.Frame(scrollview_canvas, ) scrollview_bar.config(command=scrollview_canvas.yview) scrollview_frame.bind( "<Configure>", lambda e: scrollview_canvas.configure( scrollregion=scrollview_canvas.bbox("all"))) scrollview_canvas.create_window(0, 0, anchor="nw", window=scrollview_frame) scrollview_canvas.configure(yscrollcommand=scrollview_bar.set) thumbnails_count = e.get_images_count() thumbnails = e.get_all_images_thumbnail(THUMBNAIL_IMAGE_SZ) for it, t in enumerate(thumbnails): fr = tk.Frame( scrollview_frame, bg=COLOR_RIGHT_BG, ) img = ImageTk.PhotoImage(t) image_holder = tk.Label( fr, image=img, borderwidth=ui.FRAME_BORDER, ) image_holder.img = img # hold reference image_holder.pack(side=tk.LEFT) fr_subbuttons = tk.Frame(fr) tk.Button( fr_subbuttons, text="x", state=tk.DISABLED if thumbnails_count == 1 else None, command=partial(cls.entity_image_del, e, it), ).pack( side=tk.TOP, fill='x', ) tk.Button( fr_subbuttons, text="^", state=tk.DISABLED if it == 0 else None, command=partial(cls.entity_image_move_up, e, it), ).pack( side=tk.TOP, fill='x', ) tk.Button( fr_subbuttons, text="v", state=tk.DISABLED if it == thumbnails_count - 1 else None, command=partial(cls.entity_image_move_down, e, it), ).pack( side=tk.TOP, fill='x', ) fr_subbuttons.pack(side=tk.RIGHT) fr.pack(side=tk.TOP)
def entity_image_move_down(cls, e: entity.Entity, index: int): if index < e.get_images_count() - 1: e.swap_images(index, index + 1)