a
    ¨º”hÄ  ã                   @  s¤   d dl mZ d dlZd dlmZ d dlmZ ddlmZm	Z	 dZ
e
rPddlmZ d	d
dœdd„Zdddddœdd„ZG dd„ dƒZG dd„ dƒZdddœdd„ZdS )é    )ÚannotationsN)ÚBytesIO)ÚAnyé   )ÚImageÚ	ImageFileF)ÚCapsuleTypezdict[str, Any]zImageFile.ImageFile | None)ÚkwÚreturnc                 C  s@   d }d| v r|   d¡}nd| v r.t|   d¡ƒ}|s6d S t |¡S )NÚfileÚdata)Úpopr   r   Úopen)r	   Úsource© r   ú9/var/www/auris/lib/python3.9/site-packages/PIL/ImageTk.pyÚ_get_image_from_kw+   s    r   ÚstrzPhotoImage | tkinter.PhotoImager   ÚNone)ÚcommandÚphotoÚptrr
   c              	   C  sb   |j }z| | |t|ƒ¡ W n@ tjy\   ddlm} | | ¡ ¡ | | |t|ƒ¡ Y n0 d S )Nr   )Ú
_imagingtk)	ÚtkÚcallÚreprÚtkinterZTclErrorÚ r   ZtkinitZ
interpaddr)r   r   r   r   r   r   r   r   Ú_pyimagingtkcall6   s    r   c                   @  sn   e Zd ZdZddddddœdd	„Zdd
œdd„Zdd
œdd„Zdd
œdd„Zdd
œdd„Zdd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).
    NzImage.Image | str | Noneztuple[int, int] | Noner   r   )ÚimageÚsizer	   r
   c                 K  sà   |d u rt |ƒ}|d u r&d}t|ƒ‚nnt|tƒrN|}d }|d u r”d}t|ƒ‚nF|j}|dkr~| ¡  | ¡  |jrz|jjnd}|j}|\|d< |d< |dvr¦t	 
|¡}|| _|| _tjf i |¤Ž| _| jj| _|rÜ|  |¡ d S )NúImage is requiredz+If first argument is mode, size is requiredÚPÚRGBÚwidthÚheight)Ú1ÚLr$   ÚRGBA)r   Ú
ValueErrorÚ
isinstancer   ÚmodeZapply_transparencyÚloadZpaletter!   r   ZgetmodebaseÚ_PhotoImage__modeÚ_PhotoImage__sizer   r   Ú_PhotoImage__photor   Úpaste)Úselfr    r!   r	   Úmsgr,   r   r   r   Ú__init__]   s4    




zPhotoImage.__init__©r
   c                 C  sX   z| j j}W n ty    Y d S 0 d | j _z| j j dd|¡ W n tyR   Y n0 d S ©Nr    Údelete)r0   ÚnameÚAttributeErrorr   r   Ú	Exception©r2   r8   r   r   r   Ú__del__†   s    zPhotoImage.__del__r   c                 C  s
   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   r0   ©r2   r   r   r   Ú__str__‘   s    zPhotoImage.__str__Úintc                 C  s
   | j d S ©zU
        Get the width of the image.

        :return: The width, in pixels.
        r   ©r/   r=   r   r   r   r%   ›   s    zPhotoImage.widthc                 C  s
   | j d S ©zW
        Get the height of the image.

        :return: The height, in pixels.
        r   rA   r=   r   r   r   r&   £   s    zPhotoImage.heightúImage.Image)Úimr
   c                 C  sX   |  ¡ }|j}| ¡ r"|j| jkrFt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.
        ZPyImagingPhotoN)ÚgetimrD   Zisblockr,   r.   r   ÚcoreZ	new_blockr!   Zconvert2r   r   r0   )r2   rD   r   r    Úblockr   r   r   r1   «   s    
zPhotoImage.paste)NN)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r4   r<   r>   r%   r&   r1   r   r   r   r   r   I   s     ý)
r   c                   @  s\   e Zd ZdZdddddœdd„Zdd	œd
d„Zdd	œdd„Zdd	œdd„Zd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.
    NzImage.Image | Noner   r   )r    r	   r
   c                 K  sR   |d u rt |ƒ}|d u r$d}t|ƒ‚|j| _|j| _tjf d| ¡ i|¤Ž| _	d S )Nr"   r   )
r   r*   r,   Z_BitmapImage__moder!   Ú_BitmapImage__sizer   rL   ZtobitmapÚ_BitmapImage__photo)r2   r    r	   r3   r   r   r   r4   Ñ   s    zBitmapImage.__init__r5   c                 C  sX   z| j j}W n ty    Y d S 0 d | j _z| j j dd|¡ W n tyR   Y n0 d S r6   )rN   r8   r9   r   r   r:   r;   r   r   r   r<   Þ   s    zBitmapImage.__del__r?   c                 C  s
   | j d S r@   ©rM   r=   r   r   r   r%   é   s    zBitmapImage.widthc                 C  s
   | j d S rB   rO   r=   r   r   r   r&   ñ   s    zBitmapImage.heightr   c                 C  s
   t | jƒS )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   rN   r=   r   r   r   r>   ù   s    zBitmapImage.__str__)N)	rH   rI   rJ   rK   r4   r<   r%   r&   r>   r   r   r   r   rL   Ã   s   rL   rC   )r   r
   c                 C  s,   t  d|  ¡ |  ¡ f¡}td| | ¡ ƒ |S )z:Copies the contents of a PhotoImage to a PIL image memory.r)   ZPyImagingPhotoGet)r   Únewr%   r&   r   rE   )r   rD   r   r   r   Úgetimage  s    rQ   )Ú
__future__r   r   Úior   Útypingr   r   r   r   ÚTYPE_CHECKINGÚ_typingr   r   r   r   rL   rQ   r   r   r   r   Ú<module>   s   zA