sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #05157
Re: [Question #170365]: Name Error using Java classes in imported script --- workaround
Question #170365 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/170365
Description changed to:
***** workaround
when importing other .sikuli, use Java's fully qualified package names
in the imported modules.
see comment #2 below
If you decide to use the direct import of the contained .py files, you
have to import each class package like:
from some.java.package import Class
so you can use later
x = Class()
see comment #4 below
----------------------------------------------------------------
Hi,
I created a utility module that will assist me in taking screenshots
when my script runs into an error, but I'm getting "NameError: global
name 'Rectangle' not defined" and am not sure why.
Here are my functions:
--------------------------------------------------
my file directory is this
--------------------------------------------------
./testMain
./testUtility
--------------------------------------------------
testMain contains
--------------------------------------------------
import os
myPath = os.path.dirname(getBundlePath())
if not myPath in sys.path: sys.path.append(myPath)
from testUtility import *
takeScreenshotOfError("myError.jpg")
--------------------------------------------------
testUtility contains
--------------------------------------------------
from java.awt import Robot
from java.awt import Toolkit
from java.awt import Rectangle
from java.io import File
from javax.imageio import ImageIO
def takeScreenshotOfError(filename):
testResultsPath = "c:\\test\\"
robot = Robot()
theImage = robot.createScreenCapture(Rectangle(Toolkit.getDefaultToolkit().getScreenSize()))
ImageIO.write(theImage, "jpg", File(testResultsPath+filename))
-----------------------------------------
this is the error i get when i run testMain in sikuli IDE
theImage = robot.createScreenCapture(Rectangle(Toolkit.getDefaultToolkit().getScreenSize())) NameError: global name 'Rectangle' is not defined
can anyone help me with this? the code works when when it's all
contained in one file, but i need it to be modular so other sikuli
scripts can use the screenshot function.
thanks
--
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.