sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #44834
Re: [Question #661427]: How to pause the main script when handling an event using observeInBackground
Question #661427 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/661427
Status: Open => Answered
RaiMan proposed the following answer:
-- solution 1:
define at the beginning of main script:
shouldWait = False
Make a function like:
def myFind(region, imageOrPattern, waittime = 3):
while shouldWait:
wait(1)
return region.wait(imageOrPattern, waittime)
... and use it instead of the find operations, that needs to be guarded.
instead of
click(someImage)
use
click(myFind(SCREEN, someImage))
... and in the observe handler at the beginning:
global shouldWait
shouldWait = True
# do your handling
shouldWait = False
This is a basic solution, that might help in many cases. The risk is,
that the handler event is triggered, but the handler not yet started and
a find op has already begun.
-- solution 2:
Intercept the FindFailed situations, that are caused by the GUI event (e.g. popup hiding the target image), that should be handled by observeInBackground.
Since version 1.1.1 we have a callback feature for FindFailed situations:
http://sikulix-2014.readthedocs.io/en/latest/region.html#exception-findfailed
Similar to solution 1 you have to define and handle global variables for
communication between the FindFailed handler and the observe handler.
The principal workflow:
- in FindFaild handler check, wether an observe event is or was handled
- if yes, wait for the completion of the observe handling and return with the REPEAT advice
- if no, then you have a normal FindFailed that should be handled as needed
This solution is a bit more complex, but has a chance, to get around all
such conflict situations.
You received this question notification because your team Sikuli Drivers
is an answer contact for Sikuli.