
 Xa                 @   s   d  d l  m Z Gd d   d e  Z Gd d   d e  Z Gd d   d e  Z Gd d	   d	 e  Z Gd
 d   d e  Z d S)    )Imagec               @   s.   e  Z d  Z d Z d d   Z d d   Z d S)HDCz
    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)dc)selfr    r   I/home/ubuntu/projects/ifolica/lib/python3.4/site-packages/PIL/ImageWin.py__init__   s    zHDC.__init__c             C   s   |  j  S)N)r   )r   r   r   r   __int__    s    zHDC.__int__N)__name__
__module____qualname____doc__r   r	   r   r   r   r   r      s   r   c               @   s.   e  Z d  Z d Z d d   Z d d   Z d S)HWNDz
    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)wnd)r   r   r   r   r   r   *   s    zHWND.__init__c             C   s   |  j  S)N)r   )r   r   r   r   r	   -   s    zHWND.__int__N)r
   r   r   r   r   r	   r   r   r   r   r   $   s   r   c               @   s   e  Z d  Z d Z d d d  Z d d   Z d d d  Z d	 d
   Z d d d  Z d d   Z	 d d   Z
 d d   Z d d   Z d S)Diba&  
    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.
    Nc             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)Nmodesize1LPRGB)r   r   r   r   )	hasattrr   r   r   Zgetmodebasecoredisplayimagepaste)r   r   r   r   r   r   r   r   E   s    			zDib.__init__c             C   sg   t  | t  rQ |  j j |  } z |  j j |  } Wd |  j j | |  Xn |  j j |  } | S)a)  
        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)
isinstancer   r   getdcexpose	releasedc)r   handler   resultr   r   r   r   T   s    z
Dib.exposec             C   s   | s d |  j  } n  t | t  rm |  j j |  } z |  j j | | |  } Wd |  j j | |  Xn |  j j | | |  } | S)am  
        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.
        r   N)r   r   )r   r   r   r   r   drawr   )r   r    dstsrcr   r!   r   r   r   r"   f   s    
zDib.drawc             C   sg   t  | t  rQ |  j j |  } z |  j j |  } Wd |  j j | |  Xn |  j j |  } | S)ae  
        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   query_paletter   )r   r    r!   r   r   r   r%   |   s    zDib.query_palettec             C   sg   | j    |  j | j k r1 | j |  j  } n  | rP |  j j | j |  n |  j j | j  d S)a  
        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)loadr   convertr   r   im)r   r(   Zboxr   r   r   r      s    
z	Dib.pastec             C   s   |  j  j |  S)z
        Load display memory contents from byte data.

        :param buffer: A buffer containing display data (usually
                       data returned from <b>tobytes</b>)
        )r   	frombytes)r   bufferr   r   r   r)      s    zDib.frombytesc             C   s   |  j  j   S)zy
        Copy display memory contents to bytes object.

        :return: A bytes object containing display data.
        )r   tobytes)r   r   r   r   r+      s    zDib.tobytesc             O   s   t  d d   d  S)Nzfromstring() has been removed. zPlease use frombytes() instead.)NotImplementedError)r   argskwr   r   r   
fromstring   s    zDib.fromstringc             O   s   t  d d   d  S)Nztostring() has been removed. zPlease use tobytes() instead.)r,   )r   r-   r.   r   r   r   tostring   s    zDib.tostring)r
   r   r   r   r   r   r"   r%   r   r)   r+   r/   r0   r   r   r   r   r   1   s   	r   c               @   s   e  Z d  Z d Z d d d d d  Z d d   Z d d	   Z d
 d   Z d d   Z d d   Z	 d d   Z
 d d   Z d S)Windowz*Create a Window with the given title size.PILNc             C   s1   t  j j | |  j | p d | p$ d  |  _ d  S)Nr   )r   r   Zcreatewindow_Window__dispatcherZhwnd)r   titlewidthheightr   r   r   r      s    	zWindow.__init__c             G   s   t  |  d |  |   S)NZ
ui_handle_)getattr)r   actionr-   r   r   r   Z__dispatcher   s    zWindow.__dispatcherc             C   s   d  S)Nr   )r   r   x0y0x1y1r   r   r   ui_handle_clear   s    zWindow.ui_handle_clearc             C   s   d  S)Nr   )r   r9   r:   r;   r<   r   r   r   ui_handle_damage   s    zWindow.ui_handle_damagec             C   s   d  S)Nr   )r   r   r   r   ui_handle_destroy   s    zWindow.ui_handle_destroyc             C   s   d  S)Nr   )r   r   r9   r:   r;   r<   r   r   r   ui_handle_repair   s    zWindow.ui_handle_repairc             C   s   d  S)Nr   )r   r5   r6   r   r   r   ui_handle_resize   s    zWindow.ui_handle_resizec             C   s   t  j j   d  S)N)r   r   Z	eventloop)r   r   r   r   mainloop   s    zWindow.mainloop)r
   r   r   r   r   r3   r=   r>   r?   r@   rA   rB   r   r   r   r   r1      s   r1   c               @   s1   e  Z d  Z d Z d d d  Z d d   Z d S)ImageWindowz6Create an image window which displays the given image.r2   c             C   sV   t  | t  s t |  } n  | |  _ | j \ } } t j |  | d | d | d  S)Nr5   r6   )r   r   r   r   r1   r   )r   r   r4   r5   r6   r   r   r   r      s
    	zImageWindow.__init__c             C   s#   |  j  j | | | | | f  d  S)N)r   r"   )r   r   r9   r:   r;   r<   r   r   r   r@      s    zImageWindow.ui_handle_repairN)r
   r   r   r   r   r@   r   r   r   r   rC      s   rC   N)r2   r   objectr   r   r   r1   rC   r   r   r   r   <module>   s
   