if wait(img1) or wait(img2) in statement

Asked by Adrian

Hi there,

i need to wait for one of two images aroud 30 or 240 sec max, and depends on what img is shown do some actions.
Is it possible to do something like that statement?

if wait(IMG1, 240) or wait(IMG2, 240): #script is waiting for one of the images to appear and after i do statement depends on what img appeared
if exists(IMG1) :
     do some action
elif exists(IMG2):
    do another action

now im waiting for IMG1 "wait(IMG1, 240).highlight(1)" which is the best for me becouse IMG1 is appearing more than 80% time, and wait(IMG, 240) can recognise him even if he appear in 40 sec and after that it clicks it instantly without waiting full 240 sec. If IMG2 is appear i ofcourse got error and need to run script again... i want to avoid that ;)

PS i dont want to use if exists(IMG, 240) like in
https://answers.launchpad.net/sikuli/+question/644269
becouse i dont want to wait full 240 sec always, especially when exists() is called sequentially it means that if IMG2 appear i would wait 480 sec to do action... only action after img shown is acceptable for me if it's possible of course :)

Thank You in advance

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
masuo (masuo-ohara) said :
#1

I think onAppear() or findAny() is useful for your case.
http://sikulix-2014.readthedocs.io/en/latest/region.html#find-more-than-one-image-in-a-region-at-the-same-time
http://sikulix-2014.readthedocs.io/en/latest/region.html#Region.onAppear

[example findAny()]
imagelist = ["image000.png","image001.png"]
sleeptm = 1 #ajust according to what you want to do
while True:
    idlist = []
    matchlist = findAny(imagelist)
    if len(matchlist)>0:
        for m in matchlist:
            idlist.append(m.getIndex())
        break
    sleep(sleeptm)

for id in idlist:
    print imagelist[id] + " was found"

Can you help with this problem?

Provide an answer of your own, or ask Adrian for more information if necessary.

To post a message you must log in.