← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #272057]: Multiple Observers threading

 

Question #272057 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/272057

    Status: Open => Answered

RaiMan proposed the following answer:
Be sure to have the latest nightly 1.1.0 and looked into the docs about
observe (revised yesterday).

-- 1. with your threading ...
 ... since you delegated everything to threads, the main script immediately stops after the last statement, since nothing else to do.

add a sufficient wait(someTime), and it should work.

-- 2. using the whole screen ...
... is problematic, since it is one "static" Region object and as the error tells you:
[error] Region: observe: already running for this region. Only one allowed!

so this would solve it:
reg1 = SCREEN
reg2 = Region(SCREEN) or reg2 = Screen(0)
which both create a new Region object for the whole screen

-- 3. we have our own threaded observe:
observeInBackground() runs in parallel


reg1 = Region(76,61,569,635)
reg2 = Region(680,66,637,622)

addImagePath(r'C:\Sikuli Nightly')

def findMario():
    reg1.onAppear('Mario_png.PNG',  lambda e:popup("Mario Appeared"))
    reg1.observeInBackground(FOREVER)

def findMushroom():
    reg2.onAppear('Mushroom2.PNG', lambda e:popup("Mushroomh Appeared"))
    reg2.observeInBackground(FOREVER)

findMario()
findMushroom()
wait(60) # hoping something happens within 60 seconds

You received this question notification because your team Sikuli Drivers
is an answer contact for Sikuli.