B
    N[                 @   s   d Z ddlmZmZmZ ddlZddlZddlm	Z	 ddl
mZ G dd deZG d	d
 d
eZG dd deZeddg dZe	e eddg dZe	e dS )zD
PIL-based formats to take screenshots and grab from the clipboard.
    )absolute_importprint_functiondivisionN   )formats)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__ 3lib/python3.7/site-packages/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   sj   | j X | jsZd| _dd l}t|ds.tdyddlm} W n tk
rR   d S X || _W d 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 )Nr   )r   r   r   r   _open-   s    zBaseGrabFormat.Reader._openc             C   s   d S )Nr   )r   r   r   r   _close0   s    zBaseGrabFormat.Reader._closec             C   s   | j |S )N)format	_get_data)r   indexr   r   r   r!   3   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 dkrdS |jdkr dS t|  S )N   zi?Fz<screen>)modefilenameboolr   )r   r   r   r   r   	_can_readC   s
    
zScreenGrabFormat._can_readc             C   s6   |   }|st| }|d k	s$tt|}|i fS )N)r   AssertionErrorZgrabnpasarray)r   r"   r   pil_imimr   r   r   r!   J   s    
zScreenGrabFormat._get_dataN)r#   r$   r%   r'   r.   r!   r   r   r   r   r)   7   s   
r)   c               @   s    e Zd ZdZdd Zdd ZdS )ClipboardGrabFormata1   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 dkrdS |jdkr dS t|  S )Nr*   zi?Fz<clipboard>)r+   r,   r-   r   )r   r   r   r   r   r.   `   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RuntimeErrorr0   r1   )r   r"   r   r2   r3   r   r   r   r!   g   s    
zClipboardGrabFormat._get_dataN)r#   r$   r%   r'   r.   r!   r   r   r   r   r4   T   s   
r4   Z
screengrabz(Grab screenshots (Windows and OS X only)iZclipboardgrabz"Grab from clipboard (Windows only))r'   Z
__future__r   r   r   r   Znumpyr0    r   Zcorer   r   r)   r4   r    Z
add_formatr   r   r   r   <module>   s   (!
