Error when running sikuli with jython under Eclipse

Asked by sikuli user

Hi,

I am new in sikuli, eclipse and jython and I'm having difficulties in running them together. I've seen all the questions and answers related to this topic but still couldn't solve my problem

What I did until now:
- had pydev plugin installed in eclipse and had jython set as the interpreter by adding sikuli-script.jar as the interpreter executable; also I added sikuli folder(from C:\Program Files\Sikuli\sikuli-script\lib\sikuli) to the System PYTHONPATH because I understood from one of the answers on the forum that this folder is not visible if it is in the sikuli-script jar. (I also tryed to have the interpreter executable jython.jar)

- I created a new project and added as external libs sikuli-script.jar and D:\sikuli_pict_lib.sikuli (this is the folder where I keep my screenshots)

- have OpenCV added to my Path (windows XP)

- I have the following piece of code in eclipse:

import os
import sikuli.Sikuli as sikuli
import edu.mit.csail.uid.Screen as screen

def google():
    pict_path="D:\\sikuli_pict_lib.sikuli"
    sikuli.setBundlePath(pict_path)
    if screen.exists("D:\\sikuli_pict_lib.sikuli\\exist_pg_google.png",10):
        screen.type("write_asdf.png", "asdf", 0)
        screen.click(0, "click_search.png")
        screen.wait("pg_rezults.png")

google()

and I get the following error when running:

ScreenMatchProxy loaded.
VDictProxy loaded.
Win32Util loaded.
ScreenMatchProxy loaded.
Traceback (most recent call last):
  File "C:\Documents and Settings\dragosb\workspace\MyJytonProject\src\root\nested\example.py", line 32, in <module>
    google()
  File "C:\Documents and Settings\dragosb\workspace\MyJytonProject\src\root\nested\example.py", line 26, in google
    if screen.exists("D:\\sikuli_pict_lib.sikuli\\exista_pg_google.png",10):
TypeError: exists(): self arg can't be coerced to edu.mit.csail.uid.Region

Please let me know if you're having any idea of what I'm doing wrong.

Thanks a lot!

Question information

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

1. --- The interpreter has to be Jython (selectable/configurable on the project preferences)

I have put the sikuli folder into the lib/site-packages folder of Jython (I have installed my own version of Jython), so I only need sikuli-script.jar in external libraries for the java part.

There is no need to put your image lib as external library.

2. --- try
from sikuli.Sikuli import *

instead of

import sikuli.Sikuli as sikuli
import edu.mit.csail.uid.Screen as screen

3. --- my version
pict_path="D:\\sikuli_pict_lib.sikuli" # put it outside, so it is global

def google():
    sikuli.setBundlePath(pict_path)
    if exists("exist_pg_google.png",10): # no path, it is in the bundle
        type("write_asdf.png", "asdf", 0)
        click(0, "click_search.png")
        wait("pg_rezults.png")

google()

Without any qualification, the Sikuli functions automatically act on the constant object SCREEN, which is set to Screen(0) at Sikuli initialization

Revision history for this message
sikuli user (dragos-bordeianu) said :
#2

Thanks a lot for your answer!

It works now BUT I still have a little problem. In Eclipse, on the left side there's the red sign with the warning "Undefined variable: click" (same for 'wait' and 'exists' , ok for type). How could escape this issue?

Thanks again!

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

Since Windows/Eclipse is not my main Focus (using Netbeans on Mac), I stopped my research, when I was able to run and debug Sikuli scripts with Eclipse.

It seems that the syntax checker does not have access to the function definitions inside sikuli-script.jar. So it reclaims click e.g as an unknown name. (Netbeans has no problems with that)

type is ok, because it is defined in basic python too.

I guess it is some speciality with the Python plugin, that has to be further tracked down.

I hope you understand, that I have to leave you alone with that :-(

If you find out: feedback appreciated.

Good luck.

Revision history for this message
sikuli user (dragos-bordeianu) said :
#4

Thanks a lot for all your help! If I'll find a way to solve this issue I'll let you guys know!
Best regards!

Revision history for this message
saurabh devgun (saurabhdevgun) said :
#5

Hi Dragos ,

Did you find any solution to the red sign warning messages ?? If yes , Please share with me as well .

Revision history for this message
Ulf Tidstrand (ulf-tidstrand) said :
#6

I had similar issues with the error markers.

After some investigation it seems like PyDev sometimes has problems importing code completion information since it only does static analysis of the imported modules. It seems like the Sikuli module does a lot of importing dynamically which works fine during runtime, but not statically in Eclipse/PyDev.

This is what I did to make it work:

1) Select Window --> Preferences --> PyDev --> Interpreters --> Jython Interpreter
2) In tab "Libraries": Add sikuli-java.jar ("New Jar/Zips")
3) In tab "Libraries": Add the Lib source folder unzipped from sikuli-java.jar (containing the Sikuli python source code).
4) In tab "Forced Builtins" - add the string "sikuli.Sikuli" and then click "apply"
5) Close all source code windows and reopen them to reload code completion information (alternatively right click on project and select PyDev --> Remove Error Markers)

Item 4 is the one that actually does the trick. Item 2 and 3 are only prerequisites for item 4.

More general information about this issue is available here:
http://pydev.org/manual_101_interpreter.html