← Back to team overview

sikuli-driver team mailing list archive

[Question #258814]: observe and stopObserver() seem to be creating infinite loops?

 

New question #258814 on Sikuli:
https://answers.launchpad.net/sikuli/+question/258814

I've never used Sikuli before so I'm new to this. My handlers seem to work ok, but I think its the logic of my main that is doing strange things, for example:

Environment ------------------------------------------------------------------------------------------------------------
Win7 64bit using Sikuli-IDE-w.bat
jdk-6u45-windows-i586
jdk-7u72-windows-i586

Code ------------------------------------------------------------------------------------------------------------
import random
def myHandler1(event): #when called this will click an input box and type VANISH, works fine.
    click(Pattern("input.png").similar(0.45))
    type("VANISH" + Key.ENTER)
    event.region.stopObserver()

def myHandler2(event): #when called this will click an input box and type EXAMPLE #, woks fine.
    click(Pattern("input.png").similar(0.42))
    if exists(Pattern("example1.png").similar(0.40), 0): type("EXAMPLE " + str(example1) + Key.ENTER)
    elif exists (Pattern("example2.png").similar(0.40), 0): type("EXAMPLE " + str(example2) + Key.ENTER)
    elif exists (Pattern("example3.png").similar(0.46), 0): type("EXAMPLE " + str(example3) + Key.ENTER)
    event.region.stopObserver()

example1 = 1
example2 = 2
example3 = 3

while True : #infinite loop
    onVanish(Pattern("image.png").similar(0.47), myHandler1) #wait for the example image to disappear, and then type VANISH
    observe(FOREVER)
    onAppear(Pattern("image.png").similar(0.48), myHandler2) #wait for an image to appear, and then type the found EXAMPLE #
    observe(FOREVER)

What happens  ------------------------------------------------------------------------------------------------------------
1) The program gets slower and slower.
2) My output looks like the following:
On the first image, example 1
VANISH
EXAMPLE 1
On the second image, example 3
VANISH
VANISH
EXAMPLE 3
EXAMPLE 3
On the third image, example 2
VANISH
VANISH
VANISH
EXAMPLE 2
EXAMPLE 2
EXAMPLE 2
This keeps happening until it begins repeating 5-6 and then it crashes.
3) I have tried replacing observe(FOREVER) with observer(12000) with no luck.

I need to monitor for an image to appear, and react accordingly 1 time.
Once that image disappears, I need to perform another set of commands 1 time until the image appears again.

I tried to explain this the best I could. If there is a question, I'll be happy to answer.

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