U
    %d
                     @   sT   d Z ddlZddlZddlmZ G dd deZG dd deZG d	d
 d
eZdS )zD
PIL-based formats to take screenshots and grab from the clipboard.
    N   )Formatc                       sJ   e Zd ZdZdZdZ fddZdd Zdd	 ZG d
d de	j
Z
  ZS )BaseGrabFormatzBase format for grab formats.FNc                    s    t t| j|| t | _d S N)superr   __init__	threadingRLock_lock)selfargskwargs	__class__ 8/tmp/pip-unpacked-wheel-x84omsqu/imageio/plugins/grab.pyr      s    zBaseGrabFormat.__init__c                 C   s   dS )NFr   r   requestr   r   r   
_can_write   s    zBaseGrabFormat._can_writec              	   C   sv   | j d | jsfd| _dd l}t|ds.tdzddlm} W n  tk
r^   Y W 5 Q R  d S X || _W 5 Q R X | jS )NTr   __version__z(Imageio Pillow requires Pillow, not PIL!)	ImageGrab)r
   _pillow_importedPILhasattrImportErrorr   
_ImageGrab)r   r   r   r   r   r   _init_pillow   s    
zBaseGrabFormat._init_pillowc                   @   s$   e Zd Zdd Zdd Zdd ZdS )zBaseGrabFormat.Readerc                 C   s   d S r   r   r   r   r   r   _open)   s    zBaseGrabFormat.Reader._openc                 C   s   d S r   r   r   r   r   r   _close,   s    zBaseGrabFormat.Reader._closec                 C   s   | j |S r   )format	_get_data)r   indexr   r   r   r!   /   s    zBaseGrabFormat.Reader._get_dataN)__name__
__module____qualname__r   r   r!   r   r   r   r   Reader(   s   r&   )r#   r$   r%   __doc__r   r   r   r   r   r   r&   __classcell__r   r   r   r   r      s   r   c                   @   s    e Zd ZdZdd Zdd ZdS )ScreenGrabFormata  The ScreenGrabFormat provided a means to grab screenshots using
    the uri of "<screen>".

    This functionality is provided via Pillow. Note that "<screen>" is
    only supported on Windows and OS X.

    Parameters for reading
    ----------------------
    No parameters.
    c                 C   s   |j dkrdS t|  S )Nz<screen>Ffilenameboolr   r   r   r   r   	_can_read?   s    
zScreenGrabFormat._can_readc                 C   s6   |   }|st| }|d k	s$tt|}|i fS r   )r   AssertionErrorZgrabnpasarrayr   r"   r   Zpil_imZimr   r   r   r!   D   s    
zScreenGrabFormat._get_dataNr#   r$   r%   r'   r-   r!   r   r   r   r   r)   3   s   r)   c                   @   s    e Zd ZdZdd Zdd ZdS )ClipboardGrabFormata(  The ClipboardGrabFormat provided a means to grab image data from
    the clipboard, using the uri "<clipboard>"

    This functionality is provided via Pillow. Note that "<clipboard>" is
    only supported on Windows.

    Parameters for reading
    ----------------------
    No parameters.
    c                 C   s   |j dkrdS t|  S )Nz<clipboard>Fr*   r   r   r   r   r-   Z   s    
zClipboardGrabFormat._can_readc                 C   s:   |   }|st| }|d kr(tdt|}|i fS )Nz5There seems to be no image data on the clipboard now.)r   r.   ZgrabclipboardRuntimeErrorr/   r0   r1   r   r   r   r!   _   s    
zClipboardGrabFormat._get_dataNr2   r   r   r   r   r3   N   s   r3   )	r'   r   Znumpyr/   corer   r   r)   r3   r   r   r   r   <module>   s   '