← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #255838]: Adding a function to a Region Object

 

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

    Status: Open => Answered

RaiMan proposed the following answer:
In Jython we do not have the possibility like in JRuby to dynamically
add/modify functions/methods in existing classes, which would make your
idea rather easy.

So the only possibility left with Jython is to use a wrapper Region
class, that has the modified/added methods and internally delegates to
the original Region class if needed.

class myRegion(Region):
    # define what is needed

The "problem" with Sikuli: 
- you always have to use the myRegion class to create new Region objects, to get your features
- some Sikuli features, that internally create new Regions on the fly, might not reflect your Region version

The easiest way of course is to modify the already existing Region
wrapper in Lib/Sikuli/Region.py

In version 1.1.0 you get the Lib folder automatically, when you select
option 2 (it is contained in the jars sikulix and sikulixapi and is
exported, to allow support for coding assistance in IDE's like Eclipse,
NetBeans, ...).

To activate your modified Lib folder, you have to modify the sys.path at
runtime accordingly.

Another option would be, to unjar sikulix.jar, replace the folder and
build the jar again with the jar utility from the JDK.

Since these features (export and build a jar from scratch) are already contained in SikuliX for internal uses at setup and for other cases, you might as well use these features, to get the Lib folder from sikulix.jar and rebuilt sikulix.jar as needed.
Come back, if you are interested.

I just decided, to add the latter to sikulixsetup as an option.

Be aware: once you start to modify the existing SikuliX artefacts, you
have to be very careful when upgrading to new SikuliX versions and might
have the need to revise/reimplement your features.

Your clickLog feature:
- the use feature will not help with your clickLog function (see above)
- in version 1.2 I will completely revise the logging feature, add better FindFailed handling and provide the possibility to access the last used screenshot at time of search for logging or other purposes

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