a :jg@sdddlmZddlmZGdddZGdddZGdd d ZGd d d ZGd d d eZdS)) annotations)Imagec@s.eZdZdZdddddZdddd Zd 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. intNone)dcreturncCs ||_dSNr)selfrr 6/usr/local/lib/python3.9/site-packages/PIL/ImageWin.py__init__sz HDC.__init__r cCs|jSr r r r r r__int__"sz HDC.__int__N__name__ __module__ __qualname____doc__rrr r r rrsrc@s.eZdZdZdddddZdddd Zd 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. rr)wndr cCs ||_dSr r)r rr r rr-sz HWND.__init__rcCs|jSr rrr r rr0sz HWND.__int__Nrr r r rr&src@seZdZdZd ddddddZd dd d d Zd!d d dddddZd dd ddZd"ddddddZdddddZ ddddZ dS)#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. NzImage.Image | strztuple[int, int] | Noner)imagesizer cCst|tr(|}d}|dur4d}t|n |j}|j}|dvrFt|}tj|||_ ||_||_|r~t|trtJ| |dS)Nz+If first argument is mode, size is required)1LPRGB) isinstancestr ValueErrormoderrZ getmodebasecoredisplayrpaste)r rrr&msgr r rrHs    z Dib.__init__zint | HDC | HWND)handler c Cs`t|}t|trP|j|}z|j|W|j||q\|j||0n |j|dS)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)rr#rrgetdcexpose releasedc)r r+ handle_intrr r rr-]s  "z Dib.exposeztuple[int, int, int, int]z tuple[int, int, int, int] | None)r+dstsrcr c Csz|durd|j}t|}t|trf|j|}z"|j|||W|j||qv|j||0n|j|||dS)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)rr)rrr#rrr,drawr.)r r+r0r1r/rr r rr2os   "zDib.drawrc Cs`t|}t|trP|j|}z|j|}W|j||q\|j||0n |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). )rr#rrr, query_paletter.)r r+r/resultr r rr3s  " zDib.query_palettez Image.Image)imboxr cCsH||j|jkr ||j}|r6|j|j|n|j|jdS)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&convertrr)r5)r r5r6r r rr)s   z Dib.pastebytes)bufferr cCs|j|dS)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 r:r r rr;sz Dib.frombytesrcCs |jS)zy Copy display memory contents to bytes object. :return: A bytes object containing display data. )rtobytesrr r rr<sz Dib.tobytes)N)N)N) rrrrrr-r2r3r)r;r<r r r rr4s rc@seZdZdZdddddddd Zdd dd d d Zd d d d d ddddZd d d d ddddZddddZd d d d d ddddZ d d ddddZ ddddZ dS)Windowz*Create a Window with the given title size.PILNr$z int | Noner)titlewidthheightr cCs"tj||j|pd|pd|_dS)Nr)rr'Z createwindow_Window__dispatcherZhwnd)r r?r@rAr r rrszWindow.__init__r)actionargsr cGst|d||dS)NZ ui_handle_)getattr)r rCrDr r rZ __dispatcherszWindow.__dispatcherrx0y0x1y1r cCsdSr r r rrGrHrIrJr r rui_handle_clearszWindow.ui_handle_clear)rGrHrIrJr cCsdSr r )r rGrHrIrJr r rui_handle_damageszWindow.ui_handle_damagercCsdSr r rr r rui_handle_destroyszWindow.ui_handle_destroycCsdSr r rKr r rui_handle_repairszWindow.ui_handle_repair)r@rAr cCsdSr r )r r@rAr r rui_handle_resizeszWindow.ui_handle_resizecCstjdSr )rr'Z eventlooprr r rmainloopszWindow.mainloop)r>NN) rrrrrrBrLrMrNrOrPrQr r r rr=sr=csDeZdZdZd ddddfdd Zd d d d d dd d d ZZS) ImageWindowz6Create an image window which displays the given image.r>zImage.Image | Dibr$r)rr?r cs8t|tst|}||_|j\}}tj|||ddS)N)r@rA)r#rrrsuperr)r rr?r@rA __class__r rrs   zImageWindow.__init__rrFcCs|j|||||fdSr )rr2rKr r rrOszImageWindow.ui_handle_repair)r>)rrrrrrO __classcell__r r rTrrRsrRN) __future__rrrrrrr=rRr r r rs