addHotkey cannot coerce 3rd argument to HotkeyListener
I am using this version of the IDE: 2.0.4-2020-
When I use the following program in the Sikuli IDE, it works as expected, and I can break out of the program by typing Ctrl-Shft-F:
running = True
def quitApp(event):
print "handler quit ctrl-shft-f"
global running
running = False
Env.addHotkey('f', KeyModifier.CTRL + KeyModifier.SHIFT, quitApp)
while running:
print "hello"
sleep(1)
So far so good. Then I try to run the exact same program from Jython command line (with Sikulixapi-
from org.sikuli.script import *
running = True
def quitApp(event):
print "handler quit ctrl-shft-f"
global running
running = False
Env.addHotkey('f', KeyModifier.CTRL + KeyModifier.SHIFT, quitApp)
while running:
print "hello"
sleep(1)
However, when I run this, I get the following error:
Traceback (most recent call last):
File "temp.py", line 10, in <module>
Env.
TypeError: addHotkey(): 3rd arg can't be coerced to org.sikuli.
Any idea what might be causing the problem?
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
|
#1 |
from org.sikuli.script import *
should not be used and is not necessary in any case.
Only in sub-scripts (Python scripts called from a main script) you need: (see docs)
from sikuli import *
Revision history for this message
|
#2 |
Hi RaiMan, thanks for the quick response!
If I remove the "from org.sikuli.
Traceback (most recent call last):
File "C:/Users/Peter Zejda/Google Drive/home/
Env.
NameError: name 'Env' is not defined
Process finished with exit code -1
If I replace it with the line "from sikuli import *", then I get this error:
Traceback (most recent call last):
File "C:/Users/Peter Zejda/Google Drive/home/
from sikuli import *
ImportError: No module named sikuli
Process finished with exit code -1
I read a lot of the documents, and also the did some fair amount of Googling, and also tried many variations, and that's how I eventually ended up with the "from org.sikuli.
import org.sikuli.
from sikuli import *
While this seems to work well within the Console (plus an additional couple of lines before it to print out the Python version and add the working directory to the path), when run in the stand-alone script it gives:
Traceback (most recent call last):
File "C:/Users/Peter Zejda/Google Drive/home/
from sikuli import *
File "C:\Users\Peter Zejda\AppData\
from Sikuli import *
File "C:\Users\Peter Zejda\AppData\
import org.sikuli.
java.lang.
at java.lang.
at java.lang.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at sikuli.
at sikuli.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at sikuli$
at sikuli$
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
Caused by: java.lang.
at java.net.
at java.lang.
at sun.misc.
at java.lang.
... 58 more
java.lang.
Process finished with exit code -1
I also have the following environment variables set up, though I'm not sure they are all necessary:
CLASSPATH=
JYTHONPATH=
JYTHON_
Revision history for this message
|
#3 |
tested on my Windows 10 - works.
I have a Jython 2.7.1 installed at c:\jython2.7.1
I use the following command script to run Jython:
set jython=
set CLASSPATH=
%jython% %*
Using the script without parameters opens the interactive Jython prompt.
Running this script (<some-
import org.sikuli.
from sikuli import *
for e in sys.path: print e
runs as expected without any errors and prints:
C:\Users\
C:\Users\
C:\Users\rmhde
C:\jython2.7.1\Lib
__classpath__
__pyclasspath__/
C:\jython2.
The first import takes care, that the folder <app-data>\Lib is on sys.path.
The second import initializes the API.
Revision history for this message
|
#4 |
Thanks RaiMan, that solved my question.
Revision history for this message
|
#5 |
Thanks, RaiMan. I implemented the simple script just as you provided, and also set the same environment variables. It seems that the culprit was that I was using:
CLASSPATH=
That is, I was using the API jar file instead of the IDE jar file. I think in reading the various documentation, somehow I had the impression that I need that library when using Sikuli outside of the Sikuli IDE.
Anyway, again, thanks for the pointer.
Revision history for this message
|
#6 |
Sorry for the mistake.
When running Jython from commandline directly, one should not use the IDE jar, because it already contains all the stuff needed to run Jython - might collide on sys.path.
my final test command script hence was:
set jython=
set CLASSPATH=
%jython% %*
this worked also and should be used.
Revision history for this message
|
#7 |
Hi RaiMan,
Well, it was a happy accident. For me, the IDE jar file works correct, but if I set the CLASSPATH to the API jar file, then it fails. So I guess I can just still to the ID version of the jar file (as a reasonable workaround for myself).
If interested, here is the output with the CLASSPATH being set back and forth, and the corresponding results.
C:\Users\Peter Zejda\Google Drive\home\
C:\Users\Peter Zejda\AppData\
C:\Users\Peter Zejda\AppData\
C:\Users\Peter Zejda\Google Drive\home\
C:\non-
C:\non-
__classpath__
__pyclasspath__/
C:\non-
C:\Users\Peter Zejda\Google Drive\home\
C:\non-
C:\Users\Peter Zejda\Google Drive\home\
C:\Users\Peter Zejda\Google Drive\home\
Traceback (most recent call last):
File "temp.py", line 2, in <module>
from sikuli import *
File "C:\Users\Peter Zejda\AppData\
from Sikuli import *
File "C:\Users\Peter Zejda\AppData\
import org.sikuli.
java.lang.
at java.lang.
at java.lang.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at sikuli.
at sikuli.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at sikuli$
at sikuli$
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
Caused by: java.lang.
at java.net.
at java.lang.
at sun.misc.
at java.lang.
... 58 more
java.lang.
C:\Users\Peter Zejda\Google Drive\home\
C:\Users\Peter Zejda\Google Drive\home\
C:\Users\Peter Zejda\AppData\
C:\Users\Peter Zejda\AppData\
C:\Users\Peter Zejda\Google Drive\home\
C:\non-
C:\non-
__classpath__
__pyclasspath__/
C:\non-
C:\Users\Peter Zejda\Google Drive\home\
For whatever reason, the API jar files seems to have trouble finding the ITesseract class.
Revision history for this message
|
#8 |
Ah, please ignore all of this :-(. Just in case, I re-downloaded both the IDE and the API jar files, this time being sure to pull them down directly from https:/
Sorry to have troubled you and wasted your time :-\.