o
    Wf                     @  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  s@  |d u rt jdkratd\}}t| dg}| r5| \}}}	}
|d| d| d|	|  d|
|  g7 }t|d|g  t	|}|
  t| | r_||	| |
| f}|  |S |S t jdkrtj||\}}}td||d	d
|d d d d@ d}| r|\}}| \}}}	}
||| || |	| |
| f}|S ztjjsd}t|tj|\}}W nP ty   |d u rt jdvrtdrtd\}}t| tdd|g t	|}|
  t| | r|| }|  | Y S | Y S  w td||d	d|d d d}| r|| }|S )Ndarwin.pngscreencapturez-R,z-xwin32RGBrawBGRr      z$Pillow was built without XCB support)r   r	   zgnome-screenshotz-fBGRX   r   )sysplatformtempfilemkstemposclose
subprocesscallr   openloadunlinkresizecoregrabscreen_win32	frombytescropHAVE_XCBOSErrorgrabscreen_x11shutilwhich)bboxinclude_layered_windowsall_screensxdisplayfhfilepathargslefttoprightbottomim
im_resizedoffsetsizedatax0y0msg
im_cropped r;   u/media/darth/New Volume E/PROJECTS/DRIVERZZ/DRIVERZZ_CUSTOMER_APIS/venv/lib/python3.10/site-packages/PIL/ImageGrab.pygrab   s   

*




"




r=   c                  C  sd  t jdkrItd\} }t|  d| d ddddg}d	g}|D ]}|d
|g7 }q!t| d }t|j	dkrBt
|}|  t| |S t jdkrt
j \}}|dkrdd l}|d|d }	|d dkrx||	d  dd}
n||	d  dd}
|
d |
d S t|trt|}|dkrddlm} ||S |dkrddlm} ||S d S tdrd}n
tdrd}nd }t dr|dv rg d}nt d r|d!v rg d"}nd#}t!|tj"|d$d%}|j#dkr!|j$}d&D ]
}||v r d S q|d  d'}|r|d(|%   7 }t&|t|j'}t
|}|  |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 theFile	osascriptz-er   r	   fileI   zutf-16le mbcs pngr   )PngImagePluginDIB)BmpImagePluginWAYLAND_DISPLAYwaylandDISPLAYx11wl-paste)rK   N)rN   -timagexclip)rM   N)rQ   z
-selection	clipboardrO   z	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   grabclipboard_win32structunpack_fromdecodesplitindex
isinstancebytesioBytesIOrE   rG   PngImageFilerI   DibImageFilegetenvr%   r&   NotImplementedErrorrun
returncodestderrstripChildProcessErrorstdout)r+   r,   commandsscriptcommandr2   fmtr6   rW   ofilesrG   rI   session_typer-   r9   perrsilent_errorr;   r;   r<   grabclipboarda   s   

	













rt   )NFFN)
__future__r   r^   r   r%   r   r   r   rE   r   r=   rt   r;   r;   r;   r<   <module>   s   
D