a
    ç´«jz'  ã                   @  sh  d dl mZ d dlZd dlZd dlZd dlZd dlZd dlmZ d dl	m
Z
 ddlmZ g Zd4ddd	d
œdd„Zd5dddddœdd„ZG dd„ dƒZG dd„ deƒZejdkr¶eeƒ G dd„ deƒZejdkrØeeƒ G dd„ dejeƒZG dd„ deƒZG d d!„ d!eƒZG d"d#„ d#eƒZG d$d%„ d%eƒZG d&d'„ d'eƒZejd(v�r¬e d)¡�r\eeƒ e d*¡�rpeeƒ e d+¡�r„eeƒ e d,¡�r˜eeƒ e d-¡�r¬eeƒ G d.d/„ d/eƒZzd d0lmZ W n e �yà   Y n
0 eeƒ e!d1k�rde"ej#ƒd2k �re$d3ƒ e %¡  e &ej#d ¡�.Z'e$ee'gej#d2d… ¢R Ž ƒ W d  ƒ n1 �sZ0    Y  dS )6é    )ÚannotationsN©Úquote)ÚAnyé   )ÚImageztype[Viewer] | ViewerÚintÚNone)ÚviewerÚorderÚreturnc                 C  s>   t | tƒrt| tƒr| ƒ } |dkr.t | ¡ nt d| ¡ dS )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.
    r   N)Ú
isinstanceÚtypeÚ
issubclassÚViewerÚ_viewersÚappendÚinsert)r
   r   © r   úL/var/www/html/laksyashrimp/venv/lib/python3.9/site-packages/PIL/ImageShow.pyÚregister   s
    r   úImage.Imageú
str | Noner   Úbool)ÚimageÚtitleÚoptionsr   c                 K  s*   t D ] }|j| fd|i|¤Žr dS qdS )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.
    r   TF)r   Úshow)r   r   r   r
   r   r   r   r   3   s    	r   c                   @  s’   e Zd ZU dZddddœdd„ZdZd	ed
< i Zded< dd	dœdd„Zddddœdd„Z	dddœdd„Z
ddddœdd„Zddddœdd„ZdS )r   zBase class for viewers.r   r   r   ©r   r   r   c                 K  sP   |j dv s>| jdkr|j dv s>t |j ¡}|j |kr>| |¡}| j|fi |¤ŽS )zƒ
        The main function for displaying an image.
        Converts the given image to the target format and displays it.
        )Ú1ZRGBAÚPNG)zI;16ZLA)ÚmodeÚformatr   ZgetmodebaseÚconvertÚ
show_image)Úselfr   r   Úbaser   r   r   r   G   s    ÿþþ

zViewer.showNr   r"   zdict[str, Any]r   )r   r   c                 C  s   | j S )z3Return format name, or ``None`` to save as PGM/PPM.)r"   ©r%   r   r   r   r   Ú
get_format^   s    zViewer.get_formatÚstr©Úfiler   r   c                 K  s   d}t |ƒ‚dS )zj
        Returns the command used to display the file.
        Not implemented in the base class.
        zunavailable in base viewerN)ÚNotImplementedError)r%   r+   r   Úmsgr   r   r   Úget_commandb   s    zViewer.get_commandc                 C  s   |j f d|  |¡i| j¤ŽS )z+Save to temporary file and return filename.r"   )Ú_dumpr(   r   r'   r   r   r   Ú
save_imagej   s    zViewer.save_imagec                 K  s   | j |  |¡fi |¤ŽS )zDisplay the given image.)Ú	show_filer0   ©r%   r   r   r   r   r   r$   n   s    zViewer.show_image©Úpathr   r   c                 K  s,   t j |¡st‚t  | j|fi |¤Ž¡ dS )ú%
        Display given file.
        r   )Úosr4   ÚexistsÚFileNotFoundErrorÚsystemr.   ©r%   r4   r   r   r   r   r1   r   s    zViewer.show_file)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r"   Ú__annotations__r   r(   r.   r0   r$   r1   r   r   r   r   r   B   s   
r   c                   @  sB   e Zd ZdZdZdddœZddddœd	d
„Zddddœdd„ZdS )ÚWindowsViewerzNThe default viewer on Windows is the default system application for PNG files.r    r   T©Zcompress_levelZsave_allr)   r   r*   c                 K  s   d|› d|› d�S )Nzstart "Pillow" /WAIT "z)" && ping -n 4 127.0.0.1 >NUL && del /f "ú"r   ©r%   r+   r   r   r   r   r.   …   s    þÿzWindowsViewer.get_commandr   r3   c                 K  s8   t j |¡st‚tj| j|fi |¤Ždttdƒd� dS )r5   TZCREATE_NO_WINDOW)ÚshellÚcreationflagsr   )r6   r4   r7   r8   Ú
subprocessÚPopenr.   Úgetattrr:   r   r   r   r1   Œ   s    ýzWindowsViewer.show_fileN©r;   r<   r=   r>   r"   r   r.   r1   r   r   r   r   r@      s
   
r@   Úwin32c                   @  sB   e Zd ZdZdZdddœZddddœd	d
„Zddddœdd„ZdS )Ú	MacViewerz2The default viewer on macOS using ``Preview.app``.r    r   TrA   r)   r   r*   c                 K  s(   d}d|› dt |ƒ› dt |ƒ› d�}|S )Nzopen -a Preview.appú(ú z; sleep 20; rm -f z)&r   ©r%   r+   r   Úcommandr   r   r   r.   ¤   s     zMacViewer.get_commandr   r3   c                 K  sh   t j |¡st‚t ddd|g¡ ttddƒo6ttdƒ}| rDtj	pLt
 d¡}|rdt |dd	|g¡ d
S )r5   Úopenz-azPreview.appÚfrozenFZ_MEIPASSÚpython3z-cz<import os, sys, time; time.sleep(20); os.remove(sys.argv[1])r   )r6   r4   r7   r8   rF   ÚcallrH   ÚsysÚhasattrÚ
executableÚshutilÚwhichrG   )r%   r4   r   ZpyinstallerrV   r   r   r   r1   «   s    üÿzMacViewer.show_fileNrI   r   r   r   r   rK   ž   s
   
rK   Údarwinc                   @  sD   e Zd ZdZdddœZejddddœd	d
„ƒZddddœdd„ZdS )Ú
UnixViewerr    r   TrA   r)   r   útuple[str, str]r*   c                 K  s   d S )Nr   rC   r   r   r   Úget_command_exÉ   s    zUnixViewer.get_command_exc                 K  s(   | j |fi |¤Žd }|› dt|ƒ› �S )Nr   rM   )r\   r   rN   r   r   r   r.   Í   s    zUnixViewer.get_commandN)	r;   r<   r=   r"   r   ÚabcÚabstractmethodr\   r.   r   r   r   r   rZ   Å   s
   
rZ   c                   @  s4   e Zd ZdZddddœdd„Zdddd	œd
d„ZdS )Ú	XDGViewerz3
    The freedesktop.org ``xdg-open`` command.
    r)   r   r[   r*   c                 K  s   d }}||fS )Núxdg-openr   )r%   r+   r   rO   rV   r   r   r   r\   ×   s    zXDGViewer.get_command_exr   r3   c                 K  s"   t j |¡st‚t d|g¡ dS )r5   r`   r   ©r6   r4   r7   r8   rF   rG   r:   r   r   r   r1   Û   s    zXDGViewer.show_fileN©r;   r<   r=   r>   r\   r1   r   r   r   r   r_   Ò   s   r_   c                   @  s8   e Zd ZdZddddddœdd	„Zddd
dœdd„ZdS )ÚDisplayViewerz`
    The ImageMagick ``display`` command.
    This viewer supports the ``title`` parameter.
    Nr)   r   r   r[   ©r+   r   r   r   c                 K  s&   d }}|r|dt |ƒ› �7 }||fS )NÚdisplayz -title r   ©r%   r+   r   r   rO   rV   r   r   r   r\   ë   s    zDisplayViewer.get_command_exr   r3   c                 K  sH   t j |¡st‚dg}| d¡}|r0|d|g7 }| |¡ t |¡ dS )r5   re   r   z-titler   ©r6   r4   r7   r8   Úgetr   rF   rG   ©r%   r4   r   Úargsr   r   r   r   r1   ó   s    


zDisplayViewer.show_file)Nrb   r   r   r   r   rc   å   s    ÿrc   c                   @  s4   e Zd ZdZddddœdd„Zdddd	œd
d„ZdS )ÚGmDisplayViewerz*The GraphicsMagick ``gm display`` command.r)   r   r[   r*   c                 K  s   d}d}||fS )NÚgmz
gm displayr   ©r%   r+   r   rV   rO   r   r   r   r\     s    zGmDisplayViewer.get_command_exr   r3   c                 K  s$   t j |¡st‚t dd|g¡ dS )r5   rl   re   r   ra   r:   r   r   r   r1     s    zGmDisplayViewer.show_fileNrb   r   r   r   r   rk     s   rk   c                   @  s4   e Zd ZdZddddœdd„Zdddd	œd
d„ZdS )Ú	EogViewerz'The GNOME Image Viewer ``eog`` command.r)   r   r[   r*   c                 K  s   d}d}||fS )NÚeogzeog -nr   rm   r   r   r   r\     s    zEogViewer.get_command_exr   r3   c                 K  s$   t j |¡st‚t dd|g¡ dS )r5   ro   z-nr   ra   r:   r   r   r   r1     s    zEogViewer.show_fileNrb   r   r   r   r   rn     s   rn   c                   @  s8   e Zd ZdZddddddœdd	„Zddd
dœdd„ZdS )ÚXVViewerzX
    The X Viewer ``xv`` command.
    This viewer supports the ``title`` parameter.
    Nr)   r   r   r[   rd   c                 K  s&   d }}|r|dt |ƒ› �7 }||fS )NÚxvz -name r   rf   r   r   r   r\   -  s    zXVViewer.get_command_exr   r3   c                 K  sH   t j |¡st‚dg}| d¡}|r0|d|g7 }| |¡ t |¡ dS )r5   rq   r   z-namer   rg   ri   r   r   r   r1   7  s    


zXVViewer.show_file)Nrb   r   r   r   r   rp   '  s    ÿ
rp   )rJ   rY   r`   re   rl   ro   rq   c                   @  s"   e Zd ZdZddddœdd„ZdS )	ÚIPythonViewerz!The viewer for IPython frontends.r   r   r   r   c                 K  s   t |ƒ dS )Nr   )Úipython_displayr2   r   r   r   r$   W  s    zIPythonViewer.show_imageN)r;   r<   r=   r>   r$   r   r   r   r   rr   T  s   rr   )re   Ú__main__é   z.Syntax: python3 ImageShow.py imagefile [title])r   )N)(Ú
__future__r   r]   r6   rW   rF   rT   Úshlexr   Útypingr   Ú r   r   r   r   r   r@   ÚplatformrK   ÚABCrZ   r_   rc   rk   rn   rp   rX   rr   ÚIPython.displayre   rs   ÚImportErrorr;   ÚlenÚargvÚprintÚexitrP   Zimr   r   r   r   Ú<module>   s^   =
#
 
