3
`¢JZÿ  ã               @   s`   d dl mZ G dd„ deƒZG dd„ deƒZG dd„ deƒZG dd	„ d	eƒZG d
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   ú./usr/lib/python3/dist-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               @   sN   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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   sj   t |dƒr"t |dƒr"|j}|j}n|}d }|dkr<tj|ƒ}tjj||ƒ| _|| _|| _|rf| j|ƒ d S )NÚmodeÚsizeÚ1ÚLÚPÚRGB)r   r   r   r   )	Úhasattrr   r   r   ZgetmodebaseÚcoreZdisplayÚimageÚpaste)r   r   r   r   r   r   r   r   E   s    
zDib.__init__c             C   sJ   t |tƒr:| jj|ƒ}z| jj|ƒ}W d| jj||ƒ X n| 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  }t|tƒrL| jj|ƒ}z| jj|||ƒ}W d| jj||ƒ X n| 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.
        é    N)r!   r!   )r   r   r   r   r   Údrawr   )r   r   ÚdstÚsrcr   r    r   r   r   r"   f   s    


zDib.drawc             C   sJ   t |tƒr:| jj|ƒ}z| jj|ƒ}W d| jj||ƒ X n| 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   sH   |j ƒ  | j|jkr |j| jƒ}|r6| 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   Z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.tobytes)N)N)N)r
   r   r   r   r   r   r"   r%   r   r(   r*   r   r   r   r   r   1   s   


	r   c               @   sR   e Zd ZdZ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   s"   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   ÚactionÚargsr   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   r4   r5   r6   r7   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   r4   r5   r6   r7   r   r   r   Úui_handle_repairÎ   s    zWindow.ui_handle_repairc             C   s   d S )Nr   )r   r/   r0   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,   NN)r
   r   r   r   r   r-   r8   r9   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S )	ÚImageWindowz6Create an image window which displays the given image.r,   c             C   s8   t |tƒst|ƒ}|| _|j\}}tj| |||d d S )N)r/   r0   )r   r   r   r   r+   r   )r   r   r.   r/   r0   r   r   r   r   Û   s
    

zImageWindow.__init__c             C   s   | j j|||||fƒ d S )N)r   r"   )r   r   r4   r5   r6   r7   r   r   r   r;   â   s    zImageWindow.ui_handle_repairN)r,   )r
   r   r   r   r   r;   r   r   r   r   r>   Ø   s   
r>   N)Ú r   Úobjectr   r   r   r+   r>   r   r   r   r   Ú<module>   s    
