ó
O'—^c           @   s³   y d  d l  Z  Wn& e k
 r8 d  d l Z e Z  [ n Xd  d l m Z d  d l m Z d a d „  Z	 d „  Z
 d e f d „  ƒ  YZ d e f d	 „  ƒ  YZ d
 „  Z d „  Z d S(   iÿÿÿÿN(   t   Image(   t   BytesIOc          C   sf   t  d  k rb y6 t j d d ƒ }  t j d d |  j j ƒ d a  Wqb t j k
 r^ d a  qb Xn  t  S(   Nt   1i   t   datas   PIL:%di    (   i   i   (	   t   _pilbitmap_okt   NoneR    t   newt   tkintert   BitmapImaget   imt   idt   TclError(   R	   (    (    s-   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageTk.pyt   _pilbitmap_check-   s    
c         C   s_   d  } d |  k r$ |  j d ƒ } n$ d |  k rH t |  j d ƒ ƒ } n  | r[ t j | ƒ Sd  S(   Nt   fileR   (   R   t   popR   R    t   open(   t   kwt   source(    (    s-   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageTk.pyt   _get_image_from_kw9   s    t
   PhotoImagec           B   sM   e  Z d  Z d d d „ Z d „  Z d „  Z d „  Z d „  Z d d „ Z	 RS(   s3  
    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).
    c         K   s  | d  k r t | ƒ } n  t | d ƒ r¥ t | d ƒ r¥ | j } | d k r… | j ƒ  y | j j } Wq… t k
 r d } q… Xn  | j } | \ | d <| d <n | } d  } | d
 k rÏ t j	 | ƒ } n  | |  _
 | |  _ t j |   |  _ |  j j |  _ | r|  j | ƒ n  d  S(   Nt   modet   sizet   Pt   RGBt   widtht   heightR   t   Lt   RGBA(   R   R   R   R   (   R   R   t   hasattrR   t   loadt   palettet   AttributeErrorR   R    t   getmodebaset   _PhotoImage__modet   _PhotoImage__sizeR   R   t   _PhotoImage__photot   tkt   paste(   t   selft   imageR   R   R   (    (    s-   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageTk.pyt   __init__Z   s,    	
			c         C   sC   |  j  j } d  |  j  _ y |  j  j j d d | ƒ Wn n Xd  S(   NR'   t   delete(   R#   t   nameR   R$   t   call(   R&   R*   (    (    s-   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageTk.pyt   __del__z   s    c         C   s   t  |  j ƒ S(   sô   
        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).
        (   t   strR#   (   R&   (    (    s-   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageTk.pyt   __str__‚   s    c         C   s   |  j  d S(   sU   
        Get the width of the image.

        :return: The width, in pixels.
        i    (   R"   (   R&   (    (    s-   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageTk.pyR   Œ   s    c         C   s   |  j  d S(   sW   
        Get the height of the image.

        :return: The height, in pixels.
        i   (   R"   (   R&   (    (    s-   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageTk.pyR   ”   s    c         C   s:  | j  ƒ  | j } | j ƒ  r: | j |  j k r: | } n( | j |  j | j ƒ } | j | | ƒ |  j j	 } y | j
 d |  j | j ƒ Wn¨ t j k
 r5yq d d l m } y | j | j ƒ  d ƒ Wn' t k
 rô | j t | ƒ d ƒ n X| j
 d |  j | j ƒ Wq6t t t j f k
 r1‚  q6Xn Xd S(   s  
        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.
        :param box: A 4-tuple defining the left, upper, right, and lower pixel
                    coordinate.  If None is given instead of a tuple, all of
                    the image is assumed.
        t   PyImagingPhotoiÿÿÿÿ(   t
   _imagingtki   i    N(   R   R	   t   isblockR   R!   t	   new_blockR   t   convert2R#   R$   R+   R
   R   R   t   PILR0   t   tkinitt
   interpaddrR   t   ImportError(   R&   R	   t   boxR'   t   blockR$   R0   (    (    s-   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageTk.pyR%   œ   s&    
		N(
   t   __name__t
   __module__t   __doc__R   R(   R,   R.   R   R   R%   (    (    (    s-   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageTk.pyR   F   s    		
		R   c           B   s>   e  Z d  Z d d „ Z d „  Z d „  Z d „  Z d „  Z RS(   sä  
    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.
    c         K   sŒ   | d  k r t | ƒ } n  | j |  _ | j |  _ t ƒ  rf | j ƒ  d | j j	 | d <| |  _
 n | j ƒ  | d <t j |   |  _ d  S(   Ns   PIL:%dR   (   R   R   R   t   _BitmapImage__modeR   t   _BitmapImage__sizeR   R   R	   R
   t   _BitmapImage__imt   tobitmapR   R   t   _BitmapImage__photo(   R&   R'   R   (    (    s-   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageTk.pyR(   Ô   s    	
c         C   sC   |  j  j } d  |  j  _ y |  j  j j d d | ƒ Wn n Xd  S(   NR'   R)   (   RA   R*   R   R$   R+   (   R&   R*   (    (    s-   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageTk.pyR,   ç   s    c         C   s   |  j  d S(   sU   
        Get the width of the image.

        :return: The width, in pixels.
        i    (   R>   (   R&   (    (    s-   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageTk.pyR   ï   s    c         C   s   |  j  d S(   sW   
        Get the height of the image.

        :return: The height, in pixels.
        i   (   R>   (   R&   (    (    s-   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageTk.pyR   ÷   s    c         C   s   t  |  j ƒ S(   s÷   
        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-   RA   (   R&   (    (    s-   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageTk.pyR.   ÿ   s    N(	   R:   R;   R<   R   R(   R,   R   R   R.   (    (    (    s-   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageTk.pyR   Æ   s   			c         C   s   |  j  j d |  ƒ d S(   s:   Copies the contents of a PhotoImage to a PIL image memory.t   PyImagingPhotoGetN(   R$   R+   (   t   photo(    (    s-   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageTk.pyt   getimage
  s    c         C   sj   d t  j f d „  ƒ  Y} t  j s1 t d ƒ ‚ n  t  j ƒ  } | rS | j | ƒ n  | | |  ƒ j ƒ  d S(   s!   Helper for the Image.show method.t   UIc           B   s   e  Z d  „  Z RS(   c      	   S   sn   | j  d k r- t | d d d | ƒ|  _ n t | d | ƒ|  _ t j j |  | d |  j d d d d	 ƒd  S(
   NR   t
   foregroundt   whitet   masterR'   t   bgt   blackt   bdi    (   R   R   R'   R   R   t   LabelR(   (   R&   RH   R	   (    (    s-   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageTk.pyR(     s
    (   R:   R;   R(   (    (    (    s-   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageTk.pyRE     s   s   tkinter not initializedN(   R   RL   t   _default_roott   IOErrort   Toplevelt   titlet   pack(   R'   RP   RE   t   top(    (    s-   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageTk.pyt   _show  s    		(   R   R7   t   TkinterR4   R    t   ioR   R   R   R   R   t   objectR   R   RD   RS   (    (    (    s-   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageTk.pyt   <module>   s   		€D	