
    h'              	      n   S SK Jr  S SKrS SKrS SKrS SKrS SKrS SKJr  S SK	J
r
  SSKJr  / rS)S*S jjrS+S,S jjr " S	 S
5      r " S S\5      r\R$                  S:X  a  \" \5         " S S\5      r\R$                  S:X  a  \" \5         " S S\R(                  \5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r\R$                  S;  a  \R6                  " S5      (       a  \" \5        \R6                  " S5      (       a  \" \5        \R6                  " S 5      (       a  \" \5        \R6                  " S!5      (       a  \" \5        \R6                  " S"5      (       a  \" \5         " S# S$\5      r S S%KJr  \" \5        \!S&:X  at  \"" \RF                  5      S':  a  \$" S(5        \RJ                  " 5         \RL                  " \RF                  S   5       r'\$" \" \'/\RF                  S'S Q76 5        SSS5        gg! \  a     Nf = f! , (       d  f       g= f)-    )annotationsNquote)Any   )Imagec                    [        U [        5      (       a  [        U [        5      (       a  U " 5       n US:  a  [        R                  U 5        g[        R                  SU 5        g)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     ?/var/www/html/env/lib/python3.13/site-packages/PIL/ImageShow.pyregisterr      sE     &$Jvv$>$>qy6"    c                V    [          H  nUR                  " U 4SU0UD6(       d  M    g   g)z
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/     ;;u5E5W55  r   c                  v    \ rS rSr% SrSS jrSrS\S'    0 rS\S'    SS	 jr	SS
 jr
SS jrSS jrSS jrSrg)r   B   zBase class for viewers.r   c                
   UR                   S;   da  U R                  S:X  a  UR                   S;   dA  [        R                  " UR                   5      nUR                   U:w  a  UR	                  U5      nU R
                  " U40 UD6$ )zk
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   Viewer.showG   si     JJ-'u$~)E$$UZZ0DzzT!d+u000r   N
str | Noner#   zdict[str, Any]c                    U R                   $ )z3Return format name, or ``None`` to save as PGM/PPM.)r#   r'   r   s     r   
get_formatViewer.get_format^   s    {{r   c                    Sn[        U5      e)zR
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_commandViewer.get_commandb   s    
 +!#&&r   c                \    UR                   " SSU R                  U5      0U R                  D6$ )z+Save to temporary file and return filename.r#    )_dumpr-   r   r,   s     r   
save_imageViewer.save_imagej   s&    {{I$//%"8IDLLIIr   c                F    U R                   " U R                  U5      40 UD6$ )zDisplay the given image.)	show_filer8   r'   r   r   s      r   r&   Viewer.show_imagen   s    ~~dooe4@@@r   c                    [         R                  R                  U5      (       d  [        e[         R                  " U R
                  " U40 UD65        g)
Display given file.
r   )ospathexistsFileNotFoundErrorsystemr3   r'   rA   r   s      r   r;   Viewer.show_filer   s<     ww~~d####
		$""43734r   r6   r   Image.Imager   r   returnint)r   rH   rI   r*   r1   strr   r   rI   rL   )r   rH   rI   rL   rA   rL   r   r   rI   rJ   )__name__
__module____qualname____firstlineno____doc__r   r#   __annotations__r   r-   r3   r8   r&   r;   __static_attributes__r6   r   r   r   r   B   sA    !1$ FJ/ G^ 7'JAr   r   c                  :    \ rS rSrSrSrSSS.rSS jrSS jrS	r	g
)WindowsViewer   zNThe default viewer on Windows is the default system application for PNG files.r    r   Tcompress_levelsave_allc                    SU SU S3$ )Nzstart "Pillow" /WAIT "z)" && ping -n 4 127.0.0.1 >NUL && del /f ""r6   r'   r1   r   s      r   r3   WindowsViewer.get_command   s    $TF +q"	
r   c                    [         R                  R                  U5      (       d  [        e[        R
                  " U R                  " U40 UD6S[        [        S5      S9  g)r?   TCREATE_NO_WINDOW)shellcreationflagsr   )r@   rA   rB   rC   
subprocessPopenr3   getattrrE   s      r   r;   WindowsViewer.show_file   sQ     ww~~d####T-W-!*.@A	

 r   r6   NrK   rM   
rN   rO   rP   rQ   rR   r#   r   r3   r;   rT   r6   r   r   rV   rV      s    XF!"5G
r   rV   win32c                  :    \ rS rSrSrSrSSS.rSS jrSS jrS	r	g
)	MacViewer   z2The default viewer on macOS using ``Preview.app``.r    r   TrX   c                F    SnSU S[        U5       S[        U5       S3nU$ )Nzopen -a Preview.app( z; sleep 20; rm -f z)&r   r'   r1   r   commands       r   r3   MacViewer.get_command   s1     (gYad},>uT{m2Nr   c                (   [         R                  R                  U5      (       d  [        e[        R
                  " SSSU/5        [        R                  =(       d    [        R                  " S5      nU(       a  [        R                  " USSU/5        g)r?   openz-azPreview.apppython3z-cz<import os, sys, time; time.sleep(20); os.remove(sys.argv[1])r   )r@   rA   rB   rC   rc   callsys
executableshutilwhichrd   )r'   rA   r   rw   s       r   r;   MacViewer.show_file   sp     ww~~d####}d;<^^>v||I'>
R	 r   r6   NrK   rM   rg   r6   r   r   rj   rj      s    <F!"5Gr   rj   darwinc                  T    \ rS rSrSrSSS.r\R                  S
S j5       rSS jr	Sr
g	)
UnixViewer   r    r   TrX   c                    g Nr6   r]   s      r   get_command_exUnixViewer.get_command_ex   s    r   c                N    U R                   " U40 UD6S   nU S[        U5       3$ )Nr   rn   )r   r   ro   s       r   r3   UnixViewer.get_command   s1    %%d6g6q9!E$K=))r   r6   Nr1   rL   r   r   rI   tuple[str, str]rK   )rN   rO   rP   rQ   r#   r   abcabstractmethodr   r3   rT   r6   r   r   r}   r}      s.    F!"5G *r   r}   c                  ,    \ rS rSrSrSS jrSS jrSrg)		XDGViewer   z+
The freedesktop.org ``xdg-open`` command.
c                    S=p4X44$ )Nxdg-openr6   )r'   r1   r   rp   rw   s        r   r   XDGViewer.get_command_ex   s    ))""r   c                    [         R                  R                  U5      (       d  [        e[        R
                  " SU/5        g)r?   r   r   r@   rA   rB   rC   rc   rd   rE   s      r   r;   XDGViewer.show_file   s3     ww~~d####*d+,r   r6   Nr   rM   rN   rO   rP   rQ   rR   r   r;   rT   r6   r   r   r   r      s    #r   r   c                  @    \ rS rSrSr S       SS jjrS	S jrSrg)
DisplayViewer   zT
The ImageMagick ``display`` command.
This viewer supports the ``title`` parameter.
Nc                >    S=pEU(       a  US[        U5       3-  nXE4$ )Ndisplayz -title r   r'   r1   r   r   rp   rw   s         r   r   DisplayViewer.get_command_ex   s-      )(%,00G""r   c                    [         R                  R                  U5      (       d  [        eS/nUR	                  S5      nU(       a  USU/-  nUR                  U5        [        R                  " U5        g)r?   r   r   z-titler   r@   rA   rB   rC   getr   rc   rd   r'   rA   r   argsr   s        r   r;   DisplayViewer.show_file   sa     ww~~d####{G$Xu%%DDr   r6   r   r1   rL   r   r*   r   r   rI   r   rM   r   r6   r   r   r   r      s6     .2## *#>A#	#r   r   c                  ,    \ rS rSrSrSS jrSS jrSrg)	GmDisplayVieweri  z*The GraphicsMagick ``gm display`` command.c                    SnSnXC4$ )Ngmz
gm displayr6   r'   r1   r   rw   rp   s        r   r   GmDisplayViewer.get_command_ex  s    
""r   c                    [         R                  R                  U5      (       d  [        e[        R
                  " SSU/5        g)r?   r   r   r   r   rE   s      r   r;   GmDisplayViewer.show_file	  s5     ww~~d####$	401r   r6   Nr   rM   r   r6   r   r   r   r     s    4#
r   r   c                  ,    \ rS rSrSrSS jrSS jrSrg)		EogVieweri  z'The GNOME Image Viewer ``eog`` command.c                    SnSnXC4$ )Neogzeog -nr6   r   s        r   r   EogViewer.get_command_ex  s    
""r   c                    [         R                  R                  U5      (       d  [        e[        R
                  " SSU/5        g)r?   r   z-nr   r   rE   s      r   r;   EogViewer.show_file  s5     ww~~d####%t,-r   r6   Nr   rM   r   r6   r   r   r   r     s    1#
r   r   c                  @    \ rS rSrSr S       SS jjrS	S jrSrg)
XVVieweri%  zL
The X Viewer ``xv`` command.
This viewer supports the ``title`` parameter.
Nc                >    S=pEU(       a  US[        U5       3-  nXE4$ )Nxvz -name r   r   s         r   r   XVViewer.get_command_ex+  s-    
  $#u//G""r   c                    [         R                  R                  U5      (       d  [        eS/nUR	                  S5      nU(       a  USU/-  nUR                  U5        [        R                  " U5        g)r?   r   r   z-namer   r   r   s        r   r;   XVViewer.show_file5  sa     ww~~d####vG$We$$DDr   r6   r   r   rM   r   r6   r   r   r   r   %  s6     .2## *#>A#	#r   r   )rh   r{   r   r   r   r   r   c                  "    \ rS rSrSrSS jrSrg)IPythonVieweriR  z!The viewer for IPython frontends.c                    [        U5        g)Nr   )ipython_displayr<   s      r   r&   IPythonViewer.show_imageU  s    r   r6   NrG   )rN   rO   rP   rQ   rR   r&   rT   r6   r   r   r   r   R  s
    +r   r   )r   __main__   z.Syntax: python3 ImageShow.py imagefile [title])r   )r   ztype[Viewer] | Viewerr   rJ   rI   Noner   )r   rH   r   r*   r   r   rI   bool)(
__future__r   r   r@   rx   rc   rv   shlexr   typingr    r   r   r   r   r   rV   platformrj   ABCr}   r   r   r   r   r   ry   r   IPython.displayr   r   ImportErrorrN   lenargvprintexitrs   imr6   r   r   <module>r      s   # 
 	   
   #,7 7zF 6 <<7] B <<8Y
*& 
*
 &J <j $
 $z @ <<**||J||I||D!||E||DF : ] z
388}q>?
	CHHQK	 Bd2%%& 
!	    		 
!	 s   H 3H&H#"H#&
H4