o
    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
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S )"    )annotationsN)BytesIO)Any   )Image	ImageFileF)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   M/var/www/html/optinet_system/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   _pyimagingtkcall6   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	   msgr4   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=   rC   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:   rJ   r   r   r   r-         
zPhotoImage.widthc                 C  rN   zW
        Get the height of the image.

        :return: The height, in pixels.
        r   rP   rJ   r   r   r   r.      rQ   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)getimrS   isblockr4   r9   r   core	new_blockr(   convert2r   r$   r;   )r=   rS   r   r&   blockr   r   r   r<      s   
zPhotoImage.paste)NN)r&   r'   r(   r)   r	   r   r   r   r   r   r   r   r   rM   )rS   rT   r   r   )
__name__
__module____qualname____doc__r?   rG   rK   r-   r.   r<   r   r   r   r   r%   I   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   r2   r4   _BitmapImage__moder(   _BitmapImage__sizer   rc   tobitmap_BitmapImage__photo)r=   r&   r	   r>   r   r   r   r?      s   zBitmapImage.__init__c                 C  r@   rA   )rh   rC   rD   r   r   rE   rF   r   r   r   rG      rH   zBitmapImage.__del__rM   c                 C  rN   rO   rf   rJ   r   r   r   r-      rQ   zBitmapImage.widthc                 C  rN   rR   ri   rJ   r   r   r   r.      rQ   zBitmapImage.heightr   c                 C  rI   )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   rh   rJ   r   r   r   rK      rL   zBitmapImage.__str__)N)r&   rd   r	   r   r   r   r\   r^   r]   )	r_   r`   ra   rb   r?   rG   r-   r.   rK   r   r   r   r   rc      s    


rc   rT   c                 C  s,   t d|  |  f}td| |  |S )z:Copies the contents of a PhotoImage to a PIL image memory.r1   PyImagingPhotoGet)r   newr-   r.   r$   rV   )r   rS   r   r   r   getimage  s   rl   )r	   r
   r   r   )r   r   r   r   r   r   r   r   )r   r%   r   rT   )
__future__r   r   ior   typingr   r!   r   r   TYPE_CHECKING_typingr   r   r$   r%   rc   rl   r   r   r   r   <module>   s   

zA