← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #255984]: HowTo Region.observe: onAppear handler ?

 

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

RaiMan proposed the following answer:
ok, coming nearer ;-)

def myHandler (event) :
 if QueteValideeReg.exists("1413219985088.png"):
  wait(1)
  QueteValideeReg.click() # clicks what the exists before found
  if exists(Pattern("1413716368262.png").similar(0.92)):
   click() # clicks what the exists before found
   if PrincipaleReg.exists("1413716480430.png"): # instance
    PrincipaleReg.click("1413716513801.png")
  event.stopObserver() # we have to stop observing, since it is started newly in the outer loop

nb_quetes_tours_faites = 0

while nb_quetes_tours_faites != 200 :
 QueteValideeReg.onAppear("1413219985088-2.png", myHandler)
 observe(FOREVER) # here it waits for the image to appear
 nb_quetes_tours_faites += 1 # here it continues after the handler did his job
 print(nb_quetes_tours_faites)

In a loop using observe in background does not make sense. so we use the
observe, that waits for the event to happen.

if "1413219985088-2.png" and "1413219985088.png" are the "same" image,
then this would be even more efficient, since the handler is only
entered, if the image appears.

def myHandler (event) :
 wait(1) # what is that for? I guess it is not needed
 click(event.match) # clicks the appeared image
 if exists(Pattern("1413716368262.png").similar(0.92)):
  click() # clicks what the exists before found
  if PrincipaleReg.exists("1413716480430.png"): # instance
   PrincipaleReg.click("1413716513801.png")
 event.stopObserver() # we have to stop observing, since it is started newly in the outer loop

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