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

Provide internal unfind method to emulate inverse find #64

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions guibot/region.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,16 +599,20 @@ def wait(self, target: str | Target, timeout: int = 30) -> "Match":
log.info("Waiting for %s", target)
return self.find(target, timeout)

def wait_vanish(self, target: str | Target, timeout: int = 30) -> "Region":
def _unfind(self, target: str | Target, timeout: int = 30) -> "Region":
"""
Wait for a target to disappear (be unmatched) with a given timeout as failing tolerance.
Emulate waiting for a vanishing target.

:param target: target to look for
:param timeout: timeout before giving up
:returns: self
:raises: :py:class:`errors.NotFindError` if match is still found

This method is meant to be as internal as `find()` but with the inverse
meaning. It is not meant to be used on the same level of abstraction
as `wait_vanish()` just like `find()` is not meant to be used on the same
level of abstraction as `wait()`.
"""
log.info("Waiting for %s to vanish", target)
expires = time.time() + timeout
while time.time() < expires:
if self.exists(target, 0) is None:
Expand All @@ -620,6 +624,17 @@ def wait_vanish(self, target: str | Target, timeout: int = 30) -> "Region":
# target is still there
raise NotFindError(target)

def wait_vanish(self, target: str | Target, timeout: int = 30) -> "Region":
"""
Wait for a target to disappear (be unmatched) with a given timeout as failing tolerance.

:param target: target to look for
:param timeout: timeout before giving up
:returns: self
"""
log.info("Waiting for %s to vanish", target)
return self._unfind(target, timeout)

def idle(self, timeout: int) -> "Region":
"""
Wait for a number of seconds and continue the nested call chain.
Expand Down Expand Up @@ -794,7 +809,7 @@ def click_expect(
log.info("Retrying the mouse click (%s of %s)", i + 1, retries)
self.click(click_image_or_location, modifiers=modifiers)
try:
return self.wait(expect_target, timeout)
return self.find(expect_target, timeout)
except FindError as error:
self.hover(Location(0, 0))
if i == retries - 1:
Expand Down Expand Up @@ -824,7 +839,7 @@ def click_vanish(
log.info("Retrying the mouse click (%s of %s)", i + 1, retries)
self.click(click_image_or_location, modifiers=modifiers)
try:
return self.wait_vanish(expect_target, timeout)
return self._unfind(expect_target, timeout)
except NotFindError as error:
self.hover(Location(0, 0))
if i == retries - 1:
Expand Down Expand Up @@ -1116,7 +1131,7 @@ def press_expect(
log.info("Retrying the key press (%s of %s)", i + 1, retries)
self.press_keys(keys)
try:
return self.wait(expect_target, timeout)
return self.find(expect_target, timeout)
except FindError as error:
if i == retries - 1:
raise error
Expand Down Expand Up @@ -1144,7 +1159,7 @@ def press_vanish(
log.info("Retrying the key press (%s of %s)", i + 1, retries)
self.press_keys(keys)
try:
return self.wait_vanish(expect_target, timeout)
return self._unfind(expect_target, timeout)
except NotFindError as error:
if i == retries - 1:
raise error
Expand Down
Loading