a :jg%#@sddlmZddlZddlmZddlmZmZmZddl m Z m Z erTddl m Z dd d d d Zd ddddddZGdddZGdddZdddddZddddddZdS) ) annotationsN)BytesIO) TYPE_CHECKINGAnycast)Image ImageFile) CapsuleTypezdict[str, Any]zImageFile.ImageFile | None)kwreturncCs@d}d|vr|d}nd|vr.t|d}|s6dSt|S)Nfiledata)poprropen)r sourcer5/usr/local/lib/python3.9/site-packages/PIL/ImageTk.py_get_image_from_kw*s rstrzPhotoImage | tkinter.PhotoImager None)commandphotoptrr c Csb|j}z|||t|Wn@tjy\ddlm}|||||t|Yn0dS)Nr) _imagingtk) tkcallreprtkinterZTclErrorrZtkinitZ interpaddr)rrrrrrrr_pyimagingtkcall5s r c@sneZdZdZdddddddd Zdd d d Zd d ddZdd ddZdd ddZdddddZ dS) PhotoImagea3 A Tkinter-compatible photo image. This can be used everywhere Tkinter expects an image object. If the image is an RGBA image, pixels having alpha 0 are treated as transparent. The constructor takes either a PIL image, or a mode and a size. Alternatively, you can use the ``file`` or ``data`` options to initialize the photo image object. :param image: Either a PIL image, or a mode string. If a mode string is used, a size must also be given. :param size: If the first argument is a mode string, this defines the size of the image. :keyword file: A filename to load the image from (using ``Image.open(file)``). :keyword data: An 8-bit string containing image data (as loaded from an image file). NzImage.Image | str | Noneztuple[int, int] | Nonerr)imagesizer r cKs|durt|}|dur&d}t|nnt|trN|}d}|durd}t|nF|j}|dkr~|||jrz|jjnd}|j}|\|d<|d<|dvrt |}||_ ||_ t jfi||_|jj|_|r||dS)NImage is requiredz+If first argument is mode, size is requiredPRGBwidthheight)1Lr&RGBA)r ValueError isinstancermodeZapply_transparencyloadpaletter#rZ getmodebase_PhotoImage__mode_PhotoImage__sizerr!_PhotoImage__photorpaste)selfr"r#r msgr.rrr__init__\s4     zPhotoImage.__init__r cCsXz |jj}Wnty YdS0d|j_z|jjdd|WntyRYn0dSNr"delete)r3nameAttributeErrorrr Exceptionr5r;rrr__del__s   zPhotoImage.__del__rcCs t|jS)z Get the Tkinter photo image identifier. This method is automatically called by Tkinter whenever a PhotoImage object is passed to a Tkinter method. :return: A Tkinter photo image identifier (a string). )rr3r5rrr__str__szPhotoImage.__str__intcCs |jdSzU Get the width of the image. :return: The width, in pixels. rr2r@rrrr'szPhotoImage.widthcCs |jdSzW Get the height of the image. :return: The height, in pixels. rrDr@rrrr(szPhotoImage.height Image.Image)imr cCsX|}|j}|r"|j|jkrFtj|j|j}| |||j }t d|j |dS)aF Paste a PIL image into the photo image. Note that this can be very slow if the photo image is displayed. :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. ZPyImagingPhotoN) getimrGZisblockr.r1rcoreZ new_blockr#Zconvert2rr r3)r5rGrr"blockrrrr4s  zPhotoImage.paste)NN) __name__ __module__ __qualname____doc__r7r?rAr'r(r4rrrrr!Hs)  r!c@s\eZdZdZdddddddZdd d d Zd d d dZd d ddZdd ddZdS) BitmapImagea A Tkinter-compatible bitmap image. This can be used everywhere Tkinter expects an image object. The given image must have mode "1". Pixels having value 0 are treated as transparent. Options, if any, are passed on to Tkinter. The most commonly used option is ``foreground``, which is used to specify the color for the non-transparent parts. See the Tkinter documentation for information on how to specify colours. :param image: A PIL image. NzImage.Image | Nonerr)r"r r cKsR|durt|}|dur$d}t||j|_|j|_tjfd|i||_ dS)Nr$r) rr,r.Z_BitmapImage__moder#_BitmapImage__sizerrOZtobitmap_BitmapImage__photo)r5r"r r6rrrr7szBitmapImage.__init__r8cCsXz |jj}Wnty YdS0d|j_z|jjdd|WntyRYn0dSr9)rQr;r<rrr=r>rrrr?s   zBitmapImage.__del__rBcCs |jdSrCrPr@rrrr'szBitmapImage.widthcCs |jdSrErRr@rrrr(szBitmapImage.heightrcCs t|jS)z Get the Tkinter bitmap image identifier. This method is automatically called by Tkinter whenever a BitmapImage object is passed to a Tkinter method. :return: A Tkinter bitmap image identifier (a string). )rrQr@rrrrAszBitmapImage.__str__)N) rKrLrMrNr7r?r'r(rArrrrrOs    rOrF)rr cCs,td||f}td|||S)z:Copies the contents of a PhotoImage to a PIL image memory.r+ZPyImagingPhotoGet)rnewr'r(r rH)rrGrrrgetimagesrTz str | None)r"titler cCsPGdddtj}ttds(d}t|t}|r>|||||dS)z!Helper for the Image.show method.cs&eZdZddddfdd ZZS)z_show..UIztkinter.ToplevelrFr)masterrGr cs`||jdkr t|d|d|_nt||d|_trBttj|j}n|j}tj ||ddddS)Nr)white) foregroundrV)rVblackr)r"bgZbd) r.rOr"r!rrrZ_Imagesuperr7)r5rVrGr" __class__rrr7s z_show..UI.__init__)rKrLrMr7 __classcell__rrr\rUIsr_Z _default_rootztkinter not initializedN)rLabelgetattrOSErrorZToplevelrUpack)r"rUr_r6toprrr_show s  re) __future__rriortypingrrrrrr Z_typingr rr r!rOrTrerrrrs    zA