
    e0!                    z    d dl mZ d dlZd dlmZ ddlmZ dad Zd Z	d Z
 G d	 d
      Z G d d      Zd Zd Zy)    )annotationsN)BytesIO   )Imagec                     t         L	 t        j                  dd      } t        j                  d| j
                  j                          da t         S t         S # t        j                  $ r
 da Y t         S w xY w)N1)r   r   PIL:)datar   r   )_pilbitmap_okr   newtkinterBitmapImageimidTclError)r   s    -/usr/lib/python3/dist-packages/PIL/ImageTk.py_pilbitmap_checkr   (   sn    	3'BtBEEHH:%67M =  	M	s   AA A65A6c                    d }d| v r| j                  d      }nd| v rt        | j                  d            }|rt        j                  |      S y )Nfiler
   )popr   r   open)kwsources     r   _get_image_from_kwr   4   sK    F|	2(zz&!!     c                    |j                   }	 |j                  | ||       y # t        j                  $ r; ddlm} |j                  |j                                |j                  | ||       Y y w xY w)Nr   )
_imagingtk)tkcallr   r    r   tkinit
interpaddr)commandphotor   r   r   s        r   _pyimagingtkcallr%   >   s^    	B$
# $ 	!"--/*
#$s   " AA0/A0c                  6    e Zd ZdZd	dZd Zd Zd Zd Zd Z	y)

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      rlt        |d      r`|j                  }|dk(  r7|j                          |j	                          	 |j
                  j                  }|j                  }|\  |d<   |d<   n|}d }|dvrt        j                  |      }|| _
        || _        t        j                  di || _        | j                  j                  | _        |r| j!                  |       y y # t        $ r d}Y w xY w)	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   s    =&r*E5&!geV&<::Ds{((*

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

        :return: The width, in pixels.
        r   r9   rJ   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   rO   rJ   s    r   r.   zPhotoImage.height   rP   r   c                F   |j                          |j                  }|j                         r|j                  | j                  k(  r|}n8|j                  | j                  |j                        }|j                  ||       t        d| j                  |j                         y)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)r4   r   isblockr)   r8   	new_blockr*   convert2r%   r:   r   )r<   r   r=   blocks       r   r;   zPhotoImage.paste   sn     		==?rww$++5EOODKK9ENN5%()4<<Br   )NN)
__name__
__module____qualname____doc__r>   rE   rK   r-   r.   r;   r1   r   r   r'   r'   O   s'    &@!Cr   r'   c                  0    e Zd ZdZddZd Zd Zd Zd Zy)	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                8   |t        |      }|j                  | _        |j                  | _        t               r4|j                          d|j                  j                   |d<   || _	        n|j                         |d<   t        j                  di || _        y )Nr	   r
   r1   )r   r)   _BitmapImage__moder*   _BitmapImage__sizer   r4   r   r   _BitmapImage__imtobitmapr   r   _BitmapImage__photo)r<   r=   r   s      r   r>   zBitmapImage.__init__   s|    =&r*EjjjjJJL}-BvJDI )BvJ**0R0r   c                    | j                   j                  }d | j                   _        	 | j                   j                  j                  dd|       y # t        $ r Y y w xY wr@   )rc   rB   r   r   rC   rD   s     r   rE   zBitmapImage.__del__   rF   rG   c                     | j                   d   S rN   r`   rJ   s    r   r-   zBitmapImage.width   rP   r   c                     | j                   d   S rR   rf   rJ   s    r   r.   zBitmapImage.height   rP   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).
        )rI   rc   rJ   s    r   rK   zBitmapImage.__str__   rL   r   )N)	rY   rZ   r[   r\   r>   rE   r-   r.   rK   r1   r   r   r   r      s     1$!r   r   c                    t        j                  d| j                         | j                         f      }|j                  }t        d| |j                         |S )z:Copies the contents of a PhotoImage to a PIL image memory.r0   PyImagingPhotoGet)r   r   r-   r.   r   r%   r   )r$   r   rX   s      r   getimagerk     sB    	6EKKM5<<>:	;BEEE(%:Ir   c                     G d dt         j                        }t         j                  sd}t        |      t        j                         }|r|j                  |        |||       j                          y)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       y )Nr   white)
foregroundmaster)rr   blackr   )r=   bgbd)r)   r   r=   r'   superr>   )r<   rr   r   	__class__s      r   r>   z_show.<locals>.UI.__init__  sF    ww#~(O
'6:
GV4::'aHr   )rY   rZ   r[   r>   __classcell__)rw   s   @r   UIrn     s    	I 	Ir   ry   ztkinter not initializedN)r   Label_default_rootOSErrorTopleveltitlepack)r=   r~   ry   msgtops        r   _showr     s]    IW]] I   'cl



C		%sENr   )
__future__r   r   ior   r    r   r   r   r   r%   r'   r   rk   r   r1   r   r   <module>r      sO   6 #   
 	"
$"hC hC^@! @!Fr   