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

RaiMan proposed the following answer:
Since there was added class SikuliEvent in RC2, you should read:
http://sikuli.org/docx/region.html#observing-visual-events-in-a-region

with this construct

reg.observer(5)
reg.stopObserver()

your script will pause for 5 seconds processing the observe(), so the
stopObserver() will do nothing, when executed, since the observer is
already stopped. You may stop the observer in the handler in this case,
to continue your script in the moment of the observed event happening:

def myHandler(event):
        popup(" it") 
        event.region.stopObserver()

as already mentioned, class SikuliEvent gives more options to handle
events in the case more than one is observed simultaneously.

For only one event, this would be equivalent:

for i in range(5):
    if reg.exists(<some-image>, 0)
         break
    wait(0.7)

comments:
--  exists(<some-image>, 0)
looks only once and comes back
-- wait(0.7)
each find costs in average about 0.3 seconds, so each loop step would last 
about 1 second.

using observe() makes only sense if you have more than one event you are
waiting for at the same moment even in different regions (each region
can have it's own observer) or if you want to go on with your script in
parallel, while the observer is running (observe(FOREVER,
background=True))

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

_______________________________________________
Mailing list: https://launchpad.net/~sikuli-driver
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~sikuli-driver
More help   : https://help.launchpad.net/ListHelp

Reply via email to