sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #41247
Re: [Question #434360]: Find match exit from pool of images using one if condition
Question #434360 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/434360
Status: Open => Answered
Roman Podolyan proposed the following answer:
1) I use Python dictionary datatype for that. SikuliX supports
dictionaries, including dictionaries for images
Demo code (tested).
_________
Settings.MinSimilarity = 0.95
image_dictionary = {"sumatra":"sumatra_icon.png" ,"firefox":
"firefox_icon.png", "chrome": "chrome_icon.png" }
for key in image_dictionary.keys():
if exists(image_dictionary[key]):
hover(getLastMatch())
_______
"sumatra" here is a dictionary key (a string), and "sumatra_icon.png"
stands for image of Sumatra PDF editor icon.
I go by keys, not by images themselves (which I also could), as I may
need found key needed for some different operation. For instance, the
code can be further enhanced with "message dictionary" to log some pre-
defined message if Sumatra icon was found, etc:
_________
message_dictionary = {"sumatra":"Sumatra PDF editor" ,"firefox": "Firefox browser", "chrome": "Chrome browser" }
...
print (message_dictionary[key]) + " was found"
_________
{Note about Java. Java has similar datatype, HashMap, which can be used
in similar construction }.
I prefer dictionary/hashmap for things like these, as string index can
be more helpful than numeric here.
2) Things like
______
try {
fr.click(StaticImages.fn_DisabledCloseDialogNoButton());
} catch (FindFailed e) {
LogReport.error("Unable to click on NO button on disabled Close button dialog");
e.printStackTrace();
}
____
Can be packed into function
def try_to_click_and_log(key):
try {
fr.click(image_dictionary[key]);
} catch (FindFailed e) {
LogReport.error(message_dictionary[key]);
e.printStackTrace();
}
3) To speed up image search consider if you can restrict search region. For instance, if images you expect can be found only in center part of the screen, you can construct special region for that with Region(x,y,width,height).
--
You received this question notification because your team Sikuli Drivers
is an answer contact for Sikuli.