sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #34287
Re: [Question #270538]: Is there a way to remove the sikuli import feature in the nightly build?
Question #270538 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/270538
RaiMan proposed the following answer:
I just made some evaluation with 1.1.0.
Subclassing of Region on the Python scripting level is only possible if you either
1. do not use __init__ in your subclass
or
2. if you use __init__, you have to take care, that your Region object has valid pos (x,y) and dim (w,h)
--- in case 1.
the standard constructors are available (which are implemented on the Java level only). If you need initialisation of your subclassed Region objects, you have to find another way for that, for example
reg = subRegion(<region init parameters>)
reg.init(<your private parameters>)
--- in case 2:
you have to implement an __init__ that accepts the standard Region init parameters (x,y,w,h or another Region object) and then use
self.setROI(<region init parameters>)
to make your Region valid.
this is an example:
class XRegion(Region):
def __init__(self, *args):
if len(args) == 1:
self.setROI(args[0])
elif len(args) == 4:
self.setROI(args[0], args[1], args[2], args[3])
else:
self.setROI(SCREEN)
self.img = "image.png"
def doFind(self):
m = self.find(self.img).highlight(2)
return m
print XRegion()
reg = XRegion(0,0,500,500)
print reg
reg = XRegion(reg)
print reg
reg = XRegion(reg.doFind())
print reg
prints:
R[0,0 1440x900]@S(0)[0,0 1440x900] E:Y, T:3.0
R[0,0 500x500]@S(0)[0,0 1440x900] E:Y, T:3.0
R[0,0 500x500]@S(0)[0,0 1440x900] E:Y, T:3.0
R[257,119 58x72]@S(0)[0,0 1440x900] E:Y, T:3.0
to add userargs to the constructor, you have to implement an __init__ like this:
def __init__(self, *args, **userargs):
and handle the userargs keyword parameters accordingly
another maybe easier implementation is to use
def __init__(self, *args):
and always use the first parameter as <region init parameter> as a list,
that either contains 4 values or 1 value or is empty. Of course you have
to adapt the handling in __init__ accordingly.
usage:
XRegion([], userparm1, userparm2)
reg = XRegion((0,0,500,500), userparm1, userparm2)
XRegion((reg,), userparm1, userparm2)
--
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.