← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #215490]: I Want to Learn How to Code

 

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

RaiMan proposed the following answer:
A loop has to be set up in the main workflow and contain the parts that
are changing.

--- this is the one time basic version

# 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)

--- this is a looping version, that ends, if the imgBase is no longer
found, when starting the next turn (so e.g. manually closing the webpage
will end the script)

# 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 symbols area
rsym = Region(fix.x + fix.w + 8, fix.y + 14, 35, 35)

# 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)

while not exists(imgBase, 0):
    symbol = capture(rsym)
    # rsym.highlight(1)
    found = checkCells(symbol)
    if not found: print "not found"; exit(1)
    click(found)
    wait(10)

The last wait() might not be appropriate, depending on what happens after the click().
There might have to be added more actions before returing to the looping point (while ...).

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