← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #685479]: I don't know to how to implement the Region class in my function. I already read the documentation.

 

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

    Status: Open => Answered

RaiMan proposed the following answer:
Supposing that the images do not move while the script is running, then it brings the most, if you  restrict the search region to a smaller area than the whole screen.
This can be achieved either by absolute Regions (given with coordinates/dimension, with selectRegion() or by evaluating the app window) or relative with respect to matches you already know (logos, titles, buttons, ...).

Searchtime is dramatically reduced, if you have searched an image before
and then later search it in the place it was found before.

your example:

# add a region parameter
def do(a, b, ab, abc, reg):
    #save matches for later use
    #if not (exists(a, 0) and exists(ab, 0)):
    ma = reg.exists(a, 0)
    mab = reg.exists(ab, 0)
    if not (ma and ab):
        return

    reg.click(abc)
    start = time.time()

    # you suppose this vanishes in any case: risky
    """
    while mab.exists(ab, 0):
        pass
        #wait(0.1) # does not make sense
    """
    #better use waitVanish()
    if not mab.waitVanish(mab):
      exit(1) # did not vanish within 3 secs

    # replace with waitVanish()
    """
    while time.time() < (start + 3) and ma.exists(a, 0):
        pass

    if ma.exists(a, 0):
        click(b)
        return
    """
    if ma.waitVanish(ma, 3):
      reg.click(b)
      return # might be redundant 
    
# usage
someRegion = ...
# outer border - evaluate somehow (contains all images searched)

do(a="img1", b="img2", ab="img11", abc="img121", someRegion)

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