o
    6>g%#                     @  s   d dl mZ d dlZd dlmZ d dlmZmZmZ ddl	m
Z
mZ er*ddlmZ d#ddZd$ddZG dd dZG dd dZd%ddZd&d!d"ZdS )'    )annotationsN)BytesIO)TYPE_CHECKINGAnycast   )Image	ImageFile)CapsuleTypekwdict[str, Any]returnImageFile.ImageFile | Nonec                 C  s@   d }d| v r|  d}nd| v rt|  d}|sd S t|S )Nfiledata)popr   r   open)r   source r   >/var/www/html/venv/lib/python3.10/site-packages/PIL/ImageTk.py_get_image_from_kw*   s   
r   commandstrphotoPhotoImage | tkinter.PhotoImageptrr
   Nonec              	   C  sb   |j }z|| |t| W d S  tjy0   ddlm} ||  || |t| Y d S w )Nr   )
_imagingtk)	tkcallreprtkinterTclError r   tkinit
interpaddr)r   r   r   r   r   r   r   r   _pyimagingtkcall5   s   r&   c                   @  sR   e Zd ZdZ		ddddZdddZdddZdddZdddZd ddZ	dS )!
PhotoImagea3  
    A Tkinter-compatible photo image.  This can be used
    everywhere Tkinter expects an image object.  If the image is an RGBA
    image, pixels having alpha 0 are treated as transparent.

    The constructor takes either a PIL image, or a mode and a size.
    Alternatively, you can use the ``file`` or ``data`` options to initialize
    the photo image object.

    :param image: Either a PIL image, or a mode string.  If a mode string is
                  used, a size must also be given.
    :param size: If the first argument is a mode string, this defines the size
                 of the image.
    :keyword file: A filename to load the image from (using
                   ``Image.open(file)``).
    :keyword data: An 8-bit string containing image data (as loaded from an
                   image file).
    NimageImage.Image | str | Nonesizetuple[int, int] | Noner   r   r   r   c                 K  s   |d u rt |}|d u rd}t|t|tr&|}d }|d u r%d}t|n#|j}|dkr>|  |  |jr<|jjnd}|j}|\|d< |d< |dvrRt	
|}|| _|| _tjdi || _| jj| _|ro| | d S d S )	NImage is requiredz+If first argument is mode, size is requiredPRGBwidthheight)1Lr.   RGBAr   )r   
ValueError
isinstancer   modeapply_transparencyloadpaletter*   r   getmodebase_PhotoImage__mode_PhotoImage__sizer!   r'   _PhotoImage__photor   paste)selfr(   r*   r   msgr6   r   r   r   __init__\   s8   


zPhotoImage.__init__c                 C  X   z| j j}W n
 ty   Y d S w d | j _z| j jdd| W d S  ty+   Y d S w Nr(   delete)r=   nameAttributeErrorr   r   	Exceptionr?   rE   r   r   r   __del__      zPhotoImage.__del__r   c                 C  
   t | jS )z
        Get the Tkinter photo image identifier.  This method is automatically
        called by Tkinter whenever a PhotoImage object is passed to a Tkinter
        method.

        :return: A Tkinter photo image identifier (a string).
        )r   r=   r?   r   r   r   __str__      
zPhotoImage.__str__intc                 C  
   | j d S zU
        Get the width of the image.

        :return: The width, in pixels.
        r   r<   rL   r   r   r   r/         
zPhotoImage.widthc                 C  rP   zW
        Get the height of the image.

        :return: The height, in pixels.
        r   rR   rL   r   r   r   r0      rS   zPhotoImage.heightimImage.Imagec                 C  sX   |  }|j}| r|j| jkr#tj| j|j}|	|| |j
}td| j| dS )aF  
        Paste a PIL image into the photo image.  Note that this can
        be very slow if the photo image is displayed.

        :param im: A PIL image. The size must match the target region.  If the
                   mode does not match, the image is converted to the mode of
                   the bitmap image.
        PyImagingPhotoN)getimrU   isblockr6   r;   r   core	new_blockr*   convert2r   r&   r=   )r?   rU   r   r(   blockr   r   r   r>      s   
zPhotoImage.paste)NN)r(   r)   r*   r+   r   r   r   r   r   r   r   r   r   rO   )rU   rV   r   r   )
__name__
__module____qualname____doc__rA   rI   rM   r/   r0   r>   r   r   r   r   r'   H   s    
)



r'   c                   @  sD   e Zd ZdZddd	d
ZdddZdddZdddZdddZdS )BitmapImagea  
    A Tkinter-compatible bitmap image.  This can be used everywhere Tkinter
    expects an image object.

    The given image must have mode "1".  Pixels having value 0 are treated as
    transparent.  Options, if any, are passed on to Tkinter.  The most commonly
    used option is ``foreground``, which is used to specify the color for the
    non-transparent parts.  See the Tkinter documentation for information on
    how to specify colours.

    :param image: A PIL image.
    Nr(   Image.Image | Noner   r   r   r   c                 K  sR   |d u rt |}|d u rd}t||j| _|j| _tjdd| i|| _	d S )Nr,   r   r   )
r   r4   r6   _BitmapImage__moder*   _BitmapImage__sizer!   re   tobitmap_BitmapImage__photo)r?   r(   r   r@   r   r   r   rA      s   zBitmapImage.__init__c                 C  rB   rC   )rj   rE   rF   r   r   rG   rH   r   r   r   rI      rJ   zBitmapImage.__del__rO   c                 C  rP   rQ   rh   rL   r   r   r   r/      rS   zBitmapImage.widthc                 C  rP   rT   rk   rL   r   r   r   r0      rS   zBitmapImage.heightr   c                 C  rK   )z
        Get the Tkinter bitmap image identifier.  This method is automatically
        called by Tkinter whenever a BitmapImage object is passed to a Tkinter
        method.

        :return: A Tkinter bitmap image identifier (a string).
        )r   rj   rL   r   r   r   rM      rN   zBitmapImage.__str__)N)r(   rf   r   r   r   r   r^   r`   r_   )	ra   rb   rc   rd   rA   rI   r/   r0   rM   r   r   r   r   re      s    


re   rV   c                 C  s,   t d|  |  f}td| |  |S )z:Copies the contents of a PhotoImage to a PIL image memory.r3   PyImagingPhotoGet)r   newr/   r0   r&   rX   )r   rU   r   r   r   getimage  s   rn   r(   title
str | Nonec                 C  sP   G dd dt j}tt dsd}t|t  }|r|| |||   dS )z!Helper for the Image.show method.c                      s   e Zd Zd	 fddZ  ZS )
z_show.<locals>.UImastertkinter.ToplevelrU   rV   r   r   c                   s`   |  |j dkrt|d|d| _nt||d| _tr!ttj| j}n| j}t j	||ddd d S )Nr1   white)
foregroundrq   )rq   blackr   )r(   bgbd)
r6   re   r(   r'   r   r   r!   _ImagesuperrA   )r?   rq   rU   r(   	__class__r   r   rA     s   
z_show.<locals>.UI.__init__)rq   rr   rU   rV   r   r   )ra   rb   rc   rA   __classcell__r   r   rz   r   UI  s    r}   _default_rootztkinter not initializedN)r!   LabelgetattrOSErrorToplevelro   pack)r(   ro   r}   r@   topr   r   r   _show  s   

r   )r   r   r   r   )r   r   r   r   r   r
   r   r   )r   r'   r   rV   )r(   rV   ro   rp   r   r   )
__future__r   r!   ior   typingr   r   r   r#   r   r	   _typingr
   r   r&   r'   re   rn   r   r   r   r   r   <module>   s   

z
A	