[1.0] problems importing .sikuli scripts in the same directory

Asked by rob

hello,

i am trying to import one .sikuli file into another so that i can reuse some code. both files are in the same folder.

this is what i tried first:

from sikuli import *
from java.awt import Toolkit
from java.awt.datatransfer import DataFlavor
from org.sikuli.script.natives import Vision
import os
#get the directory containing your running .sikuli
myPath = os.path.dirname(getBundlePath()) #line 9
if not myPath in sys.path: sys.path.append(myPath) # line 10
import oxpToolKit
App.focus('*new 1 - Notepad++')
type('a', KeyModifier.CTRL)
type('c', KeyModifier.CTRL)
print oxpToolKit.getClipboardText()

and this is the error message i got:

Exception in thread "Thread-12" java.lang.IllegalStateException: No match found
at java.util.regex.Matcher.group(Unknown Source)
at org.sikuli.ide.SikuliIDE$ButtonRun.findErrorSourceWalkTrace(Unknown Source)
at org.sikuli.ide.SikuliIDE$ButtonRun.findErrorSource(Unknown Source)
at org.sikuli.ide.SikuliIDE$ButtonRun.access$1500(Unknown Source)
at org.sikuli.ide.SikuliIDE$ButtonRun$1.run(Unknown Source)

[error] script [ scratch ] stopped with error in line 11
[error] ImportError ( No module named oxpToolKit )

i also tried it with lines 9 and 10 commented out and i got the same error code. im on windows 8

thanks in advance for any help you can give me

Question information

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

Supposing this:

some_script.sikuli # importing oxpToolKit
opxToolKit.sikuli # either this or
opxToolKit.py

in the same folder.

then
import oxpToolKit

should work without any extra sys.path handling, since Sikuli's import automagically finds importable stuff in the same folder that contains the importing script.sikuli

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

if it really does not work, pls. add the following:

try:
    import oxpToolKit
except:
    for e in sys.path: print e
    exit()

and post the printout

Revision history for this message
rob (reg82) said :
#3

it still didnt work, i tried it on windows 7 and windows 8

this is the printout i got from the try statment :

C:\Program Files\sikuli\Lib
C:\Program Files\sikuli\sikuli-script.jar\Lib
__classpath__
__pyclasspath__/
C:/Program Files/sikuli/
C:/Users/rgonzales.TEAMPOSTOP/Desktop/oxp/scratch.sikuli/
C:/Users/rgonzales.TEAMPOSTOP/Desktop/oxp/
C:\Users\rgonzales.TEAMPOSTOP\Desktop\oxp\oxpToolKit.sikuli

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

sys.path looks ok.

Sure, you do not have any syntax error in your oxpToolKit.sikuli ?

Revision history for this message
rob (reg82) said :
#5

well i just tried importing a test script with just a single variable and it worked, so i must have a syntax error somewhere, oxpToolKit.sikuli runs without problems on its own though, so i guess i will have to search through the file and look for it.
thank you raiman. you have been a great help, as usual.

Revision history for this message
rob (reg82) said :
#6

i believe i found the problem. originally oxpToolKit was called workToolKit. as i started writing more code i decided to rename it, but i only renamed the .sikuli folder and not the python file. once i renamed the .py file it worked as expected.

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

LOL, one of the oldest oddities with Sikuli.

I will add an error message to the Sikuli import for the case that a script.sikuli does not contain a script.py.