Python

Moderators: None (Apply to moderate this forum)
Number of threads: 473
Number of posts: 1172

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Looping a script Posted by alcymart on 2 Dec 2012 at 8:57 AM
I am a newbie in programming and I started working with Sikuli open source package and uses Python language.

I would like my image match finding script posted below to repeat from the beginning once it reaches the end without user intervention. Here is what I have and the last line I commented, but its empty as far as repeating the script line codes?

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

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-1.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-1.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

return match
# end function area
# ------------------------------------------------------------


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

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

#Wait for counter


# Speed up mouse
Settings.MoveMouseDelay = 0
# find the position
imgBase = "1354182180938.png"
top = find(imgBase)


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

sbMarginTopBottom = 20
sbMarginLeftRight = 20
leftWidth = 65
# get the area of the left symbol
x = sb.x + sbMarginLeftRight
w = leftWidth - 2 * sbMarginLeftRight
y = sb.y + sbMarginTopBottom
h = sbHeight - 2 * sbMarginTopBottom
left = Region(x, y, w, h)


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


found = checkCells(capture(left))
if not found:
for i in range(numCells - 1):
symbol = captureSymbol(i)
found = checkCells(symbol, i+1)
if found: break
if not found: print "not found"; exit(1)
click(found)
type(Key.TAB,KEY_CTRL)
#Wait for counter on Surfbar to reach Zero
wait(1)

#Mouse speed
Settings.MoveMouseDelay = 0
# find the position
imgBase = "1354267496167-1.png"
fix = find(imgBase)


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


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


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


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


found = checkCells(symbol)
if not found: print "not found"; exit(1)
click(found)
type(Key.TAB,KEY_CTRL)
wait(12)
#Repeat from beginning



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.