3

h                 @   s  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 g Z	d%ddZ
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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'krVejdre
e ejdr.e
e ejdrBe
e ejdrVe
e G dd  d eZyd d!lmZ W n ek
r   Y n
X e
e ed"kreejd#k red$ ej  ej ejd "Z!eee!fejd#d   W dQ R X dS )(    N)quote)Image   c             C   sN   yt | tr|  } W n tk
r(   Y nX |dkr>tj|  ntjd|  dS )a  
    The :py:func:`register` function is used to register additional viewers.

    :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order r   M/var/www/html/enquirykeeper_venv/lib/python3.6/site-packages/PIL/ImageShow.pyregister   s    	

r   c             K   s,   x&t D ]}|j| fd|i|rdS qW 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.
    titler   r   )r   show)imager   optionsr   r   r   r   r   .   s    	
r   c               @   sH   e Zd ZdZdd ZdZi Zdd Zdd Zd	d
 Z	dd Z
dd ZdS )r   zBase class for viewers.c             K   sL   |j dkp| jdko|j dks>tj|j }|j |kr>|j|}| j|f|S )z
        The main function for displaying an image.
        Converts the given image to the target format and displays it.
        1RGBAPNGI;16LA)r   r   )r   r   )modeformatr   Zgetmodebaseconvert
show_image)selfr   r   baser   r   r   r   B   s    


zViewer.showNc             C   s   | j S )z3Return format name, or ``None`` to save as PGM/PPM.)r   )r   r   r   r   r   
get_formatY   s    zViewer.get_formatc             K   s   t dS )zj
        Returns the command used to display the file.
        Not implemented in the base class.
        N)NotImplementedError)r   filer   r   r   r   get_command]   s    zViewer.get_commandc             C   s   |j f d| j|i| jS )z+Save to temporary file and return filename.r   )_dumpr   r   )r   r   r   r   r   
save_imaged   s    zViewer.save_imagec             K   s   | j | j|f|S )zDisplay the given image.)	show_filer$   )r   r   r   r   r   r   r   h   s    zViewer.show_imagec             K   s   t j| j|f| dS )zDisplay the given file.r   )ossystemr"   )r   r!   r   r   r   r   r%   l   s    zViewer.show_file)__name__
__module____qualname____doc__r   r   r   r   r"   r$   r   r%   r   r   r   r   r   =   s   r   c               @   s$   e Zd ZdZdZddiZdd ZdS )WindowsViewerzNThe default viewer on Windows is the default system application for PNG files.r   compress_levelr   c             K   s   d| d| dS )Nzstart "Pillow" /WAIT "z)" && ping -n 2 127.0.0.1 >NUL && del /f ""r   )r   r!   r   r   r   r   r"   {   s    zWindowsViewer.get_commandN)r(   r)   r*   r+   r   r   r"   r   r   r   r   r,   u   s   r,   win32c               @   s,   e Zd ZdZdZddiZdd Zdd Zd	S )
	MacViewerz2The default viewer on macOS using ``Preview.app``.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_commandc             K   sb   t j \}}tj|d}|j| W dQ R X t|}tjdgd|d W dQ R X tj| dS )zDisplay given filewNz7im=$(cat); open -a Preview.app $im; sleep 20; rm -f $imT)shellstdinr   )	tempfilemkstempr&   fdopenwriteopen
subprocessPopenremove)r   r!   r   fdpathfr   r   r   r%      s    

zMacViewer.show_fileN)r(   r)   r*   r+   r   r   r"   r%   r   r   r   r   r0      s
   r0   darwinc               @   s(   e Zd ZdZddiZdd Zdd ZdS )	
UnixViewerr   r-   r   c             K   s2   | j |f|d }d| dt| dt| dS )Nr   r1   r2   z; rm -f z)&)get_command_exr   )r   r!   r   r3   r   r   r   r"      s    zUnixViewer.get_commandc             K   s|   t j \}}tj|d}|j| W dQ R X t|2}| j|f|d }tjd| d gd|d W dQ R X tj	| dS )	zDisplay given filer4   Nr   z
im=$(cat);z $im; rm -f $imT)r5   r6   r   )
r7   r8   r&   r9   r:   r;   rD   r<   r=   r>   )r   r!   r   r?   r@   rA   r3   r   r   r   r%      s    
 
zUnixViewer.show_fileN)r(   r)   r*   r   r   r"   r%   r   r   r   r   rC      s   rC   c               @   s   e Zd ZdZdd ZdS )DisplayViewerz$The ImageMagick ``display`` command.c             K   s   d }}||fS )Ndisplayr   )r   r!   r   r3   
executabler   r   r   rD      s    zDisplayViewer.get_command_exN)r(   r)   r*   r+   rD   r   r   r   r   rE      s   rE   c               @   s   e Zd ZdZdd ZdS )GmDisplayViewerz*The GraphicsMagick ``gm display`` command.c             K   s   d}d}||fS )Ngmz
gm displayr   )r   r!   r   rG   r3   r   r   r   rD      s    zGmDisplayViewer.get_command_exN)r(   r)   r*   r+   rD   r   r   r   r   rH      s   rH   c               @   s   e Zd ZdZdd ZdS )	EogViewerz'The GNOME Image Viewer ``eog`` command.c             K   s   d}d}||fS )Neogzeog -nr   )r   r!   r   rG   r3   r   r   r   rD      s    zEogViewer.get_command_exN)r(   r)   r*   r+   rD   r   r   r   r   rJ      s   rJ   c               @   s   e Zd ZdZdddZdS )XVViewerzX
    The X Viewer ``xv`` command.
    This viewer supports the ``title`` parameter.
    Nc             K   s&   d }}|r|dt | 7 }||fS )Nxvz -name )r   )r   r!   r   r   r3   rG   r   r   r   rD      s    zXVViewer.get_command_ex)N)r(   r)   r*   r+   rD   r   r   r   r   rL      s   rL   rF   rI   rK   rM   c               @   s   e Zd ZdZdd ZdS )IPythonViewerz!The viewer for IPython frontends.c             K   s   t | dS )Nr   )ipython_display)r   r   r   r   r   r   r      s    zIPythonViewer.show_imageN)r(   r)   r*   r+   r   r   r   r   r   rN      s   rN   )rF   __main__   z.Syntax: python3 ImageShow.py imagefile [title])r   )N)r/   rB   )"r&   shutilr<   sysr7   shlexr   ZPILr   r   r   r   r   r,   platformr0   rC   rE   rH   rJ   rL   whichrN   ZIPython.displayrF   rO   ImportErrorr(   lenargvprintexitr;   Zimr   r   r   r   <module>   sT   

8

		
