
     f!                        d dl mZ d dlZd dlmZ ddlmZ daddZd	 Z	d
 Z
 G d d          Z G d d          ZddZd ZdS )    )annotationsN)BytesIO   )Imagereturnintc                     t           R	 t          j        dd          } t          j        d| j        j                    da n# t          j        $ r da Y nw xY wt           S )N1)r   r   PIL:)datar   r   )_pilbitmap_okr   newtkinterBitmapImageimidTclError)r   s    N/var/www/api.educacionweb.es/myenv/lib/python3.11/site-packages/PIL/ImageTk.py_pilbitmap_checkr   (   ss    	3''B%6BEH%6%67777MM 	 	 	MMM	s   9A AAc                    d }d| v r|                      d          }n&d| v r"t          |                      d                    }|rt          j        |          S d S )Nfiler   )popr   r   open)kwsources     r   _get_image_from_kwr   4   sc    F||	2(( "z&!!!" "    c                    |j         }	 |                    | ||           d S # t          j        $ rH ddlm} |                    |                                           |                    | ||           Y d S w xY w)Nr   )
_imagingtk)tkcallr   r    r   tkinit
interpaddr)commandphotor   r    r   s        r   _pyimagingtkcallr'   >   s    	B$
##### $ $ $ 	!     "--//***
######$s   " AA98A9c                  B    e Zd ZdZ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).
    Nc                   |t          |          }t          |d          rxt          |d          rh|j        }|dk    rH|                                 |                                 	 |j        j        }n# t          $ r d}Y nw xY w|j        }|\  |d<   |d<   n|}d }|dvrt          j	        |          }|| _
        || _        t          j        di || _        | j        j        | _        |r|                     |           d S d S )	NmodesizePRGBwidthheight)r
   Lr.   RGBA )r   hasattrr+   apply_transparencyloadpaletteAttributeErrorr,   r   getmodebase_PhotoImage__mode_PhotoImage__sizer   r)   _PhotoImage__photor    paste)selfimager,   r   r+   s        r   __init__zPhotoImage.__init__c   s7   =&r**E5&!! 	geV&<&< 	:Ds{{((***

! =-DD% ! ! ! DDD!:D(,%BwKHDE000$T**D)//B//,/ 	JJu	 	s   (A5 5BBr   Nonec                    | j         j        }d | j         _        	 | j         j                            dd|           d S # t          $ r Y d S w xY wNr?   delete)r<   namer    r!   	Exceptionr>   rE   s     r   __del__zPhotoImage.__del__   _    |  	LO  (D99999 	 	 	DD	   != 
A
Astrc                *    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).
        )rK   r<   r>   s    r   __str__zPhotoImage.__str__        4<   r   r   c                    | j         d         S zU
        Get the width of the image.

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

        :return: The height, in pixels.
        r   rR   rM   s    r   r0   zPhotoImage.height   rS   r   r   Image.Imagec                ,   |                                  |j        }|                                r|j        | j        k    r|}n6|                    | 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)r6   r   isblockr+   r:   	new_blockr,   convert2r'   r<   r   )r>   r   r?   blocks       r   r=   zPhotoImage.paste   s     				==?? 	)rw$+55EEOODK99ENN5%((()4<BBBBBr   )NNr   rA   r   rK   r   r   )r   rV   r   rA   )
__name__
__module____qualname____doc__r@   rH   rN   r/   r0   r=   r3   r   r   r)   r)   O   s         &   @   ! ! ! !      C C C C C Cr   r)   c                  :    e Zd ZdZddZddZddZdd	Z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                *   |t          |          }|j        | _        |j        | _        t                      r.|                                 d|j        j         |d<   || _	        n|
                                |d<   t          j        di || _        d S )Nr   r   r3   )r   r+   _BitmapImage__moder,   _BitmapImage__sizer   r6   r   r   _BitmapImage__imtobitmapr   r   _BitmapImage__photo)r>   r?   r   s      r   r@   zBitmapImage.__init__   s    =&r**Ejj 	*JJLLL---BvJDII ))BvJ*00R00r   r   rA   c                    | j         j        }d | j         _        	 | j         j                            dd|           d S # t          $ r Y d S w xY wrC   )rj   rE   r    r!   rF   rG   s     r   rH   zBitmapImage.__del__   rI   rJ   r   c                    | j         d         S rQ   rg   rM   s    r   r/   zBitmapImage.width   rS   r   c                    | j         d         S rU   rm   rM   s    r   r0   zBitmapImage.height   rS   r   rK   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).
        )rK   rj   rM   s    r   rN   zBitmapImage.__str__   rO   r   )Nr]   r_   r^   )	r`   ra   rb   rc   r@   rH   r/   r0   rN   r3   r   r   r   r      s         1 1 1 1$         ! ! ! ! ! !r   r   r&   rV   c                    t          j        d|                                 |                                 f          }|j        }t          d| |j                   |S )z:Copies the contents of a PhotoImage to a PIL image memory.r2   PyImagingPhotoGet)r   r   r/   r0   r   r'   r   )r&   r   r\   s      r   getimagerr     sI    	6EKKMM5<<>>:	;	;BEE(%:::Ir   c                     G d dt           j                  }t           j        sd}t          |          t          j                    }|r|                    |            |||                                            dS )z!Helper for the Image.show method.c                       e Zd Z fdZ xZS )_show.<locals>.UIc                    |j         dk    rt          |d|          | _        nt          ||          | _        t	                                          || j        dd           d S )Nr
   white)
foregroundmaster)ry   blackr   )r?   bgbd)r+   r   r?   r)   superr@   )r>   ry   r   	__class__s      r   r@   z_show.<locals>.UI.__init__  sc    w#~~(OOO

'6:::
GGV4:'aHHHHHr   )r`   ra   rb   r@   __classcell__)r~   s   @r   UIru     sA        	I 	I 	I 	I 	I 	I 	I 	I 	Ir   r   ztkinter not initializedN)r   Label_default_rootOSErrorTopleveltitlepack)r?   r   r   msgtops        r   _showr     s    I I I I IW] I I I   'cll



C 		%BsENNr   r_   )r&   r)   r   rV   )
__future__r   r   ior   r"   r   r   r   r   r'   r)   r   rr   r   r3   r   r   <module>r      s  6 # " " " " "             
 	 	 	 	" " "
$ 
$ 
$"hC hC hC hC hC hC hC hC^@! @! @! @! @! @! @! @!F       r   