def populate_entity(cls, index: int, pframe: tk.Tk, e: entity.Entity): frame = tk.Frame( pframe, bg=COLOR_LEFT_BG, ) radio = tk.Radiobutton( frame, value=index, text=e.get_name(max_length=40), command=partial(cls.select_entity, index), bg=COLOR_LEFT_BG, fg=COLOR_LEFT_TEXT, highlightthickness=0, ) if cls.radio_selected_index == index: radio.select() else: radio.deselect() radio.pack(side=tk.LEFT) img = ImageTk.PhotoImage(e.get_thumbnail(ENTRY_IMAGE_SZ)) image_holder = tk.Label( frame, image=img, ) image_holder.img = img # hold reference image_holder.pack(side=tk.RIGHT) frame.pack(side=tk.TOP, anchor='n', fill='x')
def setName(self, name: str) -> None: """ Sets the name of the action and makes sure the change propagates to all wrappers :return: None :rtype: NoneType """ Entity.setName(self, name) for wrapper in self._wrappers: Entity.setName(wrapper, name)
def setName(self, name: str) -> None: """ Sets the name of the port :param name: The new name to set :type name: str :return: None :rtype: NoneType """ Entity.setName(self, name) if self._action is not None: self._action.synchronizeWrappers()
def update_entity( cls, e: entity.Entity, name: Optional[str] = None, fmt: Optional[str] = None, w_str: Optional[str] = None, h_str: Optional[str] = None, sz_min_str: Optional[str] = None, sz_max_str: Optional[str] = None, ): if (w_str is None) ^ (h_str is None): raise Exception( "Only one among w_str or h_str provided in update_entity") if (sz_min_str is None) ^ (sz_max_str is None): raise Exception( "Only one among sz_min_str or sz_max_str provided in update_entity" ) try: w = int(w_str) h = int(h_str) except ValueError as err: logging.error( f"invalid resolution: '{w_str}'x'{h_str}', err: {err}") raise ValueError(f"Invalid resolution provided '{w_str}x{h_str}'") try: sz_min = int(sz_min_str) sz_max = int(sz_max_str) except ValueError as err: logging.error( f"invalid filesize: '{sz_min_str}...{sz_max_str}', err: {err}") raise ValueError( f"Invalid resolution provided '{sz_min_str}...{sz_max_str}'") e.set_name(name) opts = e.get_export_options() opts.set_resolution((w, h)) opts.set_format(image.ImageFormat[fmt]) opts.set_filesize(sz_min, sz_max)
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)
def entity_image_move_up(cls, e: entity.Entity, index: int): if index > 0: e.swap_images(index, index - 1)
def entity_image_del(cls, e: entity.Entity, index: int): e.remove_image(index)
def add_image_in_entity(cls, e: entity.Entity): fnames = dialog.load_images() e.add_images(fnames)