ó
È4ec           @   s³   d  d l  Z  d  d l m Z d d l m Z e  j j d k rM d  d l Z n d  d l 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   BytesIOi   (   t   Imagei   c          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	   (    (    s5   /usr/local/lib/python2.7/dist-packages/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(    (    s5   /usr/local/lib/python2.7/dist-packages/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   (    (    s5   /usr/local/lib/python2.7/dist-packages/PIL/ImageTk.pyt   __init__[   s,    	
			c         C   sM   |  j  j } d  |  j  _ y |  j  j j d d | ƒ Wn t k
 rH n Xd  S(   NR'   t   delete(   R#   t   nameR   R$   t   callt	   Exception(   R&   R*   (    (    s5   /usr/local/lib/python2.7/dist-packages/PIL/ImageTk.pyt   __del__{   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&   (    (    s5   /usr/local/lib/python2.7/dist-packages/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&   (    (    s5   /usr/local/lib/python2.7/dist-packages/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&   (    (    s5   /usr/local/lib/python2.7/dist-packages/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
 r…yÁ d d l m } yj t | d ƒ rd d l m } | ƒ  } | j t | j d | j ƒ ƒ d ƒ n | j | j ƒ  d ƒ Wn' t k
 rD| j t | ƒ d ƒ n X| j
 d |  j | j ƒ Wq†t t t j f k
 r‚  q†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. See :ref:`coordinate-system`. If None is given
                    instead of a tuple, all of the image is assumed.
        t   PyImagingPhotoi   (   t
   _imagingtkt   interpiÿÿÿÿ(   t   FFIt	   uintptr_ti    N(   R   R	   t   isblockR   R!   t	   new_blockR   t   convert2R#   R$   R+   R
   R   R   t    R1   R   t   cffiR3   t   tkinitt   intt   castR2   t
   interpaddrR   t   ImportError(	   R&   R	   t   boxR'   t   blockR$   R1   R3   t   ffi(    (    s5   /usr/local/lib/python2.7/dist-packages/PIL/ImageTk.pyR%      s.    
			(N(
   t   __name__t
   __module__t   __doc__R   R(   R-   R/   R   R   R%   (    (    (    s5   /usr/local/lib/python2.7/dist-packages/PIL/ImageTk.pyR   G   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   (    (    s5   /usr/local/lib/python2.7/dist-packages/PIL/ImageTk.pyR(   â   s    	
c         C   sM   |  j  j } d  |  j  _ y |  j  j j d d | ƒ Wn t k
 rH n Xd  S(   NR'   R)   (   RI   R*   R   R$   R+   R,   (   R&   R*   (    (    s5   /usr/local/lib/python2.7/dist-packages/PIL/ImageTk.pyR-   õ   s    c         C   s   |  j  d S(   sU   
        Get the width of the image.

        :return: The width, in pixels.
        i    (   RF   (   R&   (    (    s5   /usr/local/lib/python2.7/dist-packages/PIL/ImageTk.pyR   ý   s    c         C   s   |  j  d S(   sW   
        Get the height of the image.

        :return: The height, in pixels.
        i   (   RF   (   R&   (    (    s5   /usr/local/lib/python2.7/dist-packages/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.   RI   (   R&   (    (    s5   /usr/local/lib/python2.7/dist-packages/PIL/ImageTk.pyR/     s    N(	   RB   RC   RD   R   R(   R-   R   R   R/   (    (    (    s5   /usr/local/lib/python2.7/dist-packages/PIL/ImageTk.pyR   Ô   s   			c         C   sJ   t  j d |  j ƒ  |  j ƒ  f ƒ } | j } |  j j d |  | j ƒ | S(   s:   Copies the contents of a PhotoImage to a PIL image memory.R   t   PyImagingPhotoGet(   R   R   R   R   R	   R$   R+   R
   (   t   photoR	   R@   (    (    s5   /usr/local/lib/python2.7/dist-packages/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&   RP   R	   (    (    s5   /usr/local/lib/python2.7/dist-packages/PIL/ImageTk.pyR(   &  s    (   RB   RC   R(   (    (    (    s5   /usr/local/lib/python2.7/dist-packages/PIL/ImageTk.pyRM   %  s   s   tkinter not initializedN(   R   RT   t   _default_roott   IOErrort   Toplevelt   titlet   pack(   R'   RX   RM   t   top(    (    s5   /usr/local/lib/python2.7/dist-packages/PIL/ImageTk.pyt   _show"  s    	(   t   syst   ioR    R8   R   t   version_infot   majorR   t   TkinterR   R   R   R   t   objectR   R   RL   R[   (    (    (    s5   /usr/local/lib/python2.7/dist-packages/PIL/ImageTk.pyt   <module>   s   		D	
