Can Sikuli Methods be Overridden?

Asked by Grant Young on 2012-05-15


I'm trying to find out if the custom methods in siluli, e.g. click(), can be overridden using jython? I ask as I'm looking to add additional features to the methods at the API level. Such as measuring the time it takes for the button to be found and clicked each time.

Any help would be brilliant.


Question information

English Edit question
Sikuli Edit question
No assignee Edit question
Last query:
Last reply:
j (j-the-k) said : #1

I would suggest something like this:

import sikuli.Sikuli as sikuli # import sikuli manually to get access to the original methods

def click(img):
    # do custom stuff # execute sikuli original method

click("img.png") # should now execute custom click command

RaiMan (raimund-hocke) said : #2

@ (j-the-k)
principally ok, but the sikuli.Sikuli does not contain the click() and other Region methods.
They are either in sikuli.Region or in the Java Region class.
And most of the methods are instance methods and not class methods.

So your click() suggestion will only work for unqualified usages, which search on the whole screen. will still use the Region method.

*** Depending on what you want to achieve (e.g. some wrapping), you have to use something like:

class myRegion (Region):

     def __init__(self, reg):
          self.theReg = reg

     def click(self):
           # some code
           # some code

usage e.g.
reg = find(something)

This would help in the mentioned situation (track timing).

The problem in Python/Jython is, that you might well subclass, but not selectively override on the method level (as is possible e.g. in JRuby) (with the normal language features).
There are other possibilities, if you step down to the Java level (which can be done from the Sikuli script level).

*** Another possibility for the time tracking issue:

def xt(cmd):
    # timer start
    ret = eval(cmd)
    # timer end

usage e.g.

j (j-the-k) said : #3

Okay I dind't think about, you're right RaiMan.

Can you help with this problem?

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

To post a message you must log in.