sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #27610
Re: [Question #252905]: i want sikuli to select options closest to the mouse pointer location when there are more then one matches present
Question #252905 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/252905
RaiMan proposed the following answer:
@Eugene
this might be an heuristic approach, to be able to find a region, that contains the nearest element.
This is a more general solution:
import math
# used by sorted, to calculate the distance to refLocation
# the sort function uses this value for sorting the list elements
def by_nearest(match):
x = math.fabs(match.getCenter().x - refLocation.x)
y = math.fabs(match.getCenter().y - refLocation.y)
distance = int(math.sqrt(x * x + y * y))
return distance
img = "some-image.png" # the image to look for
refLocation = Env.getMouseLocation() # the reference point
# use findAll(), to find all matches on screen
# and create the sorted list
sortedMatches = sorted(findAll(img), key=by_nearest)
# list contains the elements sorted by distance in ascending order
# hence the first element is the one we are looking for
sortedMatches[0].highlight(2)
--
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.