U
    Žb                     @   sL   d dl Z ddlmZ e jdkr6d dlZd dlZd dlZd
ddZdd	 ZdS )    N   )ImagedarwinFc              
   C   s  |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 tjjs\tdtj|\}}td||d	d|d d d}| r|| }|S )Nr   z.pngZscreencapturez-R,z-xwin32ZRGBrawZBGRr      z$Pillow was built without XCB supportZBGRX   r   )sysplatformtempfilemkstemposclose
subprocesscallr   openloadunlinkresizecoreZgrabscreen_win32Z	frombytesZcropZHAVE_XCBOSErrorZgrabscreen_x11)ZbboxZinclude_layered_windowsZall_screensZxdisplayfhfilepathargslefttoprightZbottomimZ
im_resizedoffsetsizedataZx0Zy0 r$   1/tmp/pip-unpacked-wheel-_wxctax1/PIL/ImageGrab.pygrab   sV    


*

 

"

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rt
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r|dd l}||}|dkr\ddlm} ||S |dkr|ddlm} ||S d S tdd S )Nr   z.jpgz,set theFile to (open for access POSIX file "z" with write permission)tryz4    write (the clipboard as JPEG picture) to theFilezend tryzclose access theFileZ	osascriptz-er   r   fileI   zutf-16le mbcs Zpngr   )PngImagePluginZDIB)BmpImagePluginz3ImageGrab.grabclipboard() is macOS and Windows only)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BytesIOr-   r.   ZPngImageFiler/   ZDibImageFileNotImplementedError)r   r   commandsscriptcommandr    fmtr#   r2   ofilesr9   r.   r/   r$   r$   r%   grabclipboardK   sV    

	








rB   )NFFN)	r   r-   r   r   r   r   r   r&   rB   r$   r$   r$   r%   <module>   s   

/