← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #260722]: Can .sikuli project be run from Java code?

 

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

RaiMan proposed the following answer:
This is an approach, to efficiently combine Java coding with SikuliX
features and the SikuliX IDE support.

- have the complete image handling in the IDE, just setting up scripts only containing images
such a script will simply be a list of image file names.
The images are then available in the folder you-name-it.sikuli

- now you code in Java and access the images using setBundlePath() or more efficiently using the ImagePath features.
For these high level features some useable docs are available (start here: http://sikulix.com).

One caveat:
In the IDE you have the Preview feature, that lets you adjust the minimum similarity and the targetOffset resulting in a script code with this template:
Pattern("some-image.png").similar(n.nn).targetOffset(x, y) or
Pattern("some-image.png").exact().targetOffset(x, y) (which is a shortcut for similar(0.99))

So if you use the IDE Preview feature in this case, you will not have
access in your Java code to the Pattern definitions, only the images and
would have to define the Patterns on the Java level again (at least
copy&paste could be used).

A helper in this situation would be some Java feature like this:
a class, that creates some image/pattern container, that analyses the script.py and allows to dynamically access the definitions:

ImageContainer myImages = new ImageContainer("path-to-some.sikuli")

and then use this:
Screen score = new Screen()
Match m = scr.find(myImages.get("somenameXYZ"))

where for the sake of simplicity ImageContainer.get() should simply
return a dynamically created Pattern object in any case.

the script path-to-some.sikuli content:
somename1 = "someImage.png"
somename2 = Pattern("some-image.png").similar(n.nn).targetOffset(x, y)
... and more

which would be easy to scan using pattern matching together with some
container map to store the attributes.

I guess the whole class will have about 20 - 30 lines of code and could
even be used to reuse the image and pattern definitions in existing
scripts, that are migrated to Java (in which case the ref-names might be
the line number of the line the image ore pattern is defined if no name
= is used.

I am just wondering, why not already someone has done and talked about
this ;-)

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