
O'^c           @   s   d  d l  m Z d e f d     YZ d e f d     YZ d e f d     YZ d e f d	     YZ d
 e f d     YZ d S(   i(   t   Imaget   HDCc           B   s    e  Z d  Z d   Z d   Z RS(   s   
    Wraps an HDC integer. The resulting object can be passed to the
    :py:meth:`~PIL.ImageWin.Dib.draw` and :py:meth:`~PIL.ImageWin.Dib.expose`
    methods.
    c         C   s   | |  _  d  S(   N(   t   dc(   t   selfR   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageWin.pyt   __init__   s    c         C   s   |  j  S(   N(   R   (   R   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageWin.pyt   __int__    s    (   t   __name__t
   __module__t   __doc__R   R   (    (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageWin.pyR      s   	t   HWNDc           B   s    e  Z d  Z d   Z d   Z RS(   s   
    Wraps an HWND integer. The resulting object can be passed to the
    :py:meth:`~PIL.ImageWin.Dib.draw` and :py:meth:`~PIL.ImageWin.Dib.expose`
    methods, instead of a DC.
    c         C   s   | |  _  d  S(   N(   t   wnd(   R   R
   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageWin.pyR   *   s    c         C   s   |  j  S(   N(   R
   (   R   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageWin.pyR   -   s    (   R   R   R   R   R   (    (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageWin.pyR	   $   s   	t   Dibc           B   sh   e  Z d  Z d
 d  Z d   Z d
 d  Z d   Z d
 d  Z d   Z	 d   Z
 d   Z d	   Z RS(   s&  
    A Windows bitmap with the given mode and size.  The mode can be one of "1",
    "L", "P", or "RGB".

    If the display requires a palette, this constructor creates a suitable
    palette and associates it with the image. For an "L" image, 128 greylevels
    are allocated. For an "RGB" image, a 6x6x6 colour cube is used, together
    with 20 greylevels.

    To make sure that palettes work properly under Windows, you must call the
    **palette** method upon certain events from Windows.

    :param image: Either a PIL image, or a mode string. If a mode string is
                  used, a size must also be given.  The mode can be one of "1",
                  "L", "P", or "RGB".
    :param size: If the first argument is a mode string, this
                 defines the size of the image.
    c         C   s   t  | d  r3 t  | d  r3 | j } | j } n | } d  } | d k r] t j |  } n  t j j | |  |  _ | |  _ | |  _ | r |  j	 |  n  d  S(   Nt   modet   sizet   1t   Lt   Pt   RGB(   R   R   R   R   (
   t   hasattrR   R   t   NoneR    t   getmodebaset   coret   displayt   imaget   paste(   R   R   R   R   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageWin.pyR   E   s    			c         C   sg   t  | t  rQ |  j j |  } z |  j j |  } Wd |  j j | |  Xn |  j j |  } | S(   s)  
        Copy the bitmap contents to a device context.

        :param handle: Device context (HDC), cast to a Python integer, or an
                       HDC or HWND instance.  In PythonWin, you can use the
                       :py:meth:`CDC.GetHandleAttrib` to get a suitable handle.
        N(   t
   isinstanceR	   R   t   getdct   exposet	   releasedc(   R   t   handleR   t   result(    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageWin.pyR   T   s    c         C   s   | s d |  j  } n  t | t  rm |  j j |  } z |  j j | | |  } Wd |  j j | |  Xn |  j j | | |  } | S(   sm  
        Same as expose, but allows you to specify where to draw the image, and
        what part of it to draw.

        The destination and source areas are given as 4-tuple rectangles. If
        the source is omitted, the entire image is copied. If the source and
        the destination have different sizes, the image is resized as
        necessary.
        i    N(   i    i    (   R   R   R	   R   R   t   drawR   (   R   R   t   dstt   srcR   R   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageWin.pyR   f   s    
c         C   sg   t  | t  rQ |  j j |  } z |  j j |  } Wd |  j j | |  Xn |  j j |  } | S(   se  
        Installs the palette associated with the image in the given device
        context.

        This method should be called upon **QUERYNEWPALETTE** and
        **PALETTECHANGED** events from Windows. If this method returns a
        non-zero value, one or more display palette entries were changed, and
        the image should be redrawn.

        :param handle: Device context (HDC), cast to a Python integer, or an
                       HDC or HWND instance.
        :return: A true value if one or more entries were changed (this
                 indicates that the image should be redrawn).
        N(   R   R	   R   R   t   query_paletteR   (   R   R   R   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageWin.pyR"   |   s    c         C   sg   | j    |  j | j k r1 | j |  j  } n  | rP |  j j | j |  n |  j j | j  d S(   s  
        Paste a PIL image into the bitmap image.

        :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.
        N(   t   loadR   t   convertR   R   t   im(   R   R%   t   box(    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageWin.pyR      s    
c         C   s   |  j  j |  S(   s   
        Load display memory contents from byte data.

        :param buffer: A buffer containing display data (usually
                       data returned from <b>tobytes</b>)
        (   R   t	   frombytes(   R   t   buffer(    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageWin.pyR'      s    c         C   s   |  j  j   S(   sy   
        Copy display memory contents to bytes object.

        :return: A bytes object containing display data.
        (   R   t   tobytes(   R   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageWin.pyR)      s    c         O   s   t  d d   d  S(   Ns   fromstring() has been removed. s   Please use frombytes() instead.(   t   NotImplementedError(   R   t   argst   kw(    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageWin.pyt
   fromstring   s    c         O   s   t  d d   d  S(   Ns   tostring() has been removed. s   Please use tobytes() instead.(   R*   (   R   R+   R,   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageWin.pyt   tostring   s    N(   R   R   R   R   R   R   R   R"   R   R'   R)   R-   R.   (    (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageWin.pyR   1   s   						t   Windowc           B   s_   e  Z d  Z d d
 d
 d  Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z RS(   s*   Create a Window with the given title size.t   PILc         C   s1   t  j j | |  j | p d | p$ d  |  _ d  S(   Ni    (   R    R   t   createwindowt   _Window__dispatchert   hwnd(   R   t   titlet   widtht   height(    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageWin.pyR      s    	c         G   s   t  |  d |  |   S(   Nt
   ui_handle_(   t   getattr(   R   t   actionR+   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageWin.pyt   __dispatcher   s    c         C   s   d  S(   N(    (   R   R   t   x0t   y0t   x1t   y1(    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageWin.pyt   ui_handle_clear   s    c         C   s   d  S(   N(    (   R   R;   R<   R=   R>   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageWin.pyt   ui_handle_damage   s    c         C   s   d  S(   N(    (   R   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageWin.pyt   ui_handle_destroy   s    c         C   s   d  S(   N(    (   R   R   R;   R<   R=   R>   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageWin.pyt   ui_handle_repair   s    c         C   s   d  S(   N(    (   R   R5   R6   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageWin.pyt   ui_handle_resize   s    c         C   s   t  j j   d  S(   N(   R    R   t	   eventloop(   R   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageWin.pyt   mainloop   s    N(   R   R   R   R   R   R2   R?   R@   RA   RB   RC   RE   (    (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageWin.pyR/      s   						t   ImageWindowc           B   s#   e  Z d  Z d d  Z d   Z RS(   s6   Create an image window which displays the given image.R0   c         C   sV   t  | t  s t |  } n  | |  _ | j \ } } t j |  | d | d | d  S(   NR5   R6   (   R   R   R   R   R/   R   (   R   R   R4   R5   R6   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageWin.pyR      s
    	c         C   s#   |  j  j | | | | | f  d  S(   N(   R   R   (   R   R   R;   R<   R=   R>   (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageWin.pyRB      s    (   R   R   R   R   RB   (    (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageWin.pyRF      s   N(   R0   R    t   objectR   R	   R   R/   RF   (    (    (    s.   /tmp/pip-unpacked-wheel-ivxKtu/PIL/ImageWin.pyt   <module>   s
   