It does not work onAppear

Asked by Chp

Hello
I'm using Sikuli 1.0.1
my code:
def my_handler(event):
    print "My handler", event.match

dz.scr.onAppear(Interface.Loading['play_w7'], my_handler)
dz.scr.observe(60, True)

for i in range(30):
    print('----------------------' + str(i))
    sleep(0.5)

If my handler works out at least once, it does not work next time when it finds required image. And I forced to run it this way:
def my_handler(event):
    print "My handler", event.match
    dz.scr.stopObserver()
    dz.scr.observe(60, True)

Do I do it right or there is another way?

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Best RaiMan (raimund-hocke) said :
#1

if you want to reliably use observe, I recommend to use version 1.1.0 (http://sikulix.com).

I do not support problems in 1.0.1 with observe anymore.

in 1.1.0:

- onAppear, onVanish in 1.1.0
... stop observing after the first success
... need an event.repeat(waittime) before leaving the handler, if you want to continue the observe
... to stop the observe in handler: event.stopObserver()

Never ever start an observer inside of a handler !!!

def my_handler(event):
    print "My handler", event.match
    event.repeat(2)

dz.scr.onAppear(Interface.Loading['play_w7'], my_handler)
dz.scr.observe(60, True)

for i in range(30):
    print('----------------------' + str(i))
    sleep(0.5)

The docs for the new observe in 1.1.0 will be available tomorrow.

Revision history for this message
Chp (chpnick) said :
#2

I am not ready yet to upgrade to version 1.1, I tried but it did not solve the problem of click to for app unity3d player

Revision history for this message
Chp (chpnick) said :
#3

Thanks RaiMan, that solved my question.