
    :h'              	         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)d*dZd+d,dZ G d	 d
      Z G d de      Zej$                  dk(  r ee        G d de      Zej$                  dk(  r ee        G d dej(                  e      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Zej$                  dvr ej6                  d      r ee        ej6                  d      r ee        ej6                  d       r ee        ej6                  d!      r ee        ej6                  d"      r ee        G d# d$e      Z	 d d%lmZ  ee       e!d&k(  rs e"ejF                        d'k  r e$d(        ejJ                           ejL                  ejF                  d         5 Z' e$ ee'gejF                  d'd         ddd       yy# e $ r Y w xY w# 1 sw Y   yxY w)-    )annotationsNquote)Any   )Imagec                    t        | t              rt        | t              r |        } |dkD  rt        j                  |        yt        j                  d|        y)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)viewerorders     K/var/www/urcfiles/bundle/venv/lib/python3.12/site-packages/PIL/ImageShow.pyregisterr      s?     &$Jvv$>qy6"    c                H    t         D ]  } |j                  | fd|i|s y y)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.
    titleTF)r   show)imager   optionsr   s       r   r   r   3   s.     6;;u5E5W5  r   c                  b    e Zd ZU dZddZdZded<   	 i Zded<   	 ddZdd	Z	dd
Z
ddZddZy)r   zBase class for viewers.r   c                    |j                   dv s\| j                  dk(  r|j                   dv s?t        j                  |j                         }|j                   |k7  r|j	                  |      } | 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   bases       r   r   zViewer.showG   sk     JJ-'u$~)E$$UZZ0DzzT!d+tu000r   N
str | Noner"   zdict[str, Any]c                    | j                   S )z3Return format name, or ``None`` to save as PGM/PPM.)r"   r&   r   s     r   
get_formatzViewer.get_format^   s    {{r   c                    d}t        |      )zj
        Returns the command used to display the file.
        Not implemented in the base class.
        zunavailable in base viewer)NotImplementedError)r&   filer   msgs       r   get_commandzViewer.get_commandb   s    
 +!#&&r   c                \     |j                   dd| j                  |      i| j                  S )z+Save to temporary file and return filename.r"    )_dumpr+   r   r*   s     r   
save_imagezViewer.save_imagej   s(    u{{I$//%"8IDLLIIr   c                F     | j                   | j                  |      fi |S )zDisplay the given image.)	show_filer4   r&   r   r   s      r   r%   zViewer.show_imagen   s!    t~~dooe4@@@r   c                    t         j                  j                  |      st        t        j                   | j
                  |fi |       y)%
        Display given file.
        r   )ospathexistsFileNotFoundErrorsystemr0   r&   r;   r   s      r   r6   zViewer.show_filer   s<     ww~~d###
		"$""43734r   r   Image.Imager   r   returnint)r   rA   rB   r(   r.   strr   r   rB   rE   )r   rA   rB   rE   r;   rE   r   r   rB   rC   )__name__
__module____qualname____doc__r   r"   __annotations__r   r+   r0   r4   r%   r6   r2   r   r   r   r   B   sA    !1$ FJ/ G^ 7'JAr   r   c                  .    e Zd ZdZdZdddZd	dZd
dZy)WindowsViewerzNThe default viewer on Windows is the default system application for PNG files.r   r   Tcompress_levelsave_allc                    d| d| dS )Nzstart "Pillow" /WAIT "z)" && ping -n 4 127.0.0.1 >NUL && del /f ""r2   r&   r.   r   s      r   r0   zWindowsViewer.get_command   s    $TF +q"	
r   c                    t         j                  j                  |      st        t	        j
                   | j                  |fi |dt        t        d             y)r9   TCREATE_NO_WINDOW)shellcreationflagsr   )r:   r;   r<   r=   
subprocessPopenr0   getattrr?   s      r   r6   zWindowsViewer.show_file   sP     ww~~d###DT-W-!*.@A	

 r   NrD   rF   rG   rH   rI   rJ   r"   r   r0   r6   r2   r   r   rM   rM      s    XF!"5G
r   rM   win32c                  .    e Zd ZdZdZdddZd	dZd
dZy)	MacViewerz2The default viewer on macOS using ``Preview.app``.r   r   TrN   c                F    d}d| dt        |       dt        |       d}|S )Nzopen -a Preview.app( z; sleep 20; rm -f z)&r   r&   r.   r   commands       r   r0   zMacViewer.get_command   s1     (gYad},>uT{m2Nr   c                   t         j                  j                  |      st        t	        j
                  ddd|g       t        j                  xs t        j                  d      }|rt	        j                  |dd|g       y)r9   openz-azPreview.apppython3z-cz<import os, sys, time; time.sleep(20); os.remove(sys.argv[1])r   )r:   r;   r<   r=   rX   callsys
executableshutilwhichrY   )r&   r;   r   ri   s       r   r6   zMacViewer.show_file   sm     ww~~d###}d;<^^>v||I'>
R	 r   NrD   rF   r[   r2   r   r   r^   r^      s    <F!"5Gr   r^   darwinc                  H    e Zd ZdZdddZej                  dd       Zd	dZy)

UnixViewerr   r   TrN   c                     y Nr2   rS   s      r   get_command_exzUnixViewer.get_command_ex   s    r   c                N     | j                   |fi |d   }| dt        |       S )Nr   ra   )rq   r   rb   s       r   r0   zUnixViewer.get_command   s3    %$%%d6g6q9!E$K=))r   Nr.   rE   r   r   rB   tuple[str, str]rD   )	rG   rH   rI   r"   r   abcabstractmethodrq   r0   r2   r   r   rn   rn      s.    F!"5G *r   rn   c                       e Zd ZdZddZddZy)	XDGViewerz3
    The freedesktop.org ``xdg-open`` command.
    c                    dx}}||fS )Nxdg-openr2   )r&   r.   r   rc   ri   s        r   rq   zXDGViewer.get_command_ex   s    ))*
""r   c                |    t         j                  j                  |      st        t	        j
                  d|g       y)r9   rz   r   r:   r;   r<   r=   rX   rY   r?   s      r   r6   zXDGViewer.show_file   s0     ww~~d###*d+,r   Nrs   rF   rG   rH   rI   rJ   rq   r6   r2   r   r   rx   rx      s    #r   rx   c                  2    e Zd ZdZ	 d	 	 	 	 	 	 	 ddZddZy)DisplayViewerz`
    The ImageMagick ``display`` command.
    This viewer supports the ``title`` parameter.
    Nc                8    dx}}|r|dt        |       z  }||fS )Ndisplayz -title r   r&   r.   r   r   rc   ri   s         r   rq   zDisplayViewer.get_command_ex   s1      )(*%,00G
""r   c                    t         j                  j                  |      st        dg}|j	                  d      }|r|d|gz  }|j                  |       t        j                  |       y)r9   r   r   z-titler   r:   r;   r<   r=   getr   rX   rY   r&   r;   r   argsr   s        r   r6   zDisplayViewer.show_file   s^     ww~~d###{G$Xu%%DDr   rp   r.   rE   r   r(   r   r   rB   rt   rF   r}   r2   r   r   r   r      s6     .2## *#>A#	#r   r   c                       e Zd ZdZddZddZy)GmDisplayViewerz*The GraphicsMagick ``gm display`` command.c                    d}d}||fS )Ngmz
gm displayr2   r&   r.   r   ri   rc   s        r   rq   zGmDisplayViewer.get_command_ex  s    

""r   c                ~    t         j                  j                  |      st        t	        j
                  dd|g       y)r9   r   r   r   r|   r?   s      r   r6   zGmDisplayViewer.show_file	  s2     ww~~d###$	401r   Nrs   rF   r}   r2   r   r   r   r     s    4#
r   r   c                       e Zd ZdZddZddZy)	EogViewerz'The GNOME Image Viewer ``eog`` command.c                    d}d}||fS )Neogzeog -nr2   r   s        r   rq   zEogViewer.get_command_ex  s    

""r   c                ~    t         j                  j                  |      st        t	        j
                  dd|g       y)r9   r   z-nr   r|   r?   s      r   r6   zEogViewer.show_file  s2     ww~~d###%t,-r   Nrs   rF   r}   r2   r   r   r   r     s    1#
r   r   c                  2    e Zd ZdZ	 d	 	 	 	 	 	 	 ddZddZy)XVViewerzX
    The X Viewer ``xv`` command.
    This viewer supports the ``title`` parameter.
    Nc                8    dx}}|r|dt        |       z  }||fS )Nxvz -name r   r   s         r   rq   zXVViewer.get_command_ex+  s1    
  $#*u//G
""r   c                    t         j                  j                  |      st        dg}|j	                  d      }|r|d|gz  }|j                  |       t        j                  |       y)r9   r   r   z-namer   r   r   s        r   r6   zXVViewer.show_file5  s^     ww~~d###vG$We$$DDr   rp   r   rF   r}   r2   r   r   r   r   %  s6     .2## *#>A#	#r   r   )r\   rl   rz   r   r   r   r   c                      e Zd ZdZddZy)IPythonViewerz!The viewer for IPython frontends.c                    t        |       y)Nr   )ipython_displayr7   s      r   r%   zIPythonViewer.show_imageU  s    r   Nr@   )rG   rH   rI   rJ   r%   r2   r   r   r   r   R  s
    +r   r   )r   __main__   z.Syntax: python3 ImageShow.py imagefile [title])r   )r   ztype[Viewer] | Viewerr   rC   rB   Nonerp   )r   rA   r   r(   r   r   rB   bool)(
__future__r   ru   r:   rj   rX   rh   shlexr   typingr    r   r   r   r   r   rM   platformr^   ABCrn   rx   r   r   r   r   rk   r   IPython.displayr   r   ImportErrorrG   lenargvprintexitre   imr2   r   r   <module>r      s   # 
 	   
   #,7 7zF 6 <<7] B <<8Y
*& 
*
 &J <j $
 $z @ <<**v||Jv||Iv||D!v||Ev||DF : ] z
388}q>?
	CHHQK	 Bd2%%& 
!	    		 
!	 s   0G7 H7G?>G?H