a
    áñh•  ã                   @  sd   d dl mZ 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 )é    )Úannotationsé   )ÚImagec                   @  s.   e Zd ZdZdddœdd„Zddœ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.
    ÚintÚNone)ÚdcÚreturnc                 C  s
   || _ d S ©N©r   )Úselfr   © r   úL/home/yuhw/wc/uboone-dl-vtx/venv/lib/python3.9/site-packages/PIL/ImageWin.pyÚ__init__   s    zHDC.__init__©r	   c                 C  s   | j S r
   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dœdd„Zddœ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.
    r   r   )Úwndr	   c                 C  s
   || _ d S r
   ©r   )r   r   r   r   r   r   -   s    zHWND.__init__r   c                 C  s   | j S r
   r   r   r   r   r   r   0   s    zHWND.__int__Nr   r   r   r   r   r   &   s   r   c                   @  sŒ   e Zd ZdZd ddddœdd„Zd	dd
œdd„Zd!d	ddddœdd„Zd	dd
œdd„Zd"ddddœdd„Zdddœdd„Z	ddœ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 graylevels
    are allocated. For an "RGB" image, a 6x6x6 colour cube is used, together
    with 20 graylevels.

    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.
    NzImage.Image | strztuple[int, int] | Noner   )ÚimageÚsizer	   c                 C  s‚   t |tƒr(|}d}|d u r4d}t|ƒ‚n|j}|j}|dvrFt |¡}tj ||¡| _	|| _|| _|r~t |tƒrtJ ‚|  
|¡ d S )NÚ z+If first argument is mode, size is required)Ú1ÚLÚPZRGB)Ú
isinstanceÚstrÚ
ValueErrorÚmoder   r   ZgetmodebaseÚcoreZdisplayr   Úpaste)r   r   r   r%   Úmsgr   r   r   r   H   s     


zDib.__init__zint | HDC | HWND)Úhandler	   c              
   C  s`   t |ƒ}t|tƒrP| j |¡}z| j |¡ W | j ||¡ q\| j ||¡ 0 n| j |¡ d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.
        N)r   r"   r   r   ÚgetdcÚexposeÚ	releasedc)r   r)   Ú
handle_intr   r   r   r   r+   ]   s    
"z
Dib.exposeztuple[int, int, int, int]z tuple[int, int, int, int] | None)r)   ÚdstÚsrcr	   c              
   C  sz   |du rd| j  }t|ƒ}t|tƒrf| j |¡}z"| j |||¡ W | j ||¡ qv| j ||¡ 0 n| j |||¡ d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   r*   Údrawr,   )r   r)   r.   r/   r-   r   r   r   r   r0   o   s    

"zDib.drawr   c              
   C  s`   t |ƒ}t|tƒrP| j |¡}z| j |¡}W | j ||¡ q\| j ||¡ 0 n| j |¡}|S )at  
        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: The number of entries that were changed (if one or more entries,
                 this indicates that the image should be redrawn).
        )r   r"   r   r   r*   Úquery_paletter,   )r   r)   r-   Úresultr   r   r   r1   Š   s    
"zDib.query_palettezImage.Image)ÚimÚboxr	   c                 C  sH   |  ¡  | j|jkr | | j¡}|r6| j |j|¡ n| 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'   r3   )r   r3   r4   r   r   r   r'   ¤   s    z	Dib.pasteÚbytes)Úbufferr	   c                 C  s   | j  |¡ d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`)
        N)r   Ú	frombytes)r   r8   r   r   r   r9   º   s    zDib.frombytesr   c                 C  s
   | j  ¡ S )zy
        Copy display memory contents to bytes object.

        :return: A bytes object containing display data.
        )r   Útobytesr   r   r   r   r:   Ã   s    zDib.tobytes)N)N)N)r   r   r   r   r   r+   r0   r1   r'   r9   r:   r   r   r   r   r   4   s    ÿ ü ÿ	r   c                   @  s¬   e Zd ZdZddddddœdd	„Zdd
ddœdd„Zd
d
d
d
d
ddœdd„Zd
d
d
d
ddœdd„Zddœdd„Zd
d
d
d
d
ddœdd„Z	d
d
ddœdd„Z
ddœdd„ZdS )ÚWindowz*Create a Window with the given title size.ÚPILNr#   z
int | Noner   )ÚtitleÚwidthÚheightr	   c                 C  s"   t j || j|pd|pd¡| _d S )Nr   )r   r&   ZcreatewindowÚ_Window__dispatcherZhwnd)r   r=   r>   r?   r   r   r   r   Ï   s    ÿzWindow.__init__r   )ÚactionÚargsr	   c                 G  s   t | d|› �ƒ|Ž  d S )NZ
ui_handle_)Úgetattr)r   rA   rB   r   r   r   Z__dispatcherÖ   s    zWindow.__dispatcher©r   Úx0Úy0Úx1Úy1r	   c                 C  s   d S r
   r   ©r   r   rE   rF   rG   rH   r   r   r   Úui_handle_clearÙ   s    zWindow.ui_handle_clear)rE   rF   rG   rH   r	   c                 C  s   d S r
   r   )r   rE   rF   rG   rH   r   r   r   Úui_handle_damageÜ   s    zWindow.ui_handle_damager   c                 C  s   d S r
   r   r   r   r   r   Úui_handle_destroyß   s    zWindow.ui_handle_destroyc                 C  s   d S r
   r   rI   r   r   r   Úui_handle_repairâ   s    zWindow.ui_handle_repair)r>   r?   r	   c                 C  s   d S r
   r   )r   r>   r?   r   r   r   Úui_handle_resizeå   s    zWindow.ui_handle_resizec                 C  s   t j ¡  d S r
   )r   r&   Z	eventloopr   r   r   r   Úmainloopè   s    zWindow.mainloop)r<   NN)r   r   r   r   r   r@   rJ   rK   rL   rM   rN   rO   r   r   r   r   r;   Ì   s    ÿr;   c                      sD   e Zd ZdZdddddœ‡ fdd„Zd	d	d	d	d	dd
œdd„Z‡  ZS )ÚImageWindowz6Create an image window which displays the given image.r<   zImage.Image | Dibr#   r   )r   r=   r	   c                   s8   t |tƒst|ƒ}|| _|j\}}tƒ j|||d� d S )N)r>   r?   )r"   r   r   r   Úsuperr   )r   r   r=   r>   r?   ©Ú	__class__r   r   r   ï   s
    

zImageWindow.__init__r   rD   c                 C  s   | j  |||||f¡ d S r
   )r   r0   rI   r   r   r   rM   ö   s    zImageWindow.ui_handle_repair)r<   )r   r   r   r   r   rM   Ú__classcell__r   r   rR   r   rP   ì   s   rP   N)	Ú
__future__r   r   r   r   r   r   r;   rP   r   r   r   r   Ú<module>   s     