← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #230529]: Region subclass inheritance loop

 

Question #230529 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/230529

    Status: Open => Answered

RaiMan proposed the following answer:
I made some tests even with plain Jython:
There seem to be some problems with using super(), like it should be used with Python versions < 3.0 (the way you use it).

I did not get simple basic inheritance running with overwritten methods (I did not any Sikuli features). 
The problem only arises when overwriting methods.

So if you want to overwrite Region methods, this is how it works:

class Sub(Region):
    n = 0
    def __init__(self, reg):
        print "Sub:init"
        Region.__init__(self, reg)
        print "Sub:", self

    def find(self, ps):
        print "Sub:find", ps       
        return Region.find(self, ps)
        
r = Region(0,0,300,300)
r.highlight(2)
y = Sub(r)
print y.find("e4.png") # my test case ;-)

This fulfills all your aspects the same way as super() would do and is
acceptable, since your sub class is specifically written to inherit from
Sikuli's class Region.

super() is only really of value, if you want to write a class template,
that might inherit from different super classes.

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.