a
    ¦ˆcÿ  ã                   @   sp   d Z ddlmZ ddlmZmZmZ ddlmZ ddl	m
Z
 ddlmZmZ G dd„ deƒZG d	d
„ d
eƒZdS )z& The interface for an image resource. é    )ÚSequence)Ú	HasTraitsÚListÚStr)ÚIImage)Úresource_manager)Úresource_moduleÚresource_pathc                   @   s.   e Zd ZdZeƒ Zeƒ Zeƒ Ze	dd„ ƒZ
dS )ÚIImageResourcez© The interface for an image resource.

    An image resource describes the location of an image and provides a way
    to create a toolkit-specific image on demand.
    c                 C   s   dS )a   Get the size of a toolkit image

        Parameters
        ----------
        image : toolkit image
            A toolkit image to compute the size of.

        Returns
        -------
        size : tuple
            The (width, height) tuple giving the size of the image.
        N© )ÚclsÚimager   r   úZ/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/pyface/i_image_resource.pyÚ
image_size(   s    zIImageResource.image_sizeN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Zabsolute_pathÚnamer   Úsearch_pathÚclassmethodr   r   r   r   r   r
      s   	r
   c                   @   sF   e Zd ZdZdZddd„Zddd„Zddd„Zd	d
„ Ze	dd„ ƒZ
dS )ÚMImageResourcez¥ The mixin class that contains common code for toolkit specific
    implementations of the IImageResource interface.

    Implements: __init__(), create_image()
    Nc                 C   sR   || _ t|tƒr|g}n(t|tƒr(|}n|d ur8|g}ntƒ g}|tƒ g | _d S )N)r   Ú
isinstanceÚstrr   r	   r   r   )Úselfr   r   Ú_pathr   r   r   Ú__init__H   s    

zMImageResource.__init__c                 C   s(   |   |¡}|dur| ¡ }n|  ¡ }|S )a�   Creates a toolkit-specific image for this resource.

        Parameters
        ----------
        size : (int, int) or None
            The desired size as a width, height tuple, or None if wanting
            default image size.

        Returns
        -------
        image : toolkit image
            The toolkit image corresponding to the resource and the specified
            size.
        N)Ú_get_refÚloadÚ_get_image_not_found_image)r   ÚsizeÚrefr   r   r   r   Úcreate_imageY   s
    

zMImageResource.create_imagec                 C   s$   | j du rt | j| j|¡| _ | j S )ai   Return the resource manager reference to the image.

        Parameters
        ----------
        size : (int, int) or None
            The desired size as a width, height tuple, or None if wanting
            default image size.

        Returns
        -------
        ref : ImageReference instance
            The reference to the requested image.
        N)Z_refr   Zlocate_imager   r   )r   r    r   r   r   r   u   s
    

ÿzMImageResource._get_refc                 C   s&   |   ¡ }| |ur| ¡ }ntdƒ‚|S )z˜ Returns the 'image not found' image.

        Returns
        -------
        image : toolkit image
            The 'not found' toolkit image.
        z,cannot locate the file for 'image_not_found')Ú_get_image_not_foundr"   Ú
ValueError)r   Ú	not_foundr   r   r   r   r   ‹   s
    	
z)MImageResource._get_image_not_found_imagec                 C   s&   | j du r ddlm} |dƒ| _ | j S )zÀ Returns the 'image not found' image resource.

        Returns
        -------
        not_found : ImageResource instance
            An image resource for the the 'not found' image.
        Nr   )ÚImageResourceZimage_not_found)Ú_image_not_foundZpyface.image_resourcer&   )r   r&   r   r   r   r#   ž   s    


z#MImageResource._get_image_not_found)N)N)N)r   r   r   r   r'   r   r"   r   r   r   r#   r   r   r   r   r   8   s   	


r   N)r   Úcollections.abcr   Z
traits.apir   r   r   Zpyface.i_imager   Zpyface.resource_managerr   Zpyface.resource.resource_pathr   r	   r
   r   r   r   r   r   Ú<module>
   s   #