def visgrep(scr: str, pat: str, tolerance: int = <NUM_LIT:0>) -> int:
tol = int(tolerance)<EOL>if tol < <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>with open(scr), open(pat):<EOL><INDENT>pass<EOL><DEDENT>with tempfile.NamedTemporaryFile() as f:<EOL><INDENT>subprocess.call(['<STR_LIT>', pat], stdout=f)<EOL>f.flush()<EOL>os.fsync(f.fileno())<EOL>vg = subprocess.Popen(['<STR_LIT>', '<STR_LIT>' + str(tol), scr, f.name], stdout=subprocess.PIPE, stderr=subprocess.PIPE)<EOL>out = vg.communicate()<EOL><DEDENT>coord_str = out[<NUM_LIT:0>].decode().split('<STR_LIT:U+0020>')[<NUM_LIT:0>].split('<STR_LIT:U+002C>')<EOL>try:<EOL><INDENT>coord = [int(coord_str[<NUM_LIT:0>]), int(coord_str[<NUM_LIT:1>])]<EOL><DEDENT>except (ValueError, IndexError) as e:<EOL><INDENT>raise PatternNotFound(str([x.decode() for x in out]) + '<STR_LIT>' + repr(e))<EOL><DEDENT>return coord<EOL>
visgrep(scr: str, pat: str, tolerance: int = 0) -> int
Visual grep of scr for pattern pat.
Requires xautomation (http://hoopajoo.net/projects/xautomation.html).
visgrep("screen.png", "pat.png")
Exceptions raised: ValueError, PatternNotFound, FileNotFoundError

:param scr: path of PNG image to be grepped.
:param pat: path of pattern image (PNG) to look for in scr.
:param tolerance: An integer ≥ 0 to specify the level of tolerance for 'fuzzy' matches. If negative or not convertible to int, raises ValueError.
:returns: coordinates of the topleft point of the match, if any. Raises PatternNotFound exception otherwise.