sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #33581
Re: [Question #269004]: isinstance(Region) vs. isinstance(Region.nearby) not giving the same result
Question #269004 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/269004
Status: Open => Answered
RaiMan proposed the following answer:
this is a historical oddity, that we have to live with, because I have
to stay with this to be backwards compatible.
On the Python API level, there is a Python class Region, that is a superclass of the Java API class with the same name.
So depending on how the Region object tested came into life, it is either an instance of the Python class Region or of the Java class Region (org.sikuli.script.Region).
The complete (99 %) API of "class Region" is implemented at the Java
level. So if a Region.method() returns a new Region object, this is
always a org.sikuli.script.Region object (as reg.nearby(5) in your
case).
You can cast every Region object to be Python Region using
reg = Region(reg)
Your check case could easily be solved this way:
if isinstance(reg, Region) or isinstance(reg, JRegion): print "is a
region"
JRegion is a name that is created in the global namespace at SikuliX
startup using
import org.sikuli.script.Region as JRegion
to be able to later during init say
class Region(JRegion): # define the Python class Region as superclass of org.sikuli.script.Reagion
...
--
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.