Can't get PyDev to recognize sikuli import

Asked by aidma

I have sikuli setup to work with Eclipse via PyDev, but I've been having difficulty getting Pydev to recognize the 'sikuli' package found in '../sikulixapi.jar/Lib'. The code runs properly, my only problem is getting code-completion and tool-tips to work. Right now my EclipseIDE is filled with false errors, saying that sikuli functions are undefined even though they've been imported.

I was following the instructions from here: https://github.com/RaiMan/SikuliX-2014/wiki/Usage-in-Java-programming, but had no luck. Specifically, I can't get PyDev to add 'sikulixapi.jar/Lib' or 'sikulixapi.jar\Lib' as an External Library.

The problem is not with the Jar, as I can succesfully add 'sikulixapi.jar' as an External Library. Additionally, with 'sikulixapi.jar' as an External Library I am able to get code completion working with the line: "from Lib.sikuli import *". Unfortunately this approach breaks the scripts when I try to run them with "ImportError: No module named Lib".

So, to get code completion working I could do the following:

import org.sikuli.basics.SikulixForJython
try: from Lib.sikuli import *
except: pass
from sikuli import *

But that's inelegant and hacky.

What's the correct way to get code completion working in Eclipse/PyDev?

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
aidma (aidan-mahler13) said :
#1

Adding 'C:\Users\USER\AppData\Roaming\Sikulix\Lib' to the PyDev Python Path works. So I'll do that for now, but it isn't what's described by https://github.com/RaiMan/SikuliX-2014/wiki/Usage-in-Java-programming

Revision history for this message
RaiMan (raimund-hocke) said :
#2

this is the only thing you need if you want to RUN Jython scripts with plain Jython (which is the case in Eclipse/PyDev)
import org.sikuli.basics.SikulixForJython
from sikuli import *

For this only a reference to sikulixapi.jar in the projects PyDev properties is needed (the rest is done in org.sikuli.basics.SikulixForJython

If you want to have full code completion, then you should not use undotted functions (commands ;-) like
click()

the reason behind:
This is a convenience, only available with the Sikuli IDE and with the above statements with plain Jython at runtime. This is a dynamic action assigning all these undotted Region methods from the Java level to the "constant" object SCREEN, which also is assigned at runtime as Screen() (meaning Screen(0).

So these dynamic stuff is not available at the static pre-runtime situation of code-completion.

you have to do the same as you have to do with Java, where it is recommended to say at the beginning:
scr = Screen() # assign Screen(0) to variable scr

and later:
scr.click()

in all situations, where the Region to use is meant the whole primary screen.

This should give you code completion.

Revision history for this message
Best RaiMan (raimund-hocke) said :
#3

... and yes, it seems, that Eclipse/PyDev still does not allow, to name a folder inside a jar file.

As a workaround you can use the exported Lib folder, that you found, which simply is the content of
sikulixapi.jar/Lib

... and yes you are right, the docs should be revised to reflect the current situation.

Revision history for this message
aidma (aidan-mahler13) said :
#4

Oh...

Shoot.

My understanding of how Sikuli works has been radically changed.

I thought that the undotted functions were special class methods. For example, I though that setAutoWaitTimeout() was setting "timeout" class property of all regions, except for ones where it had been overwritten by a dotted Region.setAutoWaitTimeout(). And I thought an undotted click did something like "create a temporary region object with all the default class values, and then preform a click, and then dispose of the temp object"... But that's not how anything works. Instead some black magic was causing undotted methods to act on objects that had been hidden from me.

I understand everything a bit better now.

Revision history for this message
aidma (aidan-mahler13) said :
#5

Thanks RaiMan, that solved my question.