sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #33258
Re: [Question #268579]: Java API - How to sort matches in Java IDE
Question #268579 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/268579
Description changed to:
Hello, Dear Colleagues.
I wrote code in Sikuli IDE with two requirements:
1). Sort all matches, returned with findall() method;
2). Click on all matches except the last.
But I cannot implement perform none of these two conditions in Java IDE: it clicks on all images and in random order.
Could you please help me with that? Thanks.
Code:
Clicker.java:
package sikuli;
import java.util.Iterator;
import org.sikuli.script.FindFailed;
import org.sikuli.script.Match;
import org.sikuli.script.Pattern;
import org.sikuli.script.Screen;
public class Clicker {
static Screen scr1 = new Screen(0);
static String path = "images.sikuli\\plus.png";
static Pattern pat = new Pattern(path).similar(0.95f);
static int count = 0;
public static void clicker(){
try{
Iterator<Match> matches = scr1.findAll(pat);
for (; matches.hasNext(); matches.next()) {
count++;
Match m = matches.next();
System.out.println(m);
scr1.click(m);
clicker();
break;
}
}
catch(FindFailed e){
e.printStackTrace();
}
}
}
Sikuli.java:
package sikuli;
import org.sikuli.script.*;
public class Sikuli {
public static void main(String[] args) throws FindFailed{
Clicker.clicker();
System.out.println(Clicker.count);
}
}
Working code from Sikuli IDE:
def order(match):
return match.y, match.x
def CLICKER():
scr1 = Screen(0) #or Screen(0) for default monitor
pat = Pattern("plus.png").similar(0.95) # this is plus "+" image
sorted_icons = sorted(list(scr1.findAll(pat)), key=order)
for icon in sorted_icons:
if len(sorted_icons) != 1:
click(icon)
CLICKER()
break
CLICKER()
--
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.