← Back to team overview

sikuli-driver team mailing list archive

[Question #182167]: Observing Multiple Regions Simultaneously

 

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

Hello,

I'm trying to watch for one of any number of windows to appear. Previously, I simply observed for all of them on the entire screen:

imgOne = "imgOne.png"
imgTwo = "imgTwo.png"
imgThree = "imgThree.png"

onAppear(imgOne, handlerOne)
onAppear(imgTwo, handlerTwo)
onAppear(imgThree, handlerThree)

while (True): 
    Observe(Forever).

But, now I want the script to run faster, so I've cut down the regions that each window could appear in:

"""
imgOne = "img1.png"
imgTwo = "img2.png"
imgThree = "img3.png"
rOne = Region(0,0,200,200)
rTwo = Region(200,0,200,200)
rThree = Region(400,0,200,200)

rOne.onAppear(imgOne, handlerOne)
rTwo.onAppear(imgTwo, handlerTwo)
rThree.onAppear(imgThree, handlerThree)
"""

xloc = 0
for x in ["One", "Two", "Three"]:
    img = "img" + x + ".png"
    reg = Region(200*xloc, 0, 200, 200)
    reg.onAppear(img, handler)
    xloc++

While(True): 
    observe(Forever)

But, it seems like the call to Observe isn't working (for either of the methods above, the old way of hand coding each region, or the new dynamic one). I believe its because Observe only refers to events tied to the entire screen, and not to any specific region that has been created. But, the documentation isn't very deep on the subject. Ideally, I would like to be able to keep everything dynamic in the for loop, because I may want to add images later and it just makes for convenient code. 

I tried calling observe on each region individually:

for reg in regs:
    reg.observe(Forever)

But its a blocking call, so only one image would be looked for at a time. Is there a way to observe multiple regions at one time, or do I need to switch the backbone to a loop of 

while (True):
    for img in imgs:
         if (reg.exists(img)): handle(img)

? I'd rather not, Observe seems more elegant. 

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