a
    hz'                     @  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ree G dd deZejdkre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red)r\ee ed*rpee ed+ree ed,ree ed-re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   ;/var/www/auris/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   ZIPython.displayre   rs   ImportErrorr;   lenargvprintexitrP   Zimr   r   r   r   <module>   s^   =
#
 
