Why does onChange() work with a sikuli.Region and not with a org.sikuli.script.Region

Asked by Pierre Best

I'm using Eclipse, Sikuli-API-1.0.0-Win32 and jython 2.7b1 to script some tests. I wanted to set up an observer but everytime I tried to set up the handler with Region.onChange() it would fail with the error

invalid Region - use r = Region(r) before as workaround [error] observe(): Nothing to observe (for Jython: region might be invalid)

I finally tracked the problem down to the fact that I'd been using org.sikuli.script.Region rather than sikuli.Region.

In fact all my imports are from org.sikuli.script but I haven't had any problems up until now. Should I be importing objects from sikuil rather than org.sikuli.script?

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
RaiMan (raimund-hocke) said :
#1

---1. you should update to version 1.0.1 and select setup option 3 to get the sikuli-java.jar

---2. proceed according to: https://github.com/RaiMan/SikuliX-API/wiki/Usage-in-Java-programming

---3. importing from the Java level might have worked in the past, but was never defined for the Sikuli basic classes like Region, Screen, Match, Location, ...
It is recommended to use from sikuli import * and then just use the Sikuli features as mentioned in the docs.

---4. When using Jython, you MUST use the Region() to get a new Region. Do not step down to the Java level.

Revision history for this message
Pierre Best (pierre-best) said :
#2

I've followed your instructions in steps 1, 2, 3 and 4.
When I try to debug the program I get the following output:

pydev debugger: starting
[debug] SikuliXforJython: sys.path[0]: C:\Users\pierreb\Documents\alphapack test plan\sikuli-alphapack\AlphaPack.sikuli
[debug] SikuliXforJython: sys.path[1]: C:\Users\pierreb\Downloads\sikuli\eclipse\eclipse\plugins\org.python.pydev_2.8.2.2013090511\pysrc
[debug] SikuliXforJython: sys.path[2]: C:\Users\pierreb\Documents\alphapack test plan\sikuli-alphapack\AlphaPack.sikuli
[debug] SikuliXforJython: sys.path[3]: C:\Users\pierreb\Documents\alphapack test plan\sikuli-alphapack\AlphaPack.sikuli\Application.jar
[debug] SikuliXforJython: sys.path[4]: C:\Apps\sikuli-api-1.0.1\sikuli-java.jar
[debug] SikuliXforJython: sys.path[5]: C:\Apps\sikuli-api-1.0.1\libs
[debug] SikuliXforJython: sys.path[6]: C:\Apps\sikuli-api-1.0.1\libs\Lib
[debug] SikuliXforJython: sys.path[7]: C:\Apps\jython\2.7b1\Lib
[debug] SikuliXforJython: sys.path[8]: C:\Apps\jython\2.7b1\Lib\site-packages
[debug] SikuliXforJython: sys.path[9]: __classpath__
[debug] SikuliXforJython: sys.path[10]: __pyclasspath__/
[debug] SikuliXforJython: found Sikuli Jython in:
/C:/Apps/sikuli-api-1.0.1/sikuli-java.jar/Lib
[debug] SikuliXforJython: Trying to add to sys.path
[debug] SikuliXforJython: new Jython path:
[debug] SikuliXforJython: sys.path[0]: C:\Users\pierreb\Documents\alphapack test plan\sikuli-alphapack\AlphaPack.sikuli
[debug] SikuliXforJython: sys.path[1]: C:\Users\pierreb\Downloads\sikuli\eclipse\eclipse\plugins\org.python.pydev_2.8.2.2013090511\pysrc
[debug] SikuliXforJython: sys.path[2]: C:\Users\pierreb\Documents\alphapack test plan\sikuli-alphapack\AlphaPack.sikuli
[debug] SikuliXforJython: sys.path[3]: C:\Users\pierreb\Documents\alphapack test plan\sikuli-alphapack\AlphaPack.sikuli\Application.jar
[debug] SikuliXforJython: sys.path[4]: C:\Apps\sikuli-api-1.0.1\sikuli-java.jar
[debug] SikuliXforJython: sys.path[5]: C:\Apps\sikuli-api-1.0.1\libs
[debug] SikuliXforJython: sys.path[6]: C:\Apps\sikuli-api-1.0.1\libs\Lib
[debug] SikuliXforJython: sys.path[7]: C:\Apps\jython\2.7b1\Lib
[debug] SikuliXforJython: sys.path[8]: C:\Apps\jython\2.7b1\Lib\site-packages
[debug] SikuliXforJython: sys.path[9]: __classpath__
[debug] SikuliXforJython: sys.path[10]: __pyclasspath__/
[debug] SikuliXforJython: sys.path[11]: /C:/Apps/sikuli-api-1.0.1/sikuli-java.jar/Lib
[debug] ResourceLoaderBasic: SikuliX Package Build: 1.0.1 12SEP2013135849
[debug] Jython: sikuli: __init__: entering
[debug] Jython: sikuli: Sikuli: entering
[debug] Jython: sikuli: Sikuli: constants
[debug] Jython: sikuli: Sikuli: import Region
[debug] Jython: sikuli: Sikuli: import Screen
[debug] Jython: sikuli: Sikuli: Env.addHotkey
[debug] Jython: sikuli: Sikuli: import Match
[debug] Jython: sikuli: Sikuli: import Pattern
[debug] Jython: sikuli: Sikuli: import Location
[debug] Jython: sikuli: Sikuli: import ScreenUnion
[debug] Jython: sikuli: Sikuli: import Finder
[debug] ResourceLoaderBasic: check: we are running on arch: x86
[debug] ResourceLoaderBasic: check: using Java at: C:/Program Files (x86)/Java/jdk1.7.0_40/jre/
[debug] ResourceLoaderBasic: check: Exists libs folder at location of jar? YES: C:/Apps/sikuli-api-1.0.1/
[debug] ResourceLoaderBasic: checkLibsDir: C:/Apps/sikuli-api-1.0.1/libs
[error] ResourceLoaderBasic: checkLibsDir: libs dir is not on system path: C:\Apps\sikuli-api-1.0.1\libs
C:\Windows\system32
C:\Windows
C:\Apps\Sikuli-api-1.0.1\libs\
C:\Apps\Sikuli-api-1.0.1\libs\Lib\
C:\Program Files (x86)\Java\jdk1.7.0_40\jre\bin
[action] ResourceLoaderBasic: checkLibsDir: Please wait! Trying to add it to user's path
[debug] ResourceLoaderBasic: runcmd: reg QUERY HKCU
[info] runcmd: reg QUERY HKCU
[debug] ResourceLoaderBasic: runcmd: reg QUERY HKEY_CURRENT_USER\Environment /v PATH
[info] runcmd: reg QUERY HKEY_CURRENT_USER\Environment /v PATH
[debug] ResourceLoaderBasic: checkLibsDir: current:(HKEY_CURRENT_USER\Environment PATH): C:\Apps\sikuli-api-1.0.1\libs;%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;%JYTHON_HOME%;%JYTHON_HOME%\bin;%SIKULI_HOME%;%SIKULI_HOME%\libs
[error] ResourceLoaderBasic: checkLibsDir: Logout and Login again! (Since libs folder is in user's path, but not activated)
[error] Terminating SikuliX after a fatal error! Sorry, but it makes no sense to continue!
If you do not have any idea about the error cause or solution, run again
with a Debug level of 3. You might paste the output to the Q&A board.
[debug] SikuliXFinal: cleanUp: 0
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8

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

--- This is how this should be read:
[error] ResourceLoaderBasic: checkLibsDir: libs dir is not on system path: C:\Apps\sikuli-api-1.0.1\libs
-- we expect to be on system path (you have SikuliX installed in C:\Apps\sikuli-api-1.0.1)

-- the current system path:
C:\Windows\system32
C:\Windows
C:\Apps\Sikuli-api-1.0.1\libs\
C:\Apps\Sikuli-api-1.0.1\libs\Lib\
C:\Program Files (x86)\Java\jdk1.7.0_40\jre\bin
-- C:\Apps\Sikuli-api-1.0.1\libs\ should be recognized, but is not because of the trailing backslash (a minor bug of course)
-- C:\Apps\Sikuli-api-1.0.1\libs\Lib\ does not make sense on system path

-- now we try to add it to the user path as first entry
[action] ResourceLoaderBasic: checkLibsDir: Please wait! Trying to add it to user's path
[debug] ResourceLoaderBasic: runcmd: reg QUERY HKCU
[info] runcmd: reg QUERY HKCU
[debug] ResourceLoaderBasic: runcmd: reg QUERY HKEY_CURRENT_USER\Environment /v PATH
[info] runcmd: reg QUERY HKEY_CURRENT_USER\Environment /v PATH

-- this is the result (written to the registry
[debug] ResourceLoaderBasic: checkLibsDir: current:(HKEY_CURRENT_USER\Environment PATH): C:\Apps\sikuli-api-1.0.1\libs;%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;%JYTHON_HOME%;%JYTHON_HOME%\bin;%SIKULI_HOME%;%SIKULI_HOME%\libs

-- to activate this, at least a logout login is necessary
[error] ResourceLoaderBasic: checkLibsDir: Logout and Login again! (Since libs folder is in user's path, but not activated)

--- You should do the following, to make things going:
- remove from system path (is on user path now)
C:\Apps\Sikuli-api-1.0.1\libs\

- remove the path entry (not needed)
C:\Apps\Sikuli-api-1.0.1\libs\Lib\

- remove from your user path settings:
%SIKULI_HOME%;%SIKULI_HOME%\libs (no longer used by Sikuli)

-- restart your system and try Sikuli again.

Revision history for this message
Pierre Best (pierre-best) said :
#4

Thanks RaiMan, that solved my question.