Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

locateCenterOnScreen doesn't raise ImageNotFoundException. #441

Open
falconws opened this issue Jun 4, 2020 · 3 comments
Open

locateCenterOnScreen doesn't raise ImageNotFoundException. #441

falconws opened this issue Jun 4, 2020 · 3 comments

Comments

@falconws
Copy link

falconws commented Jun 4, 2020

pyautogui.locateCenterOnScreen method doesn't raise ImageNotFoundException.
This method returns None.
I'm reading this.
https://pyautogui.readthedocs.io/en/latest/screenshot.html#the-locate-functions
Why this method returning None instead of raising ImageNotFoundException?
pyautogui.locateOnScreen also same returns None.

>>> test = pyautogui.locateCenterOnScreen('not_found.png')
>>> test
>>> test == None
True
>>> 

Version: PyAutoGUI==0.9.50
OS: Linux mint MATE 19.3

$ python -V
Python 3.6.9
@copyrite
Copy link

I'm experiencing the same problem. locateOnScreen seems to be also affected.

  • PyAutoGUI version 0.9.50
  • PyScreeze 0.1.26
  • Python 3.7.4

@copyrite
Copy link

I guess this is it.

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.")

From the looks of it PyAutoGUI never explicitly calls it, so it is left to user code or PyScreeze. This should really be reflected in the documentation, but in the meantime calling that function near imports should do it.

@LukeSavefrogs
Copy link

I guess this is it.

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.")

From the looks of it PyAutoGUI never explicitly calls it, so it is left to user code or PyScreeze. This should really be reflected in the documentation, but in the meantime calling that function near imports should do it.

Thanks. This explains a lot. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants