← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #186411]: wait 1 or 2 or 3 and loop it

 

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

    Status: Open => Answered

RaiMan proposed the following answer:
--- the timing in your loop:
you are talking about small images and are searching the whole screen.
One search (which is done by exists(,0)) you can count about 0.5 seconds in average.
so your loop will run for
20 * wait: 1 second + 20 * exists: (0.5 + 0.5) seconds = about 40 seconds

If you want a loop, that has a more accurate timing:

maxWait = 20
start = time.time()
while time.time() - start < maxWait:
  mImg1 = exists("0000-1.png",0)
  mImg2 = exists("DUDE-1.png",0)
  if mImg1 or mImg2: break

This loop will take maximum about 21 seconds.

If you want to make it even more accurate, you have to check for the
time inside the loop.

--- restrict to a region
You are talking about the fact, that the images might appear in specific regions of the screen. So if you tell Sikuli to only search in these regions, you might cut down the search time to 0.1 second.
There are various ways, to evaluate a search region, e.g. with respect to another image:
# example for this page (has to be scrolled to top):
m = find("sikuli-logo.png")
top = m.nearby(10).right(1).right(400)
top.highlight(2)

With a tight capture of the Sikuli logo in the upper left, this will
make top the region containing the top menu of this page.

so with regions, your loop would look:

reg1 = some_evaluated_region1
reg2 = some_evaluated_region2
maxWait = 20
start = time.time()
while time.time() - start < maxWait:
  mImg1 = reg1.exists("0000-1.png",0)
  mImg2 = reg2.exists("DUDE-1.png",0)
  if mImg1 or mImg2: break

--- One more thing
f not (mImg1 or mImg2):
  popup ("nothing to screen"); exit(1)

if mImg1:
    img = capture(SCREEN)
    shutil.move(img, 'c:/test/')
if mImg2:
    img = capture(SCREEN)
    shutil.move(img, 'c:/test/')does not really make sense, because you do not differentiate between the cases. If either or both came up, a shot is taken:

f not (mImg1 or mImg2):
  popup ("nothing to screen"); exit(1)
else:
    img = capture(SCREEN)
    shutil.move(img, 'c:/test/')

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