← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #286623]: Using A list of regions Sikuli crashes ?

 

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

    Status: Open => Answered

RaiMan proposed the following answer:
Your usage of the sorted function does not make sense.
That it does not come back might be because your usage produces internally an endless loop - just guessing.

Ignoring your intention, the correct usage would be:

# variable names should start with lowercase letter
listR = [region1, region2, region3, region4, region5, region6, region7, region8]
img =Pattern("img.png").similar(0.67)
# Sort key function
def crosscheck(reg): # the parameter is the next list element to be sorted
    if reg.exists(img):
         return 0
    return 1
# Main function
while exists("loopImage.png"):
    sortedMatches = sorted(listR, key=crosscheck)

this would sort the regions, where the img was found, to the start of
the list (with no specific sequence) and the others towards the end. But
you do not have an information, in which regions the image was found.

matches = [] # to get the matches
listR = [region1, region2, region3, region4, region5, region6, region7, region8]
img =Pattern("img.png").similar(0.67)

for reg in listR:
    matches.append(reg.exists(img, 0)) # only 1 search, do not wait on not found

for n in range(len(listR)):
    if matches[n]: 
        listR[n].highlight(1)

the information, which region has a match, is preserved in matches in the same order as listR.
The second loop highlights only regions, that had a match in the first loop.

-- 
You received this question notification because your team Sikuli Drivers
is an answer contact for Sikuli.