project extending SikuliX functionality

Asked by Kinga Wierchomska on 2020-08-21

Hi, I am working on extending SikuliX. I want to create classes with my methods, which I will be able to use in SikuliX IDE. I know I can do this by modifying API (adding my class) and then in Sikuli.py file importing this particular class. Unfortunately I do not want to modify SikuliX API, only extend it, so is there any other way of adding new classes to python skripts in order to use its methods later in IDE? Maybe I should overwrite this Sikuli.py script in my project? Thank you in advance :)

Question information

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

Just create your extending classes the usual way:

mySXAPI.sikuli:

from sikuli import *
class Region(Region):
    def clickX(whatever):
        #do something special
        click(whatever_modified)

... and in your scripts running in the IDE (main scripts)
from mysxapi import *
# use your classes

Be aware: all your methods wether new or overwriting have to be used as reg.myAPImethod() where reg is valid Region object.

recommendations:
- do not overwrite Sikuli.py
- use your own classnames like:
class Area(Region):

... so it is always clear, what is what.

RaiMan (raimund-hocke) said : #2

sorry must read:
from mySYAPI import *

Thank you for your answer, but I've had something different in my mind. I want to create my own Java classes and use its methods in IDE without creating instances of this classes in scripts (methods like click, wait etc. works that way in sikulix IDE). How can I achieve that?

RaiMan (raimund-hocke) said : #4

Ok, understood.

Then as a base you have to do everything like mentioned above.

To use your defined functions undotted like click(), ... they have to be added to the globals inventory.
This is a dynamic process at runtime.

How this is done in SikuliX can be found in Sikuli.py, which is triggered at runtime by a
from sikuli import *

before a script is executed (automatically for main scripts, added into imported scripts)

The top function is
use()

which defines the global constant SCREEN object.

use() then internally calls
_exposeAllMethods(...)

which does the registering of the class Screen methods.

... but you will not get what you want without at least one import at the top of all your scripts.

Does this mean that I need to create my own python script which is basically the same as Sikuli.py and import it in my scripts written in IDE?

RaiMan (raimund-hocke) said : #6

not really.

your mySikuli.py only must contain your extending classes/methods and your version of __exposeAllMethods(...), that registers your methods globally, that are intended to be used undotted.

In a main script you then need at the top:
from mySikuli import *

and in imported script it must be
from sikuli import *
from mySikuli import *

Sikuli.py actually cannot be modified, because it is replaced with a fish copy from the jar with every start of the IDE.

And one more question - do I need to add sikulix IDE to my project as dependency?

RaiMan (raimund-hocke) said : #8

what kind of project?

I am creating maven project with classes which extend sikuliX API as I've mentioned earlier and I use sikuliX API as a dependency. I want to be able to use methods of this classes in IDE and because of that I was asking above questions - so how can I add sikuliX IDE to my project and this script which we discussed?

RaiMan (raimund-hocke) said : #10

ok, sorry - did not remember, that your extensions are done at the Java level.

Make a jar with your extending classes and eventual dependencies, that are not available in sikulixapi.jar, but excluding sikulixapi.jar and its dependencies, since it is already bundled with sikulixide.jar.

Then put this jar into the SikuliX extensions folder on your system <sikulix-appdata>/extensions.

During startup of the IDE your jar will then be put on class path and hence available in the IDE.

The rest (to make it available at the Jython level) see above.

RaiMan (raimund-hocke) said : #11

Sorry, the folder for extensions is:

<sikulix-appdata>/Extensions

Can you help with this problem?

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

To post a message you must log in.