← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #231963]: Image randomly appear

 

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

    Status: Open => Answered

RaiMan proposed the following answer:
--1. why not this way

For m in range(1800):
  Click(wait(img1,10))
  Click(wait(img2,10))
  Click(wait(img3,10))
  While exists(img4,20):
    If exist(img4):
      Click(exists(img5))
      Break
  Click(exists(img6,10))
  Click(exists(img7,10))

... following the DRY design pattern (Don't repeat yourself)

--2. the while does not really make sense...
  while exists(img4,20):
    If exist(img4):
      Click(exists(img5))
      Break

is the same as:
  If exist(img4, 20):
    Click(exists(img5))

Both wait max 20 secs for img4 and click img5 (if it exists) in the
moment img4 appears

--3. stop with image 8 or 9
If I understand right: you want to stop the script, if either img8 or img9 appear while your script is running.
Assuming, that img8 and img9 do not vanish after a specific time automatically again after they appear, this should do it (using the observe in background feature)

def img8Or9Appear(e):
  print "img8 or img9 poped up: stopping script"
  e.region.stopObserver()
  exit()

onAppear(img8, img8Or9Appear) 
onAppear(img9, img8Or9Appear) 
Settings.ObserveScanRate = 0.2 # check every 5 seconds
observe(FOREVER, background=True)

For m in range(1800):
  Click(wait(img1,10))
  Click(wait(img2,10))
  Click(wait(img3,10))
  If exist(img4, 20):
    Click(exists(img5))
  Click(exists(img6,10))
  Click(exists(img7,10))

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