
    zvg%#                        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rddlmZ ddZd dZ G d d          Z G d d          Zd!dZd"dZdS )#    )annotationsN)BytesIO)TYPE_CHECKINGAnycast   )Image	ImageFile)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     H/var/www/pixelcanvas.ch/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)   5   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Lr3   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)rC   nameAttributeErrorr!   r"   	ExceptionrE   rK   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   rC   rE   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   rB   rS   s    r   r4   zPhotoImage.width        {1~r   c                    | j         d         S zW
        Get the height of the image.

        :return: The height, in pixels.
        r   rY   rS   s    r   r5   zPhotoImage.height   rZ   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<   rA   r	   core	new_blockr.   convert2r   r)   rC   )rE   r]   r   r,   blocks        r   rD   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   rV   )r]   r^   r   r   )
__name__
__module____qualname____doc__rG   rO   rT   r4   r5   rD   r9   r   r   r+   r+   H   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 )Nr1   r   r9   )
r   r:   r<   _BitmapImage__moder.   _BitmapImage__sizer$   ro   tobitmap_BitmapImage__photo)rE   r,   r   rF   s       r   rG   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rI   )ru   rK   rL   r!   r"   rM   rN   s     r   rO   zBitmapImage.__del__   rP   rQ   rV   c                    | j         d         S rX   rs   rS   s    r   r4   zBitmapImage.width   rZ   r   c                    | j         d         S r\   rx   rS   s    r   r5   zBitmapImage.height   rZ   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   ru   rS   s    r   rT   zBitmapImage.__str__   rU   r   )N)r,   rp   r   r   r   r   rg   ri   rh   )	rj   rk   rl   rm   rG   rO   r4   r5   rT   r9   r   r   ro   ro      s         H H H H H	 	 	 	      ! ! ! ! ! !r   ro   r^   c                    t          j        d|                                 |                                 f          }t	          d| |                                           |S )z:Copies the contents of a PhotoImage to a PIL image memory.r8   PyImagingPhotoGet)r	   newr4   r5   r)   ra   )r   r]   s     r   getimager~     sH    	6EKKMM5<<>>:	;	;B(%<<<Ir   r,   title
str | Nonec                    G d dt           j                  }t          t           d          sd}t          |          t          j                    }|r|                    |            |||                                            dS )z!Helper for the Image.show method.c                        e Zd Zd fdZ xZS )	_show.<locals>.UImastertkinter.Toplevelr]   r^   r   r   c                $   |  |j         dk    rt          |d|          | _        nt          ||          | _        t          r t          t          j        | j                  }n| j        }t                      	                    ||dd           d S )Nr6   white)
foregroundr   )r   blackr   )r,   bgbd)
r<   ro   r,   r+   r   r   r$   _ImagesuperrG   )rE   r   r]   r,   	__class__s       r   rG   z_show.<locals>.UI.__init__  s    0w#~~(OOO

'6:::
 #W^TZ88
GGV5WCCCCCr   )r   r   r]   r^   r   r   )rj   rk   rl   rG   __classcell__)r   s   @r   UIr     sG        
	D 
	D 
	D 
	D 
	D 
	D 
	D 
	D 
	D 
	Dr   r   _default_rootztkinter not initializedN)r$   LabelgetattrOSErrorToplevelr   pack)r,   r   r   rF   tops        r   _showr     s    D D D D DW] D D D 7O,, 'cll



C 		%BsENNr   )r   r   r   r   )r   r   r   r   r   r   r   r   )r   r+   r   r^   )r,   r^   r   r   r   r   )
__future__r   r$   ior   typingr   r   r   r&   r	   r
   _typingr   r   r)   r+   ro   r~   r   r9   r   r   <module>r      s8  6 # " " " " "        + + + + + + + + + +         %$$$$$$   + + + +&s> s> s> s> s> s> s> s>t>! >! >! >! >! >! >! >!B        r   