How to set offset to top left of IMAGE, instead of center of image

Asked by Jimin Fan on 2017-01-10

Hey guys,

So I'm stuck with a small puzzle; Recently, I've decided to upgrade my test suites to SikuliX, from an older version of Sikuli from 4 years ago. The old click(x, y) method would find the image, and click x units right, and click y units down from the TOP LEFT of the image, where it is represented by (0, 0) coordinate. In SikuliX, offsetX and offsetY seem to be calculated with the SCREEN dimensions in mind. To avoid having to change every Click() in my test suites, I just want to change the customized click function I made, by converting the offSet calculations from relative to the screen, to relative to the image found.

Here's an example of what I'm trying to do:

def Click(png,offsetX,offsetY, conf=0.70):
    #If pattern returns NO MATCH, return 0
    if exists(Pattern(png).similar(conf)) == None:
        print("Did not find " + png)
        return 0

    else:
        # Find returns a match object
        m = find(Pattern(png).similar(conf))

        # v1 = ???? Some calculation to use relative image x
        # v2 = ???? Some calculation to use relative image y

        print(str(m.getTarget().getX()) + " , " + str(m.getTarget().getY()))

        # Clicks with an @offsetX, and NEGATIVE offsetY, because we are using relative position to
        # x = 0, y = 0. Normally, it is returned as middle of the image
        click(Pattern(png).targetOffset(v1, v2))
        return 1

I'm just posting here before I start experimenting with numbers, I figured someone has had to have run into this before. I will close this if I find the solution myself, thanks!

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
Jimin Fan
Solved:
2017-01-10
Last query:
2017-01-10
Last reply:
Jimin Fan (jimin) said : #1

Seems like I was overthinking it....

All I have to do is:

click(Pattern(png).targetOffset(offSetX/2 , offSetY/2))

:)