a :jg '@sdddlmZddlZddlZddlZddlZddlZddlmZddl m Z ddl m Z gZ d4ddd d d d Zd5d ddddddZGdddZGdddeZejdkreeGdddeZejdkreeGdddeZGdddeZGd d!d!eZGd"d#d#eZGd$d%d%eZGd&d'd'eZejd(vred)rXeeed*rleeed+reeed,reeed-reeGd.d/d/eZzdd0lmZWneyYn 0eee d1kr`e!ej"d2kre#d3e$e %ej"d.Z&e#ee&gej"d2dRWdn1sV0YdS)6) annotationsNquote)Any)Imageztype[Viewer] | ViewerintNone)viewerorderreturncCs>t|trt|tr|}|dkr.t|n td|dS)a$ The :py:func:`register` function is used to register additional viewers:: from PIL import ImageShow ImageShow.register(MyViewer()) # MyViewer will be used as a last resort ImageShow.register(MySecondViewer(), 0) # MySecondViewer will be prioritised ImageShow.register(ImageShow.XVViewer(), 0) # XVViewer will be prioritised :param viewer: The viewer to be registered. :param order: Zero or a negative integer to prepend this viewer to the list, a positive integer to append it. rN) isinstancetype issubclassViewer_viewersappendinsert)r r r7/usr/local/lib/python3.9/site-packages/PIL/ImageShow.pyregisters  r Image.Image str | Nonerbool)imagetitleoptionsr cKs*tD] }|j|fd|i|rdSqdS)a  Display a given image. :param image: An image object. :param title: Optional title. Not all viewers can display the title. :param \**options: Additional viewer options. :returns: ``True`` if a suitable viewer was found, ``False`` otherwise. rTF)rshow)rrrr rrrr3s rc@seZdZUdZddddddZdZd ed <iZd ed <dd d ddZddddddZ ddd ddZ ddddddZ ddddddZ dS)rzBase class for viewers.rrrrrr cKsP|jdvs>|jdkr|jdvs>t|j}|j|kr>||}|j|fi|S)z The main function for displaying an image. Converts the given image to the target format and displays it. )1ZRGBAPNG)zI;16ZLA)modeformatrZ getmodebaseconvert show_image)selfrrbaserrrrGs   z Viewer.showNrr"zdict[str, Any]r)rr cCs|jS)z3Return format name, or ``None`` to save as PGM/PPM.)r"r%rrrr get_format^szViewer.get_formatstrfilerr cKsd}t|dS)zj Returns the command used to display the file. Not implemented in the base class. zunavailable in base viewerN)NotImplementedError)r%r+rmsgrrr get_commandbszViewer.get_commandcCs|jfd||i|jS)z+Save to temporary file and return filename.r")_dumpr(rr'rrr save_imagejszViewer.save_imagecKs|j||fi|S)zDisplay the given image.) show_filer0r%rrrrrr$nszViewer.show_imagepathrr cKs,tj|stt|j|fi|dS)% Display given file. r)osr4existsFileNotFoundErrorsystemr.r%r4rrrrr1rs zViewer.show_file) __name__ __module__ __qualname____doc__rr"__annotations__rr(r.r0r$r1rrrrrBs   rc@sBeZdZdZdZdddZddddd d Zddd d d dZdS) WindowsViewerzNThe default viewer on Windows is the default system application for PNG files.r rTZcompress_levelZsave_allr)rr*cKsd|d|dS)Nzstart "Pillow" /WAIT "z)" && ping -n 4 127.0.0.1 >NUL && del /f ""rr%r+rrrrr.szWindowsViewer.get_commandrr3cKs8tj|sttj|j|fi|dttdddS)r5TZCREATE_NO_WINDOW)shell creationflagsr)r6r4r7r8 subprocessPopenr.getattrr:rrrr1s zWindowsViewer.show_fileNr;r<r=r>r"rr.r1rrrrr@s  r@win32c@sBeZdZdZdZdddZddddd d Zddd d d dZdS) MacViewerz2The default viewer on macOS using ``Preview.app``.r rTrAr)rr*cKs(d}d|dt|dt|d}|S)Nzopen -a Preview.app( z; sleep 20; rm -f z)&rr%r+rcommandrrrr.s zMacViewer.get_commandrr3cKsLtj|sttddd|gtjp0t d}|rHt |dd|gdS)r5openz-az Preview.apppython3z-czrZr1rrrrr]sr]c@s8eZdZdZdddddddd Zddd d d d ZdS) DisplayViewerz` The ImageMagick ``display`` command. This viewer supports the ``title`` parameter. Nr)rrrYr+rrr cKs&d}}|r|dt|7}||fS)Ndisplayz -title rr%r+rrrOrTrrrrZszDisplayViewer.get_command_exrr3cKsHtj|stdg}|d}|r0|d|g7}||t|dS)r5rcrz-titlerr6r4r7r8getrrFrGr%r4rargsrrrrr1s     zDisplayViewer.show_file)Nr`rrrrrasrac@s4eZdZdZddddddZdddd d d Zd S) GmDisplayViewerz*The GraphicsMagick ``gm display`` command.r)rrYr*cKsd}d}||fS)Ngmz gm displayrr%r+rrTrOrrrrZszGmDisplayViewer.get_command_exrr3cKs$tj|sttdd|gdS)r5rjrcrr_r:rrrr1 s zGmDisplayViewer.show_fileNr`rrrrrisric@s4eZdZdZddddddZdddd d d Zd S) EogViewerz'The GNOME Image Viewer ``eog`` command.r)rrYr*cKsd}d}||fS)Neogzeog -nrrkrrrrZszEogViewer.get_command_exrr3cKs$tj|sttdd|gdS)r5rmz-nrr_r:rrrr1s zEogViewer.show_fileNr`rrrrrlsrlc@s8eZdZdZdddddddd Zddd d d d ZdS)XVViewerzX The X Viewer ``xv`` command. This viewer supports the ``title`` parameter. Nr)rrrYrbcKs&d}}|r|dt|7}||fS)Nxvz -name rrdrrrrZ+szXVViewer.get_command_exrr3cKsHtj|stdg}|d}|r0|d|g7}||t|dS)r5rorz-namerrergrrrr15s     zXVViewer.show_file)Nr`rrrrrn%s rn)rJrWr^rcrjrmroc@s"eZdZdZddddddZdS) IPythonViewerz!The viewer for IPython frontends.rrrrcKs t|dS)Nr)ipython_displayr2rrrr$UszIPythonViewer.show_imageN)r;r<r=r>r$rrrrrpRsrp)rc__main__z.Syntax: python3 ImageShow.py imagefile [title])r)N)' __future__rr[r6rUrFrSshlexrtypingrrrrrrr@platformrKrXr]rarirlrnrVrpIPython.displayrcrq ImportErrorr;lenargvprintexitrPZimrrrrs^    = !