
    ZMh                        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ZddZ G d d          Z G d d          ZddZdS )    )annotationsN)BytesIO)Any   )Image	ImageFileF)CapsuleTypekwdict[str, Any]returnImageFile.ImageFile | Nonec                    d }d| v r|                      d          }n&d| v r"t          |                      d                    }|sd S t          j        |          S )Nfiledata)popr   r   open)r
   sources     K/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/PIL/ImageTk.py_get_image_from_kwr   +   s^    F||	2(( t:f    commandstrphotoPhotoImage | tkinter.PhotoImageptrr	   Nonec                ,   |j         }	 |                    | |t          |                     d S # t          j        $ rU ddlm} |                    |                                           |                    | |t          |                     Y d S w xY w)Nr   )
_imagingtk)	tkcallreprtkinterTclError r   tkinit
interpaddr)r   r   r   r   r   s        r   _pyimagingtkcallr'   6   s     
B+
S		***** + + + 	!     "--//***
S		******+s   $/ A BBc                  H    e Zd ZdZ	 	 dddZddZddZddZddZ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                ,   |t          |          }|d}t          |          t          |t                    r|}d }|d}t          |          n\|j        }|dk    r=|                                 |                                 |j        r|j        j        nd}|j        }|\  |d<   |d<   |dvrt          j
        |          }|| _        || _        t          j        di || _        | j        j        | _        |r|                     |           d S d S )	NImage is requiredz+If first argument is mode, size is requiredPRGBwidthheight)1Lr1   RGBA )r   
ValueError
isinstancer   modeapply_transparencyloadpaletter,   r   getmodebase_PhotoImage__mode_PhotoImage__sizer"   r)   _PhotoImage__photor   paste)selfr*   r,   r
   msgr:   s         r   __init__zPhotoImage.__init__]   s:    =&r**E=%CS//!s## 	-DE|C oo% 
 :Ds{{((***

-2]Eu})):D(,%BwKH000$T**D)//B//,/ 	JJu	 	r   c                    	 | j         j        }n# t          $ r Y d S w xY wd | j         _        	 | j         j                            dd|           d S # t
          $ r Y d S w xY wNr*   delete)rA   nameAttributeErrorr   r    	ExceptionrC   rI   s     r   __del__zPhotoImage.__del__       	<$DD 	 	 	FF	 	LO  (D99999 	 	 	DD	    
!A 
AAr   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   rA   rC   s    r   __str__zPhotoImage.__str__        4<   r   intc                    | j         d         S zU
        Get the width of the image.

        :return: The width, in pixels.
        r   r@   rQ   s    r   r2   zPhotoImage.width        {1~r   c                    | j         d         S zW
        Get the height of the image.

        :return: The height, in pixels.
        r   rW   rQ   s    r   r3   zPhotoImage.height   rX   r   imImage.Imagec                >   |                                 }|j        }|                                r|j        | j        k    rGt
          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)getimr[   isblockr:   r?   r   core	new_blockr,   convert2r   r'   rA   )rC   r[   r   r*   blocks        r   rB   zPhotoImage.paste   s     hhjj}} 	"'T["8"8J((bg>>ENN5%((()C)4<=====r   )NN)r*   r+   r,   r-   r
   r   r   r   r   r   r   r   r   rT   )r[   r\   r   r   )
__name__
__module____qualname____doc__rE   rM   rR   r2   r3   rB   r7   r   r   r)   r)   I   s         * +/'+' ' ' ' 'R	 	 	 	! ! ! !      > > > > > >r   r)   c                  <    e Zd ZdZddd	Zdd
ZddZddZ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                    |t          |          }|d}t          |          |j        | _        |j        | _        t          j        dd|                                i|| _	        d S )Nr/   r   r7   )
r   r8   r:   _BitmapImage__moder,   _BitmapImage__sizer"   rm   tobitmap_BitmapImage__photo)rC   r*   r
   rD   s       r   rE   zBitmapImage.__init__   sg    =&r**E=%CS//!jj*GG0@0@GBGGr   c                    	 | j         j        }n# t          $ r Y d S w xY wd | j         _        	 | j         j                            dd|           d S # t
          $ r Y d S w xY wrG   )rs   rI   rJ   r   r    rK   rL   s     r   rM   zBitmapImage.__del__   rN   rO   rT   c                    | j         d         S rV   rq   rQ   s    r   r2   zBitmapImage.width   rX   r   c                    | j         d         S rZ   rv   rQ   s    r   r3   zBitmapImage.height   rX   r   r   c                *    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   rs   rQ   s    r   rR   zBitmapImage.__str__   rS   r   )N)r*   rn   r
   r   r   r   re   rg   rf   )	rh   ri   rj   rk   rE   rM   r2   r3   rR   r7   r   r   rm   rm      s         H H H H H	 	 	 	      ! ! ! ! ! !r   rm   r\   c                    t          j        d|                                 |                                 f          }t	          d| |                                           |S )z:Copies the contents of a PhotoImage to a PIL image memory.r6   PyImagingPhotoGet)r   newr2   r3   r'   r_   )r   r[   s     r   getimager|     sH    	6EKKMM5<<>>:	;	;B(%<<<Ir   )r
   r   r   r   )r   r   r   r   r   r	   r   r   )r   r)   r   r\   )
__future__r   r"   ior   typingr   r$   r   r   TYPE_CHECKING_typingr	   r   r'   r)   rm   r|   r7   r   r   <module>r      s  6 # " " " " "                      %$$$$$$   + + + +&s> s> s> s> s> s> s> s>t>! >! >! >! >! >! >! >!B     r   