sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #05137
Re: [Question #170365]: NameError: global name 'Rectangle' not defined
Question #170365 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/170365
Status: Open => Answered
RaiMan proposed the following answer:
Might be a bug. I will report it to the developers.
See below for a workaround.
Using Sikuli's import feature (as you did), it seems, that the imports do not populate the global namespace.
Using the fully qualified package names works.
when using Jythons import (directly importing the testUtility.py) it
works as expected.
I suggest, to make a class, to be more flexible for the future.
Supposing all .sikuli in same directory.
BTW:
-- use raw strings r"some absolute path" - no need to double the backslashes
-- no need to use Java's IO - use Jythons's file() instead
**** case using direct import
--- the testUtility module
from sikuli.Sikuli import * # needed only if Sikuli features are used
from java.awt import *
from javax.imageio import *
import os
class ScreenLog:
def __init__(self, p = r"c:\test", t="jpg"):
self.myRobot = Robot()
self.logPath = p
self.imgType = t
def takeScreenshotOfError(self, filename):
ImageIO.write(self.myRobot.createScreenCapture(Rectangle(Toolkit.getDefaultToolkit().getScreenSize())),
self.imgType, file("%s.%s"%(os.path.join(self.logPath,filename),self.imgType),"w"))
--- the main script:
import os
myPath = os.path.join(os.path.dirname(getBundlePath()), "testUtility.sikuli")
if not myPath in sys.path: sys.path.append(myPath)
from testUtility import *
sl = ScreenLog()
sl.takeScreenshotOfError("test")
**** case using Sikuli's import feature
use fully qualified package names for Java packages
--- the testUtility module
from sikuli.Sikuli import *
import java.awt as Jawt
import javax.imageio as Jimgio
import os
class ScreenLog:
def __init__(self, p = r"c:\test", t="jpg"):
self.myRobot = Jawt.Robot()
self.logPath = p
self.imgType = t
def takeScreenshotOfError(self, filename):
Jimgio.ImageIO.write(self.myRobot.createScreenCapture(Jawt.Rectangle(Jawt.Toolkit.getDefaultToolkit().getScreenSize())),
self.imgType, file("%s.%s"%(os.path.join(self.logPath,filename),self.imgType),"w"))
--- the main script
impPath = "/Users/rhocke/Downloads/15_Sikuli/00_rc3"
if not impPath in sys.path: sys.path.append(impPath)
from testUtility import *
sl = ScreenLog()
sl.takeScreenshotOfError("test")
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.