o
     PjM(                     @  sV  U 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ded< d:d;ddZd<d=ddZG dd dZG dd deZejdkrWee G dd  d eZejd!krhe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/ree ed0ree ed1ree ed2ree ed3ree G d4d5 d5eZzd d6lmZ  W n	 e!y   Y nw ee e"d7kr)e#ej$d8k re%d9 e&  e'ej$d Z(e%ee(gej$d8d R   W d   dS 1 s"w   Y  dS dS )>    )annotationsNquote)Any   )Imagezlist[Viewer]_viewersviewertype[Viewer] | ViewerorderintreturnNonec                 C  s@   t | trt| tr|  } |dkrt|  dS 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Viewerr   appendinsert)r	   r    r   B/home/thesage/.local/lib/python3.10/site-packages/PIL/ImageShow.pyregister   s
   r   imageImage.Imagetitle
str | Noneoptionsr   boolc                 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                   @  st   e Zd ZU dZddd	Zd
Zded< 	 i Zded< 	 dddZd ddZ	d!ddZ
dddZd"ddZ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.
        )1RGBAPNG)zI;16LA)modeformatr   getmodebaseconvert
show_image)selfr   r   baser   r   r   r   G   s   


zViewer.showNr   r$   zdict[str, Any]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filestrc                 K  s   d}t |)zj
        Returns the command used to display the file.
        Not implemented in the base class.
        zunavailable in base viewer)NotImplementedErrorr(   r,   r   msgr   r   r   get_commandb   s   zViewer.get_commandc                 C  s   |j dd| |i| jS )z+Save to temporary file and return filename.r$   Nr   )_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_filer3   r(   r   r   r   r   r   r'   n   s   zViewer.show_imagepathc                 K  s,   t j|stt | j|fi | dS )%
        Display given file.
        r   )osr6   existsFileNotFoundErrorsystemr1   r(   r6   r   r   r   r   r4   r   s   zViewer.show_filer   c                 C  sJ   t tddo
ttd}| rtjptd}|r#t|dd|g d S d S )NfrozenF_MEIPASSpython3z-cz<import os, sys, time; time.sleep(20); os.remove(sys.argv[1]))getattrsyshasattr
executableshutilwhich
subprocessPopen)r(   r6   pyinstallerrC   r   r   r   _remove_path_after_delay{   s   zViewer._remove_path_after_delayr   r   r   r   r   r   )r   r   r   r   r,   r-   r   r   r   r-   )r   r   r   r-   r6   r-   r   r   r   r   )r6   r-   r   r   )__name__
__module____qualname____doc__r   r$   __annotations__r   r+   r1   r3   r'   r4   rI   r   r   r   r   r   B   s   
 





	r   c                   @  2   e Zd ZdZdZdddZdddZdddZdS )WindowsViewerzNThe default viewer on Windows is the default system application for PNG files.r!   r   Tcompress_levelsave_allr,   r-   r   r   r   c                 K  s2   d|v r
d}t ||dd}d| d| dS )N"z.Windows filenames cannot contain double quotes%z"%"zstart "Pillow" /WAIT "z)" && ping -n 4 127.0.0.1 >NUL && del /f ")
ValueErrorreplacer/   r   r   r   r1      s   zWindowsViewer.get_commandr6   r   c                 K  s2   t j|sttjdkrt | | | dS )r7   win32r   )r8   r6   r9   r:   rA   platform	startfilerI   r<   r   r   r   r4      s   


zWindowsViewer.show_fileNrK   rL   rM   rN   rO   rP   r$   r   r1   r4   r   r   r   r   rS      s    

rS   r[   c                   @  rR   )	MacViewerz2The default viewer on macOS using ``Preview.app``.r!   r   TrT   r,   r-   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   r1      s    zMacViewer.get_commandr6   r   c                 K  s0   t j|sttddd|g | | dS )r7   openz-azPreview.appr   )r8   r6   r9   r:   rF   callrI   r<   r   r   r   r4      s
   
zMacViewer.show_fileNrK   rL   r^   r   r   r   r   r_      s    

r_   darwinc                   @  s4   e Zd ZdZdddZejdddZdddZdS )
UnixViewerr!   r   TrT   r,   r-   r   r   r   tuple[str, str]c                 K  s   d S Nr   )r(   r,   r   r   r   r   get_command_ex   s   zUnixViewer.get_command_exc                 K  s(   | j |fi |d }| dt| S )Nr   ra   )rj   r   rb   r   r   r   r1      s   zUnixViewer.get_commandNr,   r-   r   r   r   rh   rK   )	rM   rN   rO   r$   r   abcabstractmethodrj   r1   r   r   r   r   rg      s    
rg   c                   @  $   e Zd ZdZddd	ZdddZdS )	XDGViewerz3
    The freedesktop.org ``xdg-open`` command.
    r,   r-   r   r   r   rh   c                 K  s   d }}||fS )Nxdg-openr   )r(   r,   r   rc   rC   r   r   r   rj      s   zXDGViewer.get_command_exr6   r   c                 K  s"   t j|sttd|g dS )r7   rp   r   r8   r6   r9   r:   rF   rG   r<   r   r   r   r4      s   zXDGViewer.show_fileNrk   rL   rM   rN   rO   rP   rj   r4   r   r   r   r   ro      s    
ro   c                   @  (   e Zd ZdZ	ddddZdddZdS )DisplayViewerz`
    The ImageMagick ``display`` command.
    This viewer supports the ``title`` parameter.
    Nr,   r-   r   r   r   r   r   rh   c                 K  &   d }}|r|dt | 7 }||fS )Ndisplayz -title r   r(   r,   r   r   rc   rC   r   r   r   rj      s   zDisplayViewer.get_command_exr6   r   c                 K  H   t j|stdg}|d}|r|d|g7 }|| t| dS )r7   rv   r   z-titler   r8   r6   r9   r:   getr   rF   rG   r(   r6   r   argsr   r   r   r   r4         


zDisplayViewer.show_fileri   r,   r-   r   r   r   r   r   rh   rL   rr   r   r   r   r   rt      s
    rt   c                   @  rn   )GmDisplayViewerz*The GraphicsMagick ``gm display`` command.r,   r-   r   r   r   rh   c                 K     d}d}||fS )Ngmz
gm displayr   r(   r,   r   rC   rc   r   r   r   rj        zGmDisplayViewer.get_command_exr6   r   c                 K  $   t j|sttdd|g dS )r7   r   rv   r   rq   r<   r   r   r   r4        zGmDisplayViewer.show_fileNrk   rL   rr   r   r   r   r   r         
r   c                   @  rn   )	EogViewerz'The GNOME Image Viewer ``eog`` command.r,   r-   r   r   r   rh   c                 K  r   )Neogzeog -nr   r   r   r   r   rj     r   zEogViewer.get_command_exr6   r   c                 K  r   )r7   r   z-nr   rq   r<   r   r   r   r4   "  r   zEogViewer.show_fileNrk   rL   rr   r   r   r   r   r     r   r   c                   @  rs   )XVViewerzX
    The X Viewer ``xv`` command.
    This viewer supports the ``title`` parameter.
    Nr,   r-   r   r   r   r   r   rh   c                 K  ru   )Nxvz -name r   rw   r   r   r   rj   2  s   zXVViewer.get_command_exr6   r   c                 K  rx   )r7   r   r   z-namer   ry   r{   r   r   r   r4   <  r}   zXVViewer.show_fileri   r~   rL   rr   r   r   r   r   r   ,  s
    
r   )r[   rf   rp   rv   r   r   r   c                   @  s   e Zd ZdZddd	Zd
S )IPythonViewerz!The viewer for IPython frontends.r   r   r   r   r   r   c                 K  s   t | dS )Nr   )ipython_displayr5   r   r   r   r'   \  s   zIPythonViewer.show_imageNrJ   )rM   rN   rO   rP   r'   r   r   r   r   r   Y  s    r   )rv   __main__   z.Syntax: python3 ImageShow.py imagefile [title])r   )r	   r
   r   r   r   r   ri   )r   r   r   r   r   r   r   r   ))
__future__r   rl   r8   rD   rF   rA   shlexr   typingr    r   r   rQ   r   r   r   rS   r\   r_   ABCrg   ro   rt   r   r   r   rE   r   IPython.displayrv   r   ImportErrorrM   lenargvprintexitrd   imr   r   r   r   <module>   sf   K


 





 $