î
úÙ X†"  ã               @   sÀ   y d  d l  Z  Wn' e k
 r9 d  d l Z e Z  [ Yn Xd  d l m Z d  d l m Z d a d d „  Z d d „  Z	 Gd d	 „  d	 e
 ƒ Z Gd
 d „  d e
 ƒ Z d d „  Z d d „  Z d S)é    N)ÚImage)ÚBytesIOc              C   sg   t  d  k rc y6 t j d d ƒ }  t j d d |  j j ƒ d a  Wqc t j k
 r_ d a  Yqc Xn  t  S)NÚ1é   ÚdatazPIL:%dr   )r   r   )Ú_pilbitmap_okr   ÚnewÚtkinterÚBitmapImageÚimÚidÚTclError)r   © r   úH/home/ubuntu/projects/ifolica/lib/python3.4/site-packages/PIL/ImageTk.pyÚ_pilbitmap_check-   s    
r   c             C   s_   d  } d |  k r$ |  j  d ƒ } n$ d |  k rH t |  j  d ƒ ƒ } n  | r[ t j | ƒ Sd  S)NÚfiler   )Úpopr   r   Úopen)ÚkwÚsourcer   r   r   Ú_get_image_from_kw9   s    r   c               @   sg   e  Z d  Z d Z d d d d „ Z d d „  Z d d „  Z d	 d
 „  Z d d „  Z d 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             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 } Yq† Xn  | j } | \ | d <| d <n | } d  } | d
 k rÐ t j | ƒ } n  | |  _	 | |  _
 t j |   |  _ |  j j |  _ | r|  j | ƒ n  d  S)NÚmodeÚsizeÚPÚRGBÚwidthÚheightr   ÚLÚRGBA)r   r   r   r   )r   Úhasattrr   ÚloadZpaletteÚAttributeErrorr   r   ZgetmodebaseÚ_PhotoImage__modeÚ_PhotoImage__sizer	   r   Ú_PhotoImage__photoÚtkÚpaste)ÚselfÚimager   r   r   r   r   r   Ú__init__Z   s,    	
			zPhotoImage.__init__c          
   C   sD   |  j  j } d  |  j  _ y |  j  j j d d | ƒ Wn Yn Xd  S)Nr)   Údelete)r%   Únamer&   Úcall)r(   r,   r   r   r   Ú__del__z   s    zPhotoImage.__del__c             C   s   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(   r   r   r   Ú__str__‚   s    zPhotoImage.__str__c             C   s   |  j  d S)zU
        Get the width of the image.

        :return: The width, in pixels.
        r   )r$   )r(   r   r   r   r   Œ   s    zPhotoImage.widthc             C   s   |  j  d S)zW
        Get the height of the image.

        :return: The height, in pixels.
        r   )r$   )r(   r   r   r   r   ”   s    zPhotoImage.heightc             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
 r8yr d d l m } y | j | j ƒ  d ƒ Wn( t k
 rõ | j t | ƒ d ƒ Yn X| j
 d |  j | j ƒ Wn! t t t j f k
 r3‚  Yn XYn Xd S)a  
        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.
        ZPyImagingPhotor   )Ú
_imagingtkr   N)r!   r   Zisblockr   r#   Z	new_blockr   Zconvert2r%   r&   r-   r   r	   r   ÚPILr1   ZtkinitZ
interpaddrr"   ÚImportError)r(   r   Zboxr)   Úblockr&   r1   r   r   r   r'   œ   s&    
		zPhotoImage.paste)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r*   r.   r0   r   r   r'   r   r   r   r   r   F   s    
r   c               @   sU   e  Z d  Z d Z d 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             K   sŒ   | d  k r t  | ƒ } n  | j |  _ | j |  _ t ƒ  rf | j ƒ  d | j j | d <| |  _	 n | j
 ƒ  | d <t j |   |  _ d  S)NzPIL:%dr   )r   r   Z_BitmapImage__moder   Ú_BitmapImage__sizer   r!   r   r   Z_BitmapImage__imZtobitmapr	   r
   Ú_BitmapImage__photo)r(   r)   r   r   r   r   r*   Ô   s    	
zBitmapImage.__init__c          
   C   sD   |  j  j } d  |  j  _ y |  j  j j d d | ƒ Wn Yn Xd  S)Nr)   r+   )r:   r,   r&   r-   )r(   r,   r   r   r   r.   ç   s    zBitmapImage.__del__c             C   s   |  j  d S)zU
        Get the width of the image.

        :return: The width, in pixels.
        r   )r9   )r(   r   r   r   r   ï   s    zBitmapImage.widthc             C   s   |  j  d S)zW
        Get the height of the image.

        :return: The height, in pixels.
        r   )r9   )r(   r   r   r   r   ÷   s    zBitmapImage.heightc             C   s   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/   r:   )r(   r   r   r   r0   ÿ   s    zBitmapImage.__str__)	r5   r6   r7   r8   r*   r.   r   r   r0   r   r   r   r   r
   Æ   s   r
   c             C   s   |  j  j d |  ƒ d S)z:Copies the contents of a PhotoImage to a PIL image memory.ZPyImagingPhotoGetN)r&   r-   )Zphotor   r   r   Úgetimage
  s    r;   c             C   sj   Gd d „  d t  j ƒ } t  j s1 t d ƒ ‚ n  t  j ƒ  } | rS | j | ƒ n  | | |  ƒ j ƒ  d S)z!Helper for the Image.show method.c               @   s   e  Z d  Z d d „  Z d S)z_show.<locals>.UIc          	   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   Z
foregroundZwhiteÚmasterr)   ÚbgZblackZbdr   )r   r
   r)   r   r	   ÚLabelr*   )r(   r<   r   r   r   r   r*     s
    z_show.<locals>.UI.__init__N)r5   r6   r7   r*   r   r   r   r   ÚUI  s   r?   ztkinter not initializedN)r	   r>   Z_default_rootÚIOErrorZToplevelÚtitleÚpack)r)   rA   r?   Útopr   r   r   Ú_show  s    		rD   )r	   r3   ÚTkinterr2   r   Úior   r   r   r   Úobjectr   r
   r;   rD   r   r   r   r   Ú<module>   s   €D