
    &Tht               	          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 g Zd'dZ	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      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j*                  d      r e	e        ej*                  d      r e	e        ej*                  d      r e	e        ej*                  d      r e	e        ej*                  d       r e	e        G d! d"e      Z	 d d#lmZ  e	e       ed$k(  rs eej:                        d%k  r ed&        ej>                           ej@                  ej:                  d         5 Z! e e
e!gej:                  d%d         ddd       yy# e$ r Y w xY w# 1 sw Y   yxY w))    Nquote   )Imagec                     	 t        | t              r |        } |dkD  rt        j	                  |        yt        j                  d|        y# t        $ r Y =w xY w)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)
issubclassViewer	TypeError_viewersappendinsert)viewerorders     U/home/stella.sw7ft.com/public_html/venv/lib/python3.12/site-packages/PIL/ImageShow.pyregisterr      sO    ff%XF qy6"  s   A 	AA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   2   s3      6;;u5E5W5     c                   @    e Zd ZdZd ZdZ	 i Z	 d Zd Zd Z	d Z
d Zy)	r	   zBase class for viewers.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.showF   sk     JJ-'u$~)E$$UZZ0DzzT!d+tu000r   Nc                     | 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                     t         )zj
        Returns the command used to display the file.
        Not implemented in the base class.
        )NotImplementedErrorr#   filer   s      r   get_commandzViewer.get_commanda   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_imageh   s(    u{{I$//%"8IDLLIIr   c                 F     | j                   | j                  |      fi |S )zDisplay the given image.)	show_filer0   r#   r   r   s      r   r"   zViewer.show_imagel   s!    t~~dooe4@@@r   c                 P    t        j                   | j                  |fi |       y)%
        Display given file.
        r   )ossystemr,   r#   pathr   s      r   r2   zViewer.show_filep   s&     			"$""43734r   )__name__
__module____qualname____doc__r   r   r   r'   r,   r0   r"   r2   r.   r   r   r	   r	   A   s7    !1$ F/G7"JAr   r	   c                   $    e Zd ZdZdZdddZ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 ""r.   r*   s      r   r,   zWindowsViewer.get_command   s    $TF +q"	
r   N)r:   r;   r<   r=   r   r   r,   r.   r   r   r?   r?   {   s    XF!"5G
r   r?   win32c                   *    e Zd ZdZdZdddZd Zd Zy)		MacViewerz2The default viewer on macOS using ``Preview.app``.r   r   Tr@   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   r,   zMacViewer.get_command   s1     (gYad},>uT{m2Nr   c                     t        j                  ddd|g       t        j                  xs t	        j
                  d      }|rt        j                  |dd|g       y)r5   openz-azPreview.apppython3z-cz<import os, sys, time; time.sleep(20); os.remove(sys.argv[1])r   )
subprocesscallsys
executableshutilwhichPopen)r#   r9   r   rS   s       r   r2   zMacViewer.show_file   sW     	}d;<^^>v||I'>
R	 r   N)r:   r;   r<   r=   r   r   r,   r2   r.   r   r   rG   rG      s    <F!"5Gr   rG   darwinc                        e Zd ZdZdddZd Zy)
UnixViewerr   r   Tr@   c                 P     | j                   |fi |d   }d| dt        |       S )Nr   rI   rJ   )get_command_exr   rK   s       r   r,   zUnixViewer.get_command   s5    %$%%d6g6q97)1U4[M**r   N)r:   r;   r<   r   r   r,   r.   r   r   rY   rY      s    F!"5G+r   rY   c                       e Zd ZdZd Zd Zy)	XDGViewerz3
    The freedesktop.org ``xdg-open`` command.
    c                     dx}}||fS )Nxdg-openr.   )r#   r+   r   rL   rS   s        r   r[   zXDGViewer.get_command_ex   s    ))*
""r   c                 2    t        j                  d|g       y)r5   r_   r   rP   rV   r8   s      r   r2   zXDGViewer.show_file   s     	*d+,r   Nr:   r;   r<   r=   r[   r2   r.   r   r   r]   r]      s    #r   r]   c                       e Zd ZdZddZ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   rL   rS   s         r   r[   zDisplayViewer.get_command_ex   s/    ((*%,00G
""r   c                     dg}|j                  d      }|r|d|gz  }|j                  |       t        j                  |       y)r5   rf   r   z-titler   getr   rP   rV   r#   r9   r   argsr   s        r   r2   zDisplayViewer.show_file   sH     {G$Xu%%DDr   Nrb   r.   r   r   rd   rd      s    
#r   rd   c                       e Zd ZdZd Zd Zy)GmDisplayViewerz*The GraphicsMagick ``gm display`` command.c                     d}d}||fS )Ngmz
gm displayr.   r#   r+   r   rS   rL   s        r   r[   zGmDisplayViewer.get_command_ex   s    

""r   c                 4    t        j                  dd|g       y)r5   rq   rf   r   ra   r8   s      r   r2   zGmDisplayViewer.show_file   s     	$	401r   Nrb   r.   r   r   ro   ro      s    4#
r   ro   c                       e Zd ZdZd Zd Zy)	EogViewerz'The GNOME Image Viewer ``eog`` command.c                     d}d}||fS )Neogzeog -nr.   rr   s        r   r[   zEogViewer.get_command_ex   s    

""r   c                 4    t        j                  dd|g       y)r5   rw   z-nr   ra   r8   s      r   r2   zEogViewer.show_file   s     	%t,-r   Nrb   r.   r   r   ru   ru      s    1#
r   ru   c                       e Zd ZdZddZ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   rg   s         r   r[   zXVViewer.get_command_ex
  s1      $#*u//G
""r   c                     dg}|j                  d      }|r|d|gz  }|j                  |       t        j                  |       y)r5   r|   r   z-namer   ri   rk   s        r   r2   zXVViewer.show_file  sH     vG$We$$DDr   rm   rb   r.   r   r   rz   rz     s    
#r   rz   )rE   rW   r_   rf   rq   rw   r|   c                       e Zd ZdZd Zy)IPythonViewerz!The viewer for IPython frontends.c                     t        |       y)Nr   )ipython_displayr3   s      r   r"   zIPythonViewer.show_image0  s    r   N)r:   r;   r<   r=   r"   r.   r   r   r   r   -  s
    +r   r   )rf   __main__   z.Syntax: python3 ImageShow.py imagefile [title])r   rm   )"r6   rT   rP   rR   shlexr    r   r   r   r   r	   r?   platformrG   rY   r]   rd   ro   ru   rz   rU   r   IPython.displayrf   r   ImportErrorr:   lenargvprintexitrN   imr.   r   r   <module>r      s   
   
  #24 4t
F 
 <<7] > <<8Y+ +
 "J 4j  
  z 8 <<**v||Jv||Iv||D!v||Ev||DF : ] z
388}q>?
	CHHQK	  'Bd2%%&' '   		' 's   G 3G%G"!G"%G.