OBSERVE(FOREVER) but FINDFAILED

Asked by Alexandre Bourdeau

Hello, first post here. This is my code:

def myH(e):
 hover(PICTURE)
 stopObserver()
 observe(FOREVER)

onAppear(PICTURE, myH)

observe(FOREVER)

After some time it stops and I get the following message:

[error] Message d'erreur : Traceback (most recent call last):
File "C:\Users\ALEXAN~1\AppData\Local\Temp\sikuli-tmp4889400881574180526.py", line 10, in observe(FOREVER)
File "C:\Program Files (x86)\Sikuli X\sikuli-script.jar\Lib\sikuli\Region.py", line 255, in observe
Line 6, in file C:\Users\ALEXAN~1\AppData\Local\Temp\sikuli-tmp4889400881574180526.py

at org.sikuli.script.Region.handleFindFailed(Region.java:349)
at org.sikuli.script.Region.wait(Region.java:420)
at org.python.proxies.sikuli.Region$Region$1.super__wait(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)

org.sikuli.script.FindFailed: FindFailed: can not find 1314432731963.png
Line 6, in file C:\Users\ALEXAN~1\AppData\Local\Temp\sikuli-tmp4889400881574180526.py

Why am I getting this error? All I want to do is to make a script that hovers over a picture when it appears with an endless loop.

Thanks for the help.

Question information

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

In any case: You cannot start a new observe() inside the handler.

*** So your basic code should be:

def myH(e):
 hover(picture)
 stopObserver()

picture = "your-captured-image.png" # only one capture / multiple use
onAppear(picture, myH)

observe(FOREVER)

*** So if you want this to continue this for ever:

def myH(e):
    hover(picture)
    stopObserver()

picture = "your-captured-image.png" # only one capture / multiple use
onAppear(picture, myH)

while True:
    observe(FOREVER) # this will start observing again, when handler has stopped the observer

But this does not make sense, because I cannot see any action to wait until the image disappears to start a new observation.

*** do not make another find in the handler
in the handler, you know the match of the onAppear(), so you can use:

def myH(e):
    hover(e.match)
    stopObserver()

(look: http://sikuli.org/docx/region.html#observing-visual-events-in-a-region)

*** using exists() instead of observe()
for these situations (observing in foreground - script waits) I prefer to use loops and exists()

picture = "your-captured-image.png" # only one capture / multiple use

while True: # run forever
    while not exists(picture, 0): # wait for picture
        wait(1)
    hover(getLastMatch())
    wait(10) # or something else to make picture vanish

Revision history for this message
Alexandre Bourdeau (alx-bourdeau-deactivatedaccount) said :
#2

Thank you, it works.