Pass Location() as a parameter in definition

Asked by nuknuk on 2020-08-21

I created the following definition to calculate new click location when a windowed application is moved around.

app = App("someapp")

def clickloc(X, Y):
    app.focus()
    appregion = Region(App.focusedWindow())
    appregionx = appregion.getX()
    appregiony = appregion.getY()
    click(Location(appregionx+X,appregiony+Y))

clickloc(1194, 109)

I would like to just use clickloc(Location(1194, 109)) because it's a lot easier to just use the IDE's Location button after typing clickloc.

How would I go about that? Wasn't sure how to pass location object as a parameter.

Also, is there a better method than doing app.focus() then the Region(App.focusedWindow())?

Tried the following but gave wrong coords.

 appregion = App("someapp").focusedWindow()

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
2020-08-21
Last query:
2020-08-21
Last reply:
2020-08-21
Best RaiMan (raimund-hocke) said : #1

def clickloc(myLocation):
    app.focus()
    appregion = Region(App.focusedWindow())
    appregionx = appregion.getX()
    appregiony = appregion.getY()
    click(Location(appregionx+myLocation.x,appregiony+myLocation.y))

clickloc(insertedOffset)

nuknuk (nuknuk88) said : #2

Thanks RaiMan!

nuknuk (nuknuk88) said : #3

Thanks RaiMan, that solved my question.