← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #253709]: Stopping main program flow while a handler is active

 

Question #253709 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/253709

    Status: Open => Answered

RaiMan proposed the following answer:
if you know the max waiting time for the popup, then this would do the
job:

(1)def myHandler(event):
(2) #code to make popup vanish
(3) event.region.stopObserver()

(4)def func():
(5) #Main Function code
(6) onAppear(pImage, myHandler)
(7) observe(5)
(9) #Continue with main function

Now you are using the inline observe, which would continue with (9)
immediately after the popup appeared but max 5 seconds (if not).

usually one cannot really proceed with the main workflow while having the risk of a popup.
But if it is possible in your case:
(1)def myHandler(event):
(2) #code to make popup vanish
(3) event.region.stopObserver()

(4)def func():
(5) #Main Function code
(6) onAppear(pImage, myHandler)
(7) observe(5,background=True)
(9) #Continue with main function

it continues immediately after (7), since the observe is done in
parallel and stopped after 5 seconds anyway.

If you can somehow foresee the popup situation, this would be also
possible (no use of observe):


** not needed (1)def myHandler(event):

(4)def func():
(5) #Main Function code
if popupMightAppear:
    if exists(pImage, 5):
        #code to make popup vanish
(9) #Continue with main function

Be aware: up to version 1.0.1 the observe feature has many quirks and
the most critical is, that mouse and keyboard usage is not coordinated
between main workflow and handler in case of background=true, which
might lead to strange situations.

with version 1.1.0+ mouse/keyboard usage is coordinated between threads.
Additionally for critical sections it is possible to reserve the usage for one thread.
The background observe will have a feature to check in main workflow wether the observed events have already happened, which allows, to have the handling inline (no handler might be needed) at various places in the workflow, which is the best way to coordinate.

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.