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

    Status: Open => Answered

RaiMan proposed the following answer:
For this solution a class is not really needed (only if you want to
extend it further with more behavior).

so a function would be sufficient:

def unfocus(obj, sim=0.7, reg=SCREEN):
        to = Location(0,0)
        if obj.__class__.__name__ == "Pattern":
                to = obj.getTargetOffset()
        for i in range(4): 
                if reg.exists(Pattern(obj).similar(sim).targetOffset(to.x, 
to.y),0):
                        return reg.getLastMatch()
                sim -= 0.1
        return false

this solution:
- takes any Region-like object, if omitted searches in SCREEN
- the search object can either be an image or a Pattern
- does not wait 3 seconds with every search (back latest after 3-4 seconds 
instead of 12 -15)
- does not search again if found

comment:
the first 3 lines in the def() are only necessary, because 
Pattern(some_other_pattern) does not preserve a targetOffset.


one more thing (for the developers ;-)
Having a class Pattern, that preserves the targetOffset, the def() would be:

def unfocus(obj, sim=0.7, reg=SCREEN):
        for i in range(4): 
                if reg.exists(Pattern(obj).similar(sim)):
                        return reg.getLastMatch()
                sim -= 0.1
        return false

class Pattern is really poor currently:
- should preserve the attributes when based on another Pattern
- should accept a Location object as targetOffset

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

_______________________________________________
Mailing list: https://launchpad.net/~sikuli-driver
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~sikuli-driver
More help   : https://help.launchpad.net/ListHelp

Reply via email to