← 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:
---        popup("found something")
... will never be executed because it is after the return

--- sub class def (if it makes sense at all)
class MyRegion(Region):
    def __init__(self, region, regionName = "noNameDefined"):
        self.superRegion = region
        self.name = regionName

--- a method overwriting existing Region method
    def find(self, ps):
        popup("about to find something")
        match = self.superRegion.exists(ps)
        if match:
            popup("found something")
        else:
            popup("found nothing")
        return match


--- and a possible usage:

baseRegion = Region(....) # somehow get your working region
searchRegion = MyRegion(baseRegion)
match = searchRegion.find("some image.png")
if not match: exit(1)

--- but if the goal is to only have the popups then this is much easier:

def myFind(ps, reg=None):
    if not reg: reg = SCREEN
    popup("about to find something")
    match = reg.exists(ps)
    if match:
        popup("found something")
    else:
        popup("found nothing")
    return match

match = myFind("some image.png") # whole screen
match = myFind("some image.png", Region(....)) # restrict to the given region

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