sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #06966
Re: [Question #179084]: looking for several pictures and return value
Question #179084 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/179084
Status: Open => Answered
RaiMan proposed the following answer:
--1. exact() seems to have a bug - use similar(0.99) instead. But even
that normally is not needed. But give it a try.
--2. for these situations, the first version is principally the choice,
since in the second case, a not successful find() would stop the script
with a FindFailed exception.
--3. If you make a case decision with exists(), you should use
exists(image,0), so it does not wait 3 seconds, if the case is not true
(image not there).
So this should work as expected:
def chkpic():
if exists("img1", 0):
return 1
elif exists("img2", 0):
return 2
elif exists("img3", 0):
return 3
To be more flexible and have a chance, to debug the situation:
def chkpic(debug = False):
ret = 0
if exists("img1", 0):
ret = 1
elif exists("img2", 0):
ret = 2
elif exists("img3", 0):
ret = 3
if debug and ret > 0:
print ret, "---", getLastMatch()
So when using chkpic(), no message will be printed, but for debugging
purposes you can use chkpic(True), which would print you a message,
showing the match, which gives you a chance to check e.g. the similarity
score.
To make this function even more generally usable:
def chkpic(images, debug = False):
ret = 0
for i in range(len(images)):
if exists(images[i], 0):
ret = i
break
if debug and ret > 0:
print ret, "---", getLastMatch()
and the usage would be:
chkpic(("img1", "img2", "img3"))
or
chkpic(("img1", "img2", "img3"), True)
So you can use the function in different places with different lists of
images.
--
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.