ODKddlZddlZddlmZmZddlmZddlmZej e Z Gdde Z dZGdd eZdS) N)Image ImageChops)grab)DisplayceZdZdS)DisplayTimeoutErrorN)__name__ __module__ __qualname__/srv/buildsys-work-dir/castor/build_node/builder-2/WGSG1/unpkd_srcs/cloudlinux-venv-1.0.6/venv/lib/python3.11/site-packages/pyvirtualdisplay/smartdisplay.pyrr sDr rc|jdkr|d}tjd|j|}t j||}|}|r||SdS)zCrop borders off an image. :param im: Source image. :param bgcolor: Background color, using either a color tuple. :return: An image without borders, or None if there's no actual content in the image. RGBN) modeconvertrnewsizer differencegetbboxcrop)imbgcolorbgdiffbboxs rautocroprss w% ZZ   5"'7 + +B  R ( (D <<>>D wwt}} 4r c$eZdZdZddZddZdS) SmartDisplayc,t||jS)zCrop borders off an image. :param im: Source image. :return: An image without borders, or None if there's no actual content in the image. )r_bgcolor)selfrs rrzSmartDisplay.autocrop"s DM***r Tc^t|j}|r||}|S)N)xdisplay)rnew_display_varr)r"rimgs rrzSmartDisplay.grab*s3D0111  %--$$C r <Ncd}d}d} tdt|ztj|||z }|d}||}|r|}|r|snL||rn@|}|dz }||krd|d |d } t| td |sJ|S) astart process and create screenshot. Repeat screenshot until it is not empty and cb_imgcheck callback function returns True for current screenshot. :param autocrop: True -> crop screenshot :param timeout: int :param cb_imgcheck: None or callback for testing img, True = accept img, False = reject img rg333333?g?zsleeping %s secsF)rzTimeout! elapsed time:z timeout: zscreenshot is empty, next try..)logdebugstrtimesleeprrr) r"timeoutr cb_imgcheckt sleep_time repeat_timer&img_cropmsgs rwaitgrabzSmartDisplay.waitgrab2s    9 II(3z??: ; ; ; Jz " " " OA))U)++C}}S))H  ";s##$J 3 K7{{{@A777K)#... II7 8 8 8) 9* s r )T)r'TN)r r r rrr7r r rrr!sK+++''''''r r)loggingr.PILrr PIL.ImageGrabrpyvirtualdisplayr getLoggerr r+ Exceptionrrrr r rr>s !!!!!!!!$$$$$$g!!     )   "88888788888r