Possible to do exists with a list of items?

Asked by Andrew Munro

I have an issue where there is a choice of different objects that can come up on the screen. Sikuli needs to check if any of them come up, and click on them.

At the moment I am doing an if statement to check if any of them come up, but this seems a bit overkill because I need to perform the same action on multiple images.

Basically what I want is to give it a list and have it perform an action on any item that appears in the list.

eg:

list = [image1, image2, image3, ... image 37]

if exists in (list):
 click item in list

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Best RaiMan (raimund-hocke) said :
#1

Currently, there is not Sikuli feature to accomplish that.

So make your own def:

def clickFromList(images, reg = SCREEN):
    for img in images:
          if reg.exists(img, 0): # only one search
              click(reg.getLastMatch())
              return True
   return False

# usage:
images = [image1, image2, image3, ... image 37]
while not clickFromList(images): pass # will loop until one is found and clicked

This is a basic solution, that will click on the first one, that is found and then terminate.

But be aware:
even with the trick exists(img,0), which will make only one search trial, with the current implementation (even if you restrict the search area to the smallest possible) each unsuccessful find will last 0.3 seconds (with the standard waitScanRate=3.0).
If you search the whole screen this might be 0.5 and more.

So if you need speed, you might try to delegate the searches to threads.

Revision history for this message
Andrew Munro (andrew-munro) said :
#2

Thanks RaiMan. I will try some experimentation with threading and report back if I find a better solution. As we are starting with fairly small lists, I don't see this method as being a problem.

Revision history for this message
Andrew Munro (andrew-munro) said :
#3

Thanks RaiMan, that solved my question.