← 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

RaiMan proposed the following answer:
Oh yes you will learn a lot from that sample ;-)

Ok, here you are:
https://dl.dropbox.com/u/42895525/surfbar.sikuli.zip

download and unzip.
First go through the comments to understand the approach.

Then you might try to run it having surfbar3 visible.

When setting up such stuff, I always use highlight(), to show intermediate regions and matches.
These are currently commented out (except the last one).
Feel free to uncomment for testing purposes.

Since I am usually working on Macs, I use Mac's Screenshot tool to measure distances on the screen.
see faq 1686

Since others might be interested, I post the source here too, to get an
impression:

# this is based on surfbar3
img = "1354182115923.png" # only to know which one
# to run this script, surfbar3 must be visible on the screen

# find the position
imgBase = "1354182180938.png"
top = find(imgBase)
#top.highlight(2)

# get the surfbar
sbHeight = 85
sb = top.below(3).below(sbHeight)
#area.highlight(2)

# get the area of the left symbol
left = Region(sb.x, sb.y, 65, sbHeight)
#left.highlight(2)

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

# 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)
imgSymbol = capture(symbol)

# find the cell containing the symbol
match = None
for i in range(len(other)):
    if other[i].exists(imgSymbol, 0): # only one search
        match = other[i]
        break
if not match:
    print "not found"; exit()
match.highlight(3)

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