← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #702308]: many matched components, how to decide which to click?

 

Question #702308 on SikuliX changed:
https://answers.launchpad.net/sikuli/+question/702308

    Status: Open => Answered

Manfred Hampl proposed the following answer:
Since there has not been any answer from other persons, I suggest using
https://sikulix-2014.readthedocs.io/en/latest/match.html?highlight=findall#iterating-
over-matches-after-findall

Use findall to identify all matches
loop through the list of matches:
 calculate the distance to the center for the current match, if it is better than the previous value, save the match

It should be possible to use sorting as shown in https://sikulix-2014.readthedocs.io/en/latest/region.html#Region.findAll
probably something like 
Settings.MinSimilarity = 0.97 # or whatever value you need
icons = findAll("png_icon.png")
sorted_icons = sorted(icons, reverse=True, key=lambda m: (SCREEN.getH/2 - m.getY)*(SCREEN.getH/2 - m.getY) + (SCREEN.getW/2 - m.getX)*(SCREEN.getW/2 - m.getX))
and finally sorted_icons[0] should be the match that is closest to the screen center.

(no warranty given that this works as desired)

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