U
    Evf                     @  s^   d dl mZ d dlZ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dZ
dd	 ZdS )    )annotationsN   )ImageFc              
   C  sR  |d krJt jdkrtd\}}t| dg}| rl| \}}}	}
|d| d| d|	|  d|
|  g7 }t|d|g  t	|}|
  t| | r||	| |
| f}|  |S |S t jdkrJtj||\}}}td||d	d
|d d d d@ d}| rF|\}}| \}}}	}
||| || |	| |
| f}|S z*tjjsbd}t|tj|\}}W n tk
r   |d krt jdkrtdrtd\}}t| tdd|g t	|}|
  t| | r|| }|  | Y S | Y S  Y n4X td||d	d|d d d}| rJ|| }|S d S )Ndarwin.pngZscreencapturez-R,z-xwin32ZRGBrawZBGRr      z$Pillow was built without XCB support)r   r   zgnome-screenshotz-fZBGRX   r   )sysplatformtempfilemkstemposclose
subprocesscallr   openloadunlinkresizecoreZgrabscreen_win32Z	frombytesZcropZHAVE_XCBOSErrorZgrabscreen_x11shutilwhich)ZbboxZinclude_layered_windowsZall_screensZxdisplayfhfilepathargslefttoprightZbottomimZ
im_resizedoffsetsizedataZx0Zy0msgZ
im_cropped r)   1/tmp/pip-unpacked-wheel-ciywl2yd/PIL/ImageGrab.pygrab   s    


*

 

"





r+   c                  C  s  t jdkrtd\} }t|  d| d ddddg}d	g}|D ]}|d
|g7 }qBt| d }t|j	dkrt
|}|  t| |S t jdkrxt
j \}}|dkrdd l}|d|d }	|d dkr||	d  dd}
n||	d  dd}
|
d |
d S t|trtt|}|dkrTddlm} ||S |dkrtddlm} ||S d S tdrd}ntdrd}nd }t dr|dkrddd g}n4t d!r|d"krd!d#d$dd%d&g}nd'}t!|tj"|d(d)}|j#dkrd|j$}d*D ]}||kr d S q|d  d+}|r\|d,|%   7 }t&|t|j'}t
|}|  |S d S )-Nr   r   z,set theFile to (open for access POSIX file "z" with write permission)tryu6       write (the clipboard as «class PNGf») to theFilezend tryzclose access theFileZ	osascriptz-er   r   fileI   zutf-16le mbcs Zpngr   )PngImagePluginZDIB)BmpImagePluginZWAYLAND_DISPLAYwaylandZDISPLAYx11zwl-paste)r5   Nz-timageZxclip)r6   Nz
-selectionZ	clipboardz	image/pngz-ozDwl-paste or xclip is required for ImageGrab.grabclipboard() on LinuxT)capture_output)s   Nothing is copieds   No selections"   No suitable type of content copieds    not availables   cannot convert s(   xclip: Error: There is no owner for the z errorz: )(r   r   r   r   r   r   r   r   statst_sizer   r   r   r   r   Zgrabclipboard_win32structunpack_fromdecodesplitindex
isinstancebytesioBytesIOr2   r3   ZPngImageFiler4   ZDibImageFilegetenvr   r   NotImplementedErrorrun
returncodestderrstripChildProcessErrorstdout)r   r   commandsscriptcommandr$   fmtr'   r;   ofilesr3   r4   Zsession_typer    r(   perrZsilent_errorr)   r)   r*   grabclipboarda   s    

	











rT   )NFFN)
__future__r   rB   r   r   r   r   r   r2   r   r+   rT   r)   r)   r)   r*   <module>   s   
D