o
    Ñ­j¡!  ã                   @  s|   d dl mZ d dlZd dlmZ ddlmZ daddd	„Zd
d„ Z	dd„ Z
G dd„ dƒZG dd„ dƒZddd„Zdd„ ZdS )é    )ÚannotationsN)ÚBytesIOé   )ÚImageÚreturnÚintc                  C  sT   t d u r(zt dd¡} tjd| jj› �d� da W t S  tjy'   da Y t S w t S )NÚ1)r   r   úPIL:)Údatar   r   )Ú_pilbitmap_okr   ÚnewÚtkinterÚBitmapImageÚimÚidÚTclError)r   © r   úH/var/www/html/CropPilot/venv/lib/python3.10/site-packages/PIL/ImageTk.pyÚ_pilbitmap_check(   s   þþr   c                 C  s@   d }d| v r|   d¡}nd| v rt|   d¡ƒ}|rt |¡S d S )NÚfiler
   )Úpopr   r   Úopen)ÚkwÚsourcer   r   r   Ú_get_image_from_kw4   s   
ÿr   c                 C  sZ   |j }z
| | ||¡ W d S  tjy,   ddlm} | | ¡ ¡ | | ||¡ Y d S w )Nr   )Ú
_imagingtk)ÚtkÚcallr   r   Ú r   ÚtkinitÚ
interpaddr)ÚcommandÚphotor   r   r   r   r   r   Ú_pyimagingtkcall>   s   úr#   c                   @  sL   e Zd ZdZ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).
    Nc                 K  sÖ   |d u rt |ƒ}t|dƒr?t|dƒr?|j}|dkr3| ¡  | ¡  z|jj}W n ty2   d}Y nw |j}|\|d< |d< n|}d }|dvrLt 	|¡}|| _
|| _tjdi |¤Ž| _| jj| _|ri|  |¡ d S d S )	NÚmodeÚsizeÚPÚRGBÚwidthÚheight)r   ÚLr(   ÚRGBAr   )r   Úhasattrr%   Úapply_transparencyÚloadÚpaletteÚAttributeErrorr&   r   ÚgetmodebaseÚ_PhotoImage__modeÚ_PhotoImage__sizer   r$   Ú_PhotoImage__photor   Úpaste)ÚselfÚimager&   r   r%   r   r   r   Ú__init__c   s2   ÿ

ÿzPhotoImage.__init__r   ÚNonec                 C  ó>   | j j}d | j _z| j j dd|¡ W d S  ty   Y d S w ©Nr8   Údelete)r5   Únamer   r   Ú	Exception©r7   r>   r   r   r   Ú__del__ƒ   ó   ÿzPhotoImage.__del__Ústrc                 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).
        )rC   r5   ©r7   r   r   r   Ú__str__‹   ó   
zPhotoImage.__str__r   c                 C  ó
   | j d S ©zU
        Get the width of the image.

        :return: The width, in pixels.
        r   ©r4   rE   r   r   r   r)   •   ó   
zPhotoImage.widthc                 C  rH   ©zW
        Get the height of the image.

        :return: The height, in pixels.
        r   rJ   rE   r   r   r   r*   �   rK   zPhotoImage.heightr   úImage.Imagec                 C  sX   |  ¡  |j}| ¡ r|j| jkr|}n| | j|j¡}| ||¡ td| j	|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)r/   r   Úisblockr%   r3   Ú	new_blockr&   Úconvert2r#   r5   r   )r7   r   r8   Úblockr   r   r   r6   ¥   s   
zPhotoImage.paste)NN©r   r:   ©r   rC   ©r   r   )r   rM   r   r:   )
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r9   rA   rF   r)   r*   r6   r   r   r   r   r$   O   s    

 



r$   c                   @  sB   e Zd ZdZddd„Zddd„Zdd
d„Zddd„Zddd„ZdS )r   aä  
    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.
    Nc                 K  sj   |d u rt |ƒ}|j| _|j| _tƒ r$| ¡  d|jj› �|d< || _	n| 
¡ |d< tjdi |¤Ž| _d S )Nr	   r
   r   )r   r%   Ú_BitmapImage__moder&   Ú_BitmapImage__sizer   r/   r   r   Ú_BitmapImage__imÚtobitmapr   r   Ú_BitmapImage__photo)r7   r8   r   r   r   r   r9   Ì   s   zBitmapImage.__init__r   r:   c                 C  r;   r<   )r^   r>   r   r   r?   r@   r   r   r   rA   Þ   rB   zBitmapImage.__del__r   c                 C  rH   rI   ©r[   rE   r   r   r   r)   æ   rK   zBitmapImage.widthc                 C  rH   rL   r_   rE   r   r   r   r*   î   rK   zBitmapImage.heightrC   c                 C  rD   )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).
        )rC   r^   rE   r   r   r   rF   ö   rG   zBitmapImage.__str__)NrS   rU   rT   )	rV   rW   rX   rY   r9   rA   r)   r*   rF   r   r   r   r   r   ¾   s    



r   r"   rM   c                 C  s0   t  d|  ¡ |  ¡ f¡}|j}td| |jƒ |S )z:Copies the contents of a PhotoImage to a PIL image memory.r,   ÚPyImagingPhotoGet)r   r   r)   r*   r   r#   r   )r"   r   rR   r   r   r   Úgetimage  s   ra   c                 C  sL   G dd„ dt jƒ}t jsd}t|ƒ‚t  ¡ }|r| |¡ ||| ƒ ¡  dS )z!Helper for the Image.show method.c                      s   e Zd Z‡ fdd„Z‡  ZS )z_show.<locals>.UIc                   sD   |j dkrt|d|d�| _nt||d�| _tƒ j|| jddd� d S )Nr   Úwhite)Ú
foregroundÚmaster)rd   Úblackr   )r8   ÚbgÚbd)r%   r   r8   r$   Úsuperr9   )r7   rd   r   ©Ú	__class__r   r   r9     s   
z_show.<locals>.UI.__init__)rV   rW   rX   r9   Ú__classcell__r   r   ri   r   ÚUI  s    rl   ztkinter not initializedN)r   ÚLabelÚ_default_rootÚOSErrorÚToplevelÚtitleÚpack)r8   rq   rl   ÚmsgÚtopr   r   r   Ú_show  s   
ru   rU   )r"   r$   r   rM   )Ú
__future__r   r   Úior   r   r   r   r   r   r#   r$   r   ra   ru   r   r   r   r   Ú<module>   s   

o
C
