← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #167084]: Can Find(<image> or <image>) be used, what would the syntax be?

 

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

    Status: Open => Answered

RaiMan proposed the following answer:
You have to make it on your own, since there is no such feature.

-- The easiest way: using sequential exists()
if exists(img1):
   #do something
elif exists(img2):
   # do something else
else:
   print "neither img1 nor img2"

This depends on the sequence and img2 processing will not be done, if
img1 is there. If img1 does not exist it will take 3 seconds until img2
will be searched.

--- most sophisticated
# each find action is only done once
# all images are found
# information about what images were found is available
# a max time for whole action is spacified
imgs = [img1, img2, img3]
t = 3 # waiting time
res = [False for img in imgs]

start = time.time()
while time.time()-start < t:
    for i in range(len(imgs)):
        if exists(imgs[i], 0):
            res[i] = True
    if True in res: break
print res

res contains the information, which of the images where found

so if you only want to know, that at least one of the images was there:

if True in res:
    # do something
else:
    # none of the images where found

specific actions depending on a specific image:

if res[0]:
    # special action for image 1   

*** comments
- when trying to understand scripts, it is a good idea to look into the docs in parallel
http://sikuli.org/docx/
- you need some basic knowledge of Python language, if you want to do more complex things. Especially the indentation magic is always a hurdle for beginners.

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