a
    A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rTd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dddddZdS )     )annotationsN)BytesIO)TYPE_CHECKINGAnycast   )Image	ImageFile)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   J/var/www/lab.imftr.de/x/nb_venv/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   _pyimagingtkcall5   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 rd}t|nF|j}|dkr~|  |  |jrz|jjnd}|j}|\|d< |d< |dvrt	
|}|| _|| _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)r2   nameAttributeErrorr   r   	Exceptionr4   r:   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   r2   r4   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   r1   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   rC   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)getimrF   Zisblockr.   r0   r   coreZ	new_blockr#   Zconvert2r   r    r2   )r4   rF   r   r"   blockr   r   r   r3      s    
zPhotoImage.paste)NN)
__name__
__module____qualname____doc__r6   r>   r@   r'   r(   r3   r   r   r   r   r!   H   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   rN   Ztobitmap_BitmapImage__photo)r4   r"   r   r5   r   r   r   r6      s    zBitmapImage.__init__r7   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 r8   )rP   r:   r;   r   r   r<   r=   r   r   r   r>      s    zBitmapImage.__del__rA   c                 C  s
   | j d S rB   rO   r?   r   r   r   r'      s    zBitmapImage.widthc                 C  s
   | j d S rD   rQ   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   rP   r?   r   r   r   r@      s    zBitmapImage.__str__)N)	rJ   rK   rL   rM   r6   r>   r'   r(   r@   r   r   r   r   rN      s   rN   rE   )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    rG   )r   rF   r   r   r   getimage  s    rS   z
str | None)r"   titler   c                 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ddd fddZ  ZS )z_show.<locals>.UIztkinter.ToplevelrE   r   )masterrF   r   c                   s`   |  |j dkr t|d|d| _nt||d| _trBttj| j}n| j}t j	||ddd d S )Nr)   Zwhite)Z
foregroundrU   )rU   Zblackr   )r"   bgZbd)
r.   rN   r"   r!   r   r   r   Z_Imagesuperr6   )r4   rU   rF   r"   	__class__r   r   r6     s    
z_show.<locals>.UI.__init__)rJ   rK   rL   r6   __classcell__r   r   rX   r   UI  s   r[   Z_default_rootztkinter not initializedN)r   ZLabelgetattrOSErrorZToplevelrT   pack)r"   rT   r[   r5   topr   r   r   _show  s    

r`   )
__future__r   r   ior   typingr   r   r   r   r   r	   _typingr
   r   r    r!   rN   rS   r`   r   r   r   r   <module>   s   zA	