<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'Looping a script' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'Looping a script' posted on the 'Python' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Sat, 18 May 2013 02:02:38 -0700</pubDate>
    <lastBuildDate>Sat, 18 May 2013 02:02:38 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>Looping a script</title>
      <link>http://www.programmersheaven.com/mb/python/430463/430463/looping-a-script/</link>
      <description>I am a newbie in programming and I started working with Sikuli open source package and uses Python language.&lt;br /&gt;
&lt;br /&gt;
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?&lt;br /&gt;
&lt;br /&gt;
# --------------------------------------------&lt;br /&gt;
# functions to be used in different situations&lt;br /&gt;
def captureSymbol(i = 0):&lt;br /&gt;
    r = other[i]&lt;br /&gt;
    x = r.x + sbMarginLeftRight&lt;br /&gt;
    w = r.w - 2 * sbMarginLeftRight&lt;br /&gt;
    y = r.y + sbMarginTopBottom&lt;br /&gt;
    h = r.h - 2 * sbMarginTopBottom&lt;br /&gt;
    r = Region(x, y, w, h)&lt;br /&gt;
    &lt;br /&gt;
    return capture(r)&lt;br /&gt;
&lt;br /&gt;
def captureLeftSmallest():&lt;br /&gt;
    # capture the image to search&lt;br /&gt;
    # we have to try to get the smallest capture possible&lt;br /&gt;
    # since the probe and the target have different positions&lt;br /&gt;
    # this can be set fixed, if it is always the same&lt;br /&gt;
    # find the bottom of image&lt;br /&gt;
    greyBelow = "1354183324452-1.png"&lt;br /&gt;
    g = left.find(greyBelow)&lt;br /&gt;
    #g.highlight(1)&lt;br /&gt;
    while True:&lt;br /&gt;
        g1 = g.above(sbHeight-g.y)&lt;br /&gt;
        g1.x -= 4; g1.w += 8&lt;br /&gt;
        g1 = g1.exists(greyBelow)&lt;br /&gt;
        if not g1: break&lt;br /&gt;
        g = g1&lt;br /&gt;
    #g.highlight(1)&lt;br /&gt;
    b = g.y&lt;br /&gt;
    &lt;br /&gt;
    # find the left side of image&lt;br /&gt;
    greyLeft = "1354183672313-1.png"&lt;br /&gt;
    g = left.find(greyLeft)&lt;br /&gt;
    #g.highlight(1)&lt;br /&gt;
    while True:&lt;br /&gt;
        g1 = g.right(left.w - g.x)&lt;br /&gt;
        g1.y -= 4; g1.h += 8&lt;br /&gt;
        g1 = g1.exists(greyLeft)&lt;br /&gt;
        if not g1: break&lt;br /&gt;
        g = g1&lt;br /&gt;
    #g.highlight(1)&lt;br /&gt;
    l = g.x + g.w&lt;br /&gt;
    &lt;br /&gt;
    # define the smallest possible image region&lt;br /&gt;
    symbol = Region(l, b - 60, 50, 60)&lt;br /&gt;
    #symbol.highlight(3)&lt;br /&gt;
    return capture(symbol)&lt;br /&gt;
&lt;br /&gt;
def checkCells(imgSymbol, start = 0):&lt;br /&gt;
    # find the cell containing the symbol&lt;br /&gt;
    match = None&lt;br /&gt;
    for i in range(start, len(other)):&lt;br /&gt;
        if other[i].exists(imgSymbol, 0):&lt;br /&gt;
            match = other[i]&lt;br /&gt;
            break&lt;br /&gt;
    if not match: return None&lt;br /&gt;
    &lt;br /&gt;
    return match&lt;br /&gt;
# end function area&lt;br /&gt;
# ------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ----------------------- start of main workflow -------------&lt;br /&gt;
&lt;br /&gt;
# this is based on surfbar6&lt;br /&gt;
# to run this script, surfbar6 must be visible on the screen&lt;br /&gt;
&lt;br /&gt;
#Wait for counter&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Speed up mouse&lt;br /&gt;
Settings.MoveMouseDelay = 0&lt;br /&gt;
# find the position&lt;br /&gt;
imgBase = "1354182180938.png"&lt;br /&gt;
top = find(imgBase)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# get the surfbar&lt;br /&gt;
sbHeight = 85&lt;br /&gt;
sb = top.below(3).below(sbHeight)&lt;br /&gt;
&lt;br /&gt;
sbMarginTopBottom = 20&lt;br /&gt;
sbMarginLeftRight = 20&lt;br /&gt;
leftWidth = 65&lt;br /&gt;
# get the area of the left symbol&lt;br /&gt;
x = sb.x + sbMarginLeftRight&lt;br /&gt;
w = leftWidth - 2 * sbMarginLeftRight&lt;br /&gt;
y = sb.y + sbMarginTopBottom&lt;br /&gt;
h = sbHeight - 2 * sbMarginTopBottom&lt;br /&gt;
left = Region(x, y, w, h)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# setup the regions for the others&lt;br /&gt;
numCells = 4&lt;br /&gt;
oWidth = (sb.w - leftWidth)/4&lt;br /&gt;
other = []&lt;br /&gt;
for i in range(numCells):&lt;br /&gt;
    x = sb.x + leftWidth + i*oWidth - 4&lt;br /&gt;
    other.append(Region(x, sb.y, oWidth+8, sbHeight))&lt;br /&gt;
for r in other:&lt;br /&gt;
    pass&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
found = checkCells(capture(left))&lt;br /&gt;
if not found:&lt;br /&gt;
    for i in range(numCells - 1):&lt;br /&gt;
        symbol = captureSymbol(i)&lt;br /&gt;
        found = checkCells(symbol, i+1)&lt;br /&gt;
        if found: break&lt;br /&gt;
if not found: print "not found"; exit(1)&lt;br /&gt;
click(found)&lt;br /&gt;
type(Key.TAB,KEY_CTRL)&lt;br /&gt;
#Wait for counter on Surfbar to reach Zero&lt;br /&gt;
wait(1)&lt;br /&gt;
&lt;br /&gt;
#Mouse speed&lt;br /&gt;
Settings.MoveMouseDelay = 0&lt;br /&gt;
# find the position&lt;br /&gt;
imgBase = "1354267496167-1.png"&lt;br /&gt;
fix = find(imgBase)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# get the symbol&lt;br /&gt;
rsym = Region(fix.x + fix.w + 8, fix.y + 14, 35, 35)&lt;br /&gt;
symbol = capture(rsym)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# get the surfbar&lt;br /&gt;
sbLeft = fix.right().find("1354267650780.png")&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
sbHeight = 45&lt;br /&gt;
sbWidth = 330&lt;br /&gt;
sb = Region(sbLeft.x + 4, sbLeft.y + 3, sbWidth, sbHeight)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
sbMarginTopBottom = 20&lt;br /&gt;
sbMarginLeftRight = 20&lt;br /&gt;
&lt;br /&gt;
# setup the regions for the others&lt;br /&gt;
numCells = 4&lt;br /&gt;
oWidth = (sb.w)/4&lt;br /&gt;
other = []&lt;br /&gt;
for i in range(numCells):&lt;br /&gt;
    x = sb.x + i*oWidth - 4&lt;br /&gt;
    other.append(Region(x, sb.y, oWidth+8, sbHeight))&lt;br /&gt;
for r in other:&lt;br /&gt;
    pass&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
found = checkCells(symbol)&lt;br /&gt;
if not found: print "not found"; exit(1)&lt;br /&gt;
click(found)&lt;br /&gt;
type(Key.TAB,KEY_CTRL)&lt;br /&gt;
wait(12)&lt;br /&gt;
#Repeat from beginning&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/430463/430463/looping-a-script/</guid>
      <pubDate>Sun, 02 Dec 2012 08:57:37 -0700</pubDate>
      <category>Python</category>
    </item>
  </channel>
</rss>