← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #207264]: Setting Default Region?

 

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

RaiMan proposed the following answer:
@ Grant
the with-magic is only supported for methods belonging to the class and it's parents, that the with block was created for.
since every def() you use inside a with block does not belong to the with object, inside these def's the default "magic" SCREEN is used.

The first supposed solution is the "normal" one, but you need to change
all your library functions, which I would do generally  this way:

def eitherOr(imageList, myRegion=SCREEN):
        for x in range(0, len(imageList)):
            print x
            if(myRegion.exists(imageList[x], 0)):
                return imageList[x]

So SCREEN is used if you do not use a second parameter like
eitherOr([img1, img2])

But this solution is not very elegant together with the with feature.

The "real" solution would be, to completely override the Region class
(including the original content) and add your functions.

As an alternative, you might experiment with setROI() instead of using
with. This would avoid to adapt the lib functions.

myReg = Region(App("Chrome").window())
setROI(myReg)

# with myReg:
from import lib *
eitherOr([img1, img2])

setROI(Screen(0)) # reset to whole screen

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