Wait() not working as expected on win7 or xp

Asked by Bijuak

def myHand():
 click(Image "Open" )
 stopObserve()

sleep(2)
click( Image "Process")
sleep(5)
onAppear(Image "Notification" , myHand())

I am having a application, which does some processing of files, the processing time is variable depending on the file size, I am not sure about the amount of time I need to wait for each file. I am trying to use this OnAppear API. But it is not waiting for the required amount of time, As soon as the sleep(5) is done onAppear function executes and my function fails.
Regarding the myHand function.When I try using onAppear(image "Notification", myHand) it does not execute. When defining the function as myHand(event):

Appreciate your help..

Thanks,
Biju

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Dylan McCarthy (dylan-dwmcc) said :
#1

I believe that there are several questions here:

1."OnAppear is not waiting for the required amount of time"
Instead of using OnAppear, I would experiment with the 'wait' function, but specifying an image instead of a time interval. Try:
-----
def myHand():
 click(Image "Open" )
 stopObserve()

sleep(2)
click( Image "Process")
wait(Image)
##Here, specify your Notification and the execution of the myHand function. Try doing this separately.
-----

2."When I try using onAppear(image "Notification", myHand) it does not execute"
It is possible that the syntax of it is incorrect. I would recommend, again, to do this separately, with the wait function. Example below.
-----
wait(image)
#NOTIFICATION HERE
#EXECUTE MYHAND HERE
-----
Any help?

-dwmcc

Revision history for this message
Bijuak (bijugavu) said :
#2

Thanks a lot Dylan, but it did not work :(

I tried using the Wait command but no good.

Sleep(3)
click("Image1")
sleep(1)
wait("Notification Image")
sleep(2)
click("OK")

It fails to find the Notification Image and hence my script fails.

edu.mit.csail.uid.FindFailed: FindFailed: 1282844363335.png can't be found.

Revision history for this message
Dylan McCarthy (dylan-dwmcc) said :
#3

No problem!

First off, Sikuli can have some problems with storing images in a temp folder. If you haven't already, I recommend that you save your Sikuli project somewhere on your computer. Secondly, I would double check that Sikuli can identify what part of the screen where it should find the notification image. First, go to the Notification Image where Sikuli should click OK. Keep that open on your desktop. Then, open your Sikuli script and single-click on the Notification Image screenshot. Sikuli will dissappear for a second, then return with a second window that should show your current screen, and search for your notification image. If it's open, you should see it on there. If Sikuli highlights it correctly, then there's a different problem. If Sikuli does not highlight your Notification Image in the preview window, try moving the sensitivity bar on the bottom of the window to a lower sensitivity, and keep lowering it until the Notification Image is highlighted.

Work?

-dwmcc

Revision history for this message
Bijuak (bijugavu) said :
#4

It works for the first part.If the Notification is already displayed. But the real issue is the Wait command. If the Notification shows up within the api observing time limit, the Function works fine, As I told earlier the Processing time is variable as a result. eg: If the notification shows up after 5 mins, the Wait() command is not waiting for 5 mins before it proceeds further. Its the same with OnAppear() api.

I tried tweaking the sensitivity and other parameters but no good so far..

Appreciate your help..

Thanks,
Biju

Revision history for this message
RaiMan (raimund-hocke) said :
#5

wait() raises exception FindFailed, if the waiting time is exceeded. So in this case, only exists() can help, since you can implement your own timing, without having to deal with exceptions:

stepWait = 2 # adjust your granularity
while True:
    if exists(notification-image, 0) # only one try
        break
    wait(stepWait) # just wait
# here we go after the notification window has come up

This is ok, if you are sure that the event surely occurs after some time. So if it may be that you get into an endless loop, you have to implement some counter to add an additional break

stepWait = 2 # adjust your granularity
maxWait = 100 # max 100 seconds
actualWait = 0
isFound = False
while actualWait < maxWait:
    if exists(notification-image, 0) # only one try
        isFound = True # to show success
        break
    wait(stepWait)
    actualWait += stepWait
# here we go after the notification window has come up or maxWait is reached
if not isFound:
    popup("No Success")
    exit(1)
# notification window came up

BTW: the observer feature is buggy on windows and does not do what it should (bug reported). observing only one or two events can easily be done with exists() according to the above example. It normally is sufficient, if the script has to wait for the event anyway.

Revision history for this message
RaiMan (raimund-hocke) said :
#6

@ dylan:

the observer feature has 3 components:

1. onAppear, onVanish, onChange
which define events, that should be observed within a region, specifying the name of a handler, that should be called, when the event happens.

2. the handler itself ( def myHandler(event):)
a routine, where you can deal with the event (e.g. stop the observation)

3. the observation loop started with observe()
where you can specify a max. observation time and/or wether it should run in the background (your script would continue after observe()).

so if observe() would run on windows, it has to look like this: (have a look at the docs)

def myHandler(event):
    isFound=True # to show success
    stopObserver() # adresses the standard region Screen(0)
    # or event.region.stopObserver(), so this handler can be used with any region

isFound = False
onAppear(some-image, myHandler)

observe(100) # wait max 100 seconds for some-image to appear

if not isFound:
    popup("No Success")
    exit(1)

Can you help with this problem?

Provide an answer of your own, or ask Bijuak for more information if necessary.

To post a message you must log in.