Search code examples
sortingjythonsikuli

Convert iterator objects from findAll to images in Sikuli after sorting


So I'm having an issue working with Sikuli. There's a situation where multiple occurrences of an image exist. To grab all of them, you can simply do a findAll, but it saves each image as some sort of object, rather than the image. I know that you can get the images by using getLastMatches(), but I want to sort it first. So here's the code that I got that grabs all the images and sorts them. I found some of the information on the Sikuli documentation

def by_y(match):
  return match.y

icons = findAll(image)
sorted_icons = sorted(icons, key=by_y)

The problem with this, though, is that sorted_icons contains a bunch of iterable objects (at least that's what I saw them called), and not the images. Is there a way to revert back to an image while keeping the new list sorted? Using getLastMatches() gives a list of the original unsorted list.

Also, it's Sikuli 1.0.1.

Thanks.

This should illustrate the problem (hopefully). In order to sort the images by their y value, I have to use the findAll() operation (if there is a way of doing this without using find then please share). However, this converts the image from a string, i.e.:

"imagename.png"

into... well whatever this is (match?):

M[8,1045 37x28]@S(S(0)[0,0 1920x1080]) S:1.00 Center:26,1059

the self.assets.getimage(image) function requires a string, though (so the imagename.png) rather than the funky thing you get out of using find.

def exampleMethod(image, dx=0, dy=0):
    click(Pattern(self.assets.getimage(image)).targetOffset(dx, dy))

def by_y(match):
  return match.y

image = "imagename.png"
icons = findAll(image)
sorted_icons = sorted(image, key=by_y)

exampleMethod(sorted_icons[0])

Therefore, I need 1 of 2 things:

  1. A way to convert the find object back to a String AFTER sorting
  2. A way to sort the images by their y values while keeping the images as strings

Hopefully this helps.


Solution

  • Just a quick info. JePySi doesn't deal with dynamic allocation of icons/images. This needs to be completly implemented with Sikuli features. So autoKarma is right self.assets.getImage() is useless in this context, since it only accessses pre-registered images which are addressed by name only. Hence only string operations.

    Cheers, Alex - I wrote JePySi :-)