o
    Z#a                     @   sX   d dl mZ G dd dZG dd dZG dd dZG dd	 d	ZG d
d deZdS )   )Imagec                   @       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   
   || _ d S Ndc)selfr    r
   ./usr/lib/python3/dist-packages/PIL/ImageWin.py__init__      
zHDC.__init__c                 C      | j S r   r   r	   r
   r
   r   __int__!      zHDC.__int__N__name__
__module____qualname____doc__r   r   r
   r
   r
   r   r          r   c                   @   r   )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   r   r   wnd)r	   r   r
   r
   r   r   ,   r   zHWND.__init__c                 C   r   r   r   r   r
   r
   r   r   /   r   zHWND.__int__Nr   r
   r
   r
   r   r   %   r   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   sn   t |drt |dr|j}|j}n|}d }|dvrt|}tj||| _|| _|| _|r5| | d S d S )Nmodesize)1LPRGB)	hasattrr   r   r   getmodebasecoredisplayimagepaste)r	   r&   r   r   r
   r
   r   r   G   s   
zDib.__init__c              
   C   sX   t |tr$| j|}z| j|}W | j|| |S | j|| w | 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
                       ``CDC.GetHandleAttrib()`` to get a suitable handle.
        )
isinstancer   r&   getdcexpose	releasedc)r	   handler   resultr
   r
   r   r*   V   s   
z
Dib.exposec              
   C   sn   |sd| j  }t|tr-| j|}z| j|||}W | j|| |S | j|| w | 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.   )r   r(   r   r&   r)   drawr+   )r	   r,   dstsrcr   r-   r
   r
   r   r/   h   s   


zDib.drawc              
   C   sX   t |tr$| j|}z| j|}W | j|| |S | j|| w | 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).
        )r(   r   r&   r)   query_paletter+   )r	   r,   r-   r
   r
   r   r2   ~   s   
zDib.query_palettec                 C   sJ   |   | j|jkr|| j}|r| j|j| dS | 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.  See :ref:`coordinate-system`. If
                    None is given instead of a tuple, all of the image is
                    assumed.
        N)loadr   convertr&   r'   im)r	   r5   boxr
   r
   r   r'      s   z	Dib.pastec                 C   s   | j |S )z
        Load display memory contents from byte data.

        :param buffer: A buffer containing display data (usually
                       data returned from :py:func:`~PIL.ImageWin.Dib.tobytes`)
        )r&   	frombytes)r	   bufferr
   r
   r   r7      s   zDib.frombytesc                 C   s
   | j  S )zy
        Copy display memory contents to bytes object.

        :return: A bytes object containing display data.
        )r&   tobytesr   r
   r
   r   r9      s   
zDib.tobytesr   )r   r   r   r   r   r*   r/   r2   r'   r7   r9   r
   r
   r
   r   r   3   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|p	d|pd| _d S )Nr.   )r   r$   createwindow_Window__dispatcherhwnd)r	   titlewidthheightr
   r
   r   r      s   
zWindow.__init__c                 G   s   t | d| | S )N
ui_handle_)getattr)r	   actionargsr
   r
   r   __dispatcher   s   zWindow.__dispatcherc                 C      d S r   r
   r	   r   x0y0x1y1r
   r
   r   ui_handle_clear      zWindow.ui_handle_clearc                 C   rG   r   r
   )r	   rI   rJ   rK   rL   r
   r
   r   ui_handle_damage   rN   zWindow.ui_handle_damagec                 C   rG   r   r
   r   r
   r
   r   ui_handle_destroy   rN   zWindow.ui_handle_destroyc                 C   rG   r   r
   rH   r
   r
   r   ui_handle_repair   rN   zWindow.ui_handle_repairc                 C   rG   r   r
   )r	   r@   rA   r
   r
   r   ui_handle_resize   rN   zWindow.ui_handle_resizec                 C   s   t j  d S r   )r   r$   	eventloopr   r
   r
   r   mainloop   s   zWindow.mainloop)r;   NN)r   r   r   r   r   r=   rM   rO   rP   rQ   rR   rT   r
   r
   r
   r   r:      s    
r:   c                       s*   e Zd ZdZd fdd	Zdd Z  ZS )ImageWindowz6Create an image window which displays the given image.r;   c                    s8   t |ts	t|}|| _|j\}}t j|||d d S )N)r@   rA   )r(   r   r&   r   superr   )r	   r&   r?   r@   rA   	__class__r
   r   r      s
   

zImageWindow.__init__c                 C   s   | j |||||f d S r   )r&   r/   rH   r
   r
   r   rQ      s   zImageWindow.ui_handle_repair)r;   )r   r   r   r   r   rQ   __classcell__r
   r
   rW   r   rU      s    rU   N) r   r   r   r   r:   rU   r
   r
   r
   r   <module>   s    