How to use the location object

Asked by mach81

I am aware that Sikuli provides Region function to ensure that only a specific area of the screen is referenced. But while implementing this I am still facing issues with identification. Hence I would like the provide the script the specific location of the screen elements which I want Sikuli to identify.
It would be great if someone can provide me directions (or code snippets if possible) of how to use the Location object in conjunction with the Region object.
Also, does the location object capture relative screen location or absolute one.

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
RaiMan (raimund-hocke) said :
#1

Regions are used to identify rectangular areas on the screen for whatever purposes. Usually they are used to restrict the search region. But also they can be used as references for other regions or points (Locations are simply one pixel on the screen).

m = find(some_image)
click(m.getTopLeft())

would click at the top left corner of the found image.

click(m.below(200))

would click at a point 200 pixels towards bottom of screen from center of found image

r = selectRegion() # lets you select an area
click(r)

would click at the center of the selected area.

Point coordinates (a Location or the top left corner of a region) are given in world coordinates relative to the top left corner of the primary screen:
right below: (positive, positive)
right above: (positive, negative)
left below: (negative, positive)
left above: (negative, negative)

A defined Region or Location will be mapped to the corresponding physical screen at time of usage (find operations, mouse actions, capturing, ...). Being completely outside any physical screen at this time is an error.

More details can be found in the docs: http://doc.sikuli.org

Revision history for this message
mach81 (ghosh-mayukh) said :
#2

Thanks for the indepth explanation. While capturing an image with Sikuli, is there a provision of managing (or knowing) the exact pixels being captured.

Revision history for this message
RaiMan (raimund-hocke) said :
#3

Currently a captured image on the Sikuli Script level (Jython scripting) after saying

img = capture()

img will be the path of an image file in the file system.

Sikuli Script currently has no features to access the image information on the pixel level.

If you want to do that, you have to use Java features (which are available in Sikuli scripts) from Java's image libraries.

What exactly do you want to do?

Revision history for this message
mach81 (ghosh-mayukh) said :
#4

I have a screen with multiple checkboxes, one below the other. I had used the Region function and the following code - Region(521,583,175,24).click("1375274985504.png") for identifying and click on a specific checkbox. But when I implented the same code for multiple checkboxes, Sikuli clicked on the incorrect checkbox.
Hence I was looking of specifying the exact screen location of the checkbox in order to ensure that the correct one is being clicked.

Revision history for this message
RaiMan (raimund-hocke) said :
#5

reg = Region(x,y,w,h) # the region containing a column of checkboxes
cb = <captured image of a check box>

allCB = reg.findAll(cb) # finds all checkboxes in the region
# allCB contains all ckeckbox matches in a random order

allCBsorted = sorted(allCB, key=lambda m: m.y)
# now allCBsorted is a list of all checkbox matches in the region sorted top down

click(allCBsorted[5])
# will click the sixth (list indexes count from 0) checkbox from the top

Can you help with this problem?

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

To post a message you must log in.