← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #160030]: String returned from findAll() function are not in order of their occurrence in Screen

 

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

    Status: Open => Answered

Tsung-Hsiang Chang proposed the following answer:
Suppose your question is ordered by from top to bottom, you need to sort the matches by their y coordinates.
Here is a sample code that shows to how to do this.
 
---
def by_y(match):
    return match.y

icons = findAll( [ANY_IMAGE] )
sorted_icons = sorted(icons, key=by_y) # sort the icons by their y coordinates and put them into a new variable sorted_icons
print sorted_icons 

---
A shorter version is using lambda.
icons = findAll( [ANY_IMAGE] )
sorted_icons = sorted(icons, key=lambda m:m.y)

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