When use type(Key.DOWN) in python script, get NameError: Key

Asked by Libo Cao

I was trying to use the method type(Key.DOWN) on windows XP platform -- sikuli package 0.10.1

In Sikuli IDE it is fine, but when use this in a python script (with import sikuli stuff), this method gives NameError: Key

Even if I put Key.py file under the import path and put from Key import * inside the sikuli.py file, it is not doing anything.

Why is that?

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Libo Cao
Solved:
Last query:
Last reply:
Revision history for this message
Libo Cao (libocao) said :
#1

I read this post
https://bugs.launchpad.net/sikuli/+bug/536708

but it does not help. It did not explain what have changed in Key class from
0.9.9 and above.

On Thu, Aug 12, 2010 at 6:11 PM, Libo Cao <
<email address hidden>> wrote:

> New question #120917 on Sikuli:
> https://answers.launchpad.net/sikuli/+question/120917
>
> I was trying to use the method type(Key.DOWN) on windows XP platform --
> sikuli package 0.10.1
>
> In Sikuli IDE it is fine, but when use this in a python script (with import
> sikuli stuff), this method gives NameError: Key
>
> Even if I put Key.py file under the import path and put from Key import *
> inside the sikuli.py file, it is not doing anything.
>
> Why is that?
>
> You received this question notification because you are a direct
> subscriber of the question.
>

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

My answer on your same comment with bug 536708 was, before seeing this entry:

This is because the class Key is only defined on the Jython layer, that seems not to be accessible when running sikuli-script from Java.

but it should be rather easy to circumvent, since you only have to use the corresponding unicode characters, as listed in the source of class Key:
http://bazaar.launchpad.net/%7Esikuli-dev/sikuli/0.10/annotate/head%3A/sikuli-script/src/main/python/sikuli/Key.py

You say:
Even if I put Key.py file under the import path and put from Key import * inside the sikuli.py file, it is not doing anything.

This is really strange, since Key.py only defines some constants and after importing Key.py, at least there should be no name errors any longer with something like Key.ENTER.

Revision history for this message
Libo Cao (libocao) said :
#3

I did try the type(u"\ue002") , but that does not do the trick neither.
Anything wrong here?

As for the Key still won't get recognized after importing issue, that is
strange to me too, maybe it has something to do the way I call my script,
here is the command

java -Dpython.path=Lib/ -jar sikuli-script.jar TEST_SUITE_HERE

the Lib is the one extracted from the sikuli-script.jar, and inside the Lib.
In my python script, I do import like this:

from python.edu.mit.csail.uid.Sikuli import *

I found the Sikuli.py inside Lib folder, so I added "from Key import * ",
also put the key.py file under the same folder, however it still does not
recognize the class.

Maybe when I call from java, it does not use the python path Lib at all?
however if that is true, I cannot even run my script without defining the
python path.

Libo

On Fri, Aug 13, 2010 at 12:00 AM, RaiMan <
<email address hidden>> wrote:

> Your question #120917 on Sikuli changed:
> https://answers.launchpad.net/sikuli/+question/120917
>
> RaiMan posted a new comment:
> My answer on your same comment with bug 536708 was, before seeing this
> entry:
>
> This is because the class Key is only defined on the Jython layer, that
> seems not to be accessible when running sikuli-script from Java.
>
> but it should be rather easy to circumvent, since you only have to use the
> corresponding unicode characters, as listed in the source of class Key:
>
> http://bazaar.launchpad.net/%7Esikuli-dev/sikuli/0.10/annotate/head%3A/sikuli-script/src/main/python/sikuli/Key.py
>
> You say:
> Even if I put Key.py file under the import path and put from Key import *
> inside the sikuli.py file, it is not doing anything.
>
> This is really strange, since Key.py only defines some constants and
> after importing Key.py, at least there should be no name errors any
> longer with something like Key.ENTER.
>
> --
> You received this question notification because you are a direct
> subscriber of the question.
>

Revision history for this message
Tsung-Hsiang Chang (vgod) said :
#4

Your import path is wrong, python.edu.mit.csail.uid.Sikuli is the old python path(0.9).
You should use sikuli.Sikuli instead in 0.10.

Revision history for this message
Libo Cao (libocao) said :
#5

I tried to do that before, but the following won't work at all.
from sikuli.Sikuli import *

under the Lib folder, there is a Sikuli.py, I tried to also modify it, it
still does not work.

Libo

On Fri, Aug 13, 2010 at 11:35 AM, Tsung-Hsiang Chang <
<email address hidden>> wrote:

> Your question #120917 on Sikuli changed:
> https://answers.launchpad.net/sikuli/+question/120917
>
> Tsung-Hsiang Chang posted a new comment:
> Your import path is wrong, python.edu.mit.csail.uid.Sikuli is the old
> python path(0.9).
> You should use sikuli.Sikuli instead in 0.10.
>
> --
> You received this question notification because you are a direct
> subscriber of the question.
>

Revision history for this message
Libo Cao (libocao) said :
#6

Actually "from Sikuli import * " works, I will see if I can get the Key_DOWN
working too

On Fri, Aug 13, 2010 at 12:00 PM, Libo Cao <
<email address hidden>> wrote:

> Your question #120917 on Sikuli changed:
> https://answers.launchpad.net/sikuli/+question/120917
>
> You gave more information on the question:
> I tried to do that before, but the following won't work at all.
> from sikuli.Sikuli import *
>
> under the Lib folder, there is a Sikuli.py, I tried to also modify it, it
> still does not work.
>
> Libo
>
> On Fri, Aug 13, 2010 at 11:35 AM, Tsung-Hsiang Chang <
> <email address hidden>> wrote:
>
> > Your question #120917 on Sikuli changed:
> > https://answers.launchpad.net/sikuli/+question/120917
> >
> > Tsung-Hsiang Chang posted a new comment:
> > Your import path is wrong, python.edu.mit.csail.uid.Sikuli is the old
> > python path(0.9).
> > You should use sikuli.Sikuli instead in 0.10.
> >
> > --
> > You received this question notification because you are a direct
> > subscriber of the question.
> >
>
> --
> You received this question notification because you are a direct
> subscriber of the question.
>

Revision history for this message
Libo Cao (libocao) said :
#7

If I use

type(u"\ue002")

from Sikuli IDE it works fine, but when embeded inside python script, it
gives error like

sikuli-script.jar\Lib/python/edu/mit/csail/uid/Sikuli.py", line 403, in type
java.lang.illegalArgumentException: java.lang.illegalArgumentException:
Cannot type character (a smily face here)

On Fri, Aug 13, 2010 at 2:48 PM, Libo Cao <
<email address hidden>> wrote:

> Your question #120917 on Sikuli changed:
> https://answers.launchpad.net/sikuli/+question/120917
>
> You gave more information on the question:
> Actually "from Sikuli import * " works, I will see if I can get the
> Key_DOWN
> working too
>
> On Fri, Aug 13, 2010 at 12:00 PM, Libo Cao <
> <email address hidden>> wrote:
>
> > Your question #120917 on Sikuli changed:
> > https://answers.launchpad.net/sikuli/+question/120917
> >
> > You gave more information on the question:
> > I tried to do that before, but the following won't work at all.
> > from sikuli.Sikuli import *
> >
> > under the Lib folder, there is a Sikuli.py, I tried to also modify it, it
> > still does not work.
> >
> > Libo
> >
> > On Fri, Aug 13, 2010 at 11:35 AM, Tsung-Hsiang Chang <
> > <email address hidden>> wrote:
> >
> > > Your question #120917 on Sikuli changed:
> > > https://answers.launchpad.net/sikuli/+question/120917
> > >
> > > Tsung-Hsiang Chang posted a new comment:
> > > Your import path is wrong, python.edu.mit.csail.uid.Sikuli is the old
> > > python path(0.9).
> > > You should use sikuli.Sikuli instead in 0.10.
> > >
> > > --
> > > You received this question notification because you are a direct
> > > subscriber of the question.
> > >
> >
> > --
> > You received this question notification because you are a direct
> > subscriber of the question.
> >
>
> --
> You received this question notification because you are a direct
> subscriber of the question.
>

Revision history for this message
Tsung-Hsiang Chang (vgod) said :
#8

Given you error message, it looks like you were running an old
sikuli-script.jar.
Can you see if your sikuli-script.jar is from the latest release?

Revision history for this message
Libo Cao (libocao) said :
#9

You are right, with the latest sikuli-script.jar, the tmplib, and the Lib folder extracted from the right jar, also right "from sikuli.Sikuli import *", it works fine.

Thanks