← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #231495]: highlight (and other region methods?) not working with Region subclass

 

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

Description changed to:
For starters, here are the main characteristics of the test code I have below (the real code I cut this down from is more useful and less bogged down with prints, but this version of it illustrates the issue)
-I have subclassed Region with a class called MyRegion
-I have added a pad method which pads a region by a certain number of pixels and trims it to a bounding region
-I have added print statements everywhere to show progress along the way

The code:

===============================================================================
class MyRegion(Region):
    def __init__(self, region):
        Region.__init__(self, region)
    def debugPrintCoords(self):
        print("x: " + str(self.x) + " y: " + str(self.y) + " w: " + str(self.w) + " h: " + str(self.h))
        return self
    def pad(self,pad,bound):
        print(">MyRegion.pad: start")
        print(">MyRegion.pad: printing coords before pad")
        self.debugPrintCoords()
        self.setRect(self.x - pad, self.y - pad, self.w + (2*pad), self.h + (2*pad))
        print(">MyRegion.pad: printing coords after pad")
        self.debugPrintCoords()
        self.trimToBounds(bound)
        print(">MyRegion.pad: printing coords after trim")
        self.debugPrintCoords()
        print(">MyRegion.pad: over")
        return self
    def trimToBounds(self, bounds):
        print(">>MyRegion.trimToBounds: caller is: " + inspect.stack()[1][3])
        print(">>trimToBounds: printing coords of self")
        self.debugPrintCoords()
        print(">>trimToBounds: printing coords of bounds")
        bounds.debugPrintCoords()
        print(">>trimToBounds: printing coords of intersection")
        tRect = self.getRect().createIntersection(bounds.getRect())
        print(">>>>>>>>>>>>>>>>>>>>>> x: " + str(tRect.x) + " y: " + str(tRect.y) + " w: " + str(tRect.width) + " h: " + str(tRect.height))
        self.setW(tRect.width) 
        self.setH(tRect.height)
        self.setX(tRect.x)
        self.setY(tRect.y)
        print(">>trimToBounds: printing coords after intersection applied")
        self.debugPrintCoords()
        print(">>MyRegion.trimToBounds: over")
        return self

screenRegion = MyRegion(Region(Screen(0).getBounds()))
boundaryRegion = MyRegion(Region(307,71,1122,544))
regionToExpand = MyRegion(Region(317,107,22,16)).highlight(1)
print(">reference coords: printing boundaryRegion coords")
boundaryRegion.debugPrintCoords().highlight(1)
print(">padding regionToExpand")
regionToExpand.pad(400,boundaryRegion)  

print("RESIZED REGION PROPERTY COMPARISON:")
myRegion = regionToExpand
region = Region(regionToExpand)
myRegionRect = myRegion.getRect()
regionRect = region.getRect()
print("myRegion raw properties: x: " + str(myRegion.x) + " y: " + str(myRegion.y) + " w: " + str(myRegion.w) + " h: " + str(myRegion.h))
print("myRegion raw getters: x: " + str(myRegion.getX()) + " y: " + str(myRegion.getY()) + " w: " + str(myRegion.getW()) + " h: " + str(myRegion.getH()))
print("myRegion getRect properties: x: " + str(myRegionRect.x) + " y: " + str(myRegionRect.y) + " w: " + str(myRegionRect.width) + " h: " + str(myRegionRect.height))
print("myRegion getRect getters: x: " + str(myRegionRect.getX()) + " y: " + str(myRegionRect.getY()) + " w: " + str(myRegionRect.getWidth()) + " h: " + str(myRegionRect.getHeight()))
print("region raw properties: x: " + str(region.x) + " y: " + str(region.y) + " w: " + str(region.w) + " h: " + str(region.h))
print("region raw getters: x: " + str(region.getX()) + " y: " + str(region.getY()) + " w: " + str(region.getW()) + " h: " + str(region.getH()))
print("region getRect properties: x: " + str(regionRect.x) + " y: " + str(regionRect.y) + " w: " + str(regionRect.width) + " h: " + str(regionRect.height))
print("region getRect getters: x: " + str(regionRect.getX()) + " y: " + str(regionRect.getY()) + " w: " + str(regionRect.getWidth()) + " h: " + str(regionRect.getHeight()))

myRegion.highlight(1) #failure point: despite all the other stuff being right, somehow the highlighting reveals different co-ordinates
region.highlight(1) 
===============================================================================

In order, the code highlights:
-the original region to be expanded
-the bounding region
-the padded region after trimming, without a cast from MyRegion to parent class Region
-the padded region after trimming, casted to Region

When I run this code, I expect it to pad the region then bound it. As
can be seen by the highlighting and the print statments though, despite
all the co-ordinates looking fine no matter how I access them, highlight
won't work properly unless I cast to Region. The last two
lines/highlights should look the same. What's going wrong?

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