How to use the pyscreeze.USE_IMAGE_NOT_FOUND_EXCEPTION function in PyScreeze

To help you get started, we’ve selected a few PyScreeze examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github asweigart / pyscreeze / tests / test_pyscreeze.py View on Github external
haystack2Im = Image.open(haystack2Fp)
        colorNoiseIm = Image.open(colorNoiseFp)

        self.assertEqual((94, 94, 4, 4), tuple(pyscreeze.locate(slashIm, haystack1Im)))
        self.assertEqual((93, 93, 4, 4), tuple(pyscreeze.locate(slashIm, haystack2Im)))

        self.assertEqual((94, 94, 4, 4), tuple(pyscreeze.locate(slashIm, haystack1Im, grayscale=True)))
        self.assertEqual((93, 93, 4, 4), tuple(pyscreeze.locate(slashIm, haystack2Im, grayscale=True)))

        pyscreeze.USE_IMAGE_NOT_FOUND_EXCEPTION = True
        with self.assertRaises(pyscreeze.ImageNotFoundException):
            pyscreeze.locate(slashIm, colorNoiseIm)
        with self.assertRaises(pyscreeze.ImageNotFoundException):
            pyscreeze.locate(slashIm, colorNoiseIm, grayscale=True)

        pyscreeze.USE_IMAGE_NOT_FOUND_EXCEPTION = False
        self.assertEqual(pyscreeze.locate(slashIm, colorNoiseIm), None)
        self.assertEqual(pyscreeze.locate(slashIm, colorNoiseIm, grayscale=True), None)

        slashFp.close()
        haystack1Fp.close()
        haystack2Fp.close()
        colorNoiseFp.close()
github asweigart / pyscreeze / tests / test_pyscreeze.py View on Github external
def test_locate_filename(self):
        self.assertEqual((94, 94, 4, 4), tuple(pyscreeze.locate('slash.png', 'haystack1.png')))
        self.assertEqual((93, 93, 4, 4), tuple(pyscreeze.locate('slash.png', 'haystack2.png')))

        self.assertEqual((94, 94, 4, 4), tuple(pyscreeze.locate('slash.png', 'haystack1.png', grayscale=True)))
        self.assertEqual((93, 93, 4, 4), tuple(pyscreeze.locate('slash.png', 'haystack2.png', grayscale=True)))

        pyscreeze.USE_IMAGE_NOT_FOUND_EXCEPTION = True
        with self.assertRaises(pyscreeze.ImageNotFoundException):
            pyscreeze.locate('slash.png', 'colornoise.png')
        with self.assertRaises(pyscreeze.ImageNotFoundException):
            pyscreeze.locate('slash.png', 'colornoise.png', grayscale=True)

        pyscreeze.USE_IMAGE_NOT_FOUND_EXCEPTION = False
        self.assertEqual(pyscreeze.locate('slash.png', 'colornoise.png'), None)
        self.assertEqual(pyscreeze.locate('slash.png', 'colornoise.png', grayscale=True), None)
github AXeL-dev / Dindo-Bot / pyautogui / __init__.py View on Github external
def useImageNotFoundException(value=None):
    """
    When called with no arguments, PyAutoGUI will raise ImageNotFoundException when the PyScreeze locate*() functions
    can't find the image it was told to locate. The default behavior is to return None. Call this function with no
    arguments (or with True as the argument) to have exceptions raised, which is a better practice.

    You can also disable raising exceptions by passing False for the argument.
    """
    if value is None:
        value = True
    # TODO - this will cause a NameError if PyScreeze couldn't be imported:
    try:
        pyscreeze.USE_IMAGE_NOT_FOUND_EXCEPTION = value
    except NameError:
        raise PyAutoGUIException("useImageNotFoundException() ws called but pyscreeze isn't installed.")
github asweigart / pyautogui / pyautogui / __init__.py View on Github external
def useImageNotFoundException(value=None):
    """
    When called with no arguments, PyAutoGUI will raise ImageNotFoundException when the PyScreeze locate*() functions
    can't find the image it was told to locate. The default behavior is to return None. Call this function with no
    arguments (or with True as the argument) to have exceptions raised, which is a better practice.

    You can also disable raising exceptions by passing False for the argument.
    """
    if value is None:
        value = True
    # TODO - this will cause a NameError if PyScreeze couldn't be imported:
    try:
        pyscreeze.USE_IMAGE_NOT_FOUND_EXCEPTION = value
    except NameError:
        raise PyAutoGUIException("useImageNotFoundException() ws called but pyscreeze isn't installed.")