← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #215490]: Find and click image, then switch tabs

 

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

    Status: Solved => Open

Bernard St-Pierre is still having a problem:
I reiterate my question below to whomever can answer it

How do I get the script below to wait a certain amount of seconds and
then run script all over again? I found how to get it to wait but not
how to run the script again...In fact, I found something referring to
loop command but I get errors when trying to implement it. I am probably
not placing it correctly within the below code. Where does the Wait
command and the loop go in there? With that, I should be able to code
for all my other things I need. Help Anyone?

# --------------------------------------------
# functions to be used in different situations
def captureSymbol(i = 0):
    r = other[i]
    x = r.x + sbMarginLeftRight
    w = r.w - 2 * sbMarginLeftRight
    y = r.y + sbMarginTopBottom
    h = r.h - 2 * sbMarginTopBottom
    r = Region(x, y, w, h)
    r.highlight(1)
    return capture(r)

def captureLeftSmallest():
    # capture the image to search
    # we have to try to get the smallest capture possible
    # since the probe and the target have different positions
    # this can be set fixed, if it is always the same
    # find the bottom of image
    greyBelow = "1354183324452.png"
    g = left.find(greyBelow)
    #g.highlight(1)
    while True:
        g1 = g.above(sbHeight-g.y)
        g1.x -= 4; g1.w += 8
        g1 = g1.exists(greyBelow)
        if not g1: break
        g = g1
    #g.highlight(1)
    b = g.y

    # find the left side of image
    greyLeft = "1354183672313.png"
    g = left.find(greyLeft)
    #g.highlight(1)
    while True:
        g1 = g.right(left.w - g.x)
        g1.y -= 4; g1.h += 8
        g1 = g1.exists(greyLeft)
        if not g1: break
        g = g1
    #g.highlight(1)
    l = g.x + g.w

    # define the smallest possible image region
    symbol = Region(l, b - 60, 50, 60)
    #symbol.highlight(3)
    return capture(symbol)

def checkCells(imgSymbol, start = 0):
    # find the cell containing the symbol
    match = None
    for i in range(start, len(other)):
        if other[i].exists(imgSymbol, 0):
            match = other[i]
            break
    if not match: return None
    match.highlight(1)
    return match
# end function area
# ------------------------------------------------------------

# ----------------------- start of main workflow -------------

# this is based on surfbar9
# to run this script, surfbar9 must be visible on the screen

# find the position
imgBase = "1354267496167-1.png"
fix = find(imgBase)
fix.highlight(1)

# get the symbol
rsym = Region(fix.x + fix.w + 8, fix.y + 14, 35, 35)
symbol = capture(rsym)
rsym.highlight(1)

# get the surfbar
sbLeft = fix.right().find("1354267650780-1.png")
sbLeft.highlight(1)

sbHeight = 45
sbWidth = 330
sb = Region(sbLeft.x + 4, sbLeft.y + 3, sbWidth, sbHeight)
sb.highlight(1)

sbMarginTopBottom = 20
sbMarginLeftRight = 20

# setup the regions for the others
numCells = 4
oWidth = (sb.w)/4
other = []
for i in range(numCells):
    x = sb.x + i*oWidth - 4
    other.append(Region(x, sb.y, oWidth+8, sbHeight))
for r in other:
    pass
    r.highlight(1)

found = checkCells(symbol)
if not found: print "not found"; exit(1)
click(found)

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