← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #189092]: A Simple Region.onChange request

 

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

    Status: Open => Answered

RaiMan proposed the following answer:
this should work.

def test_exampleTest(self):
        nav = Region(Region(569,809,144,36))
        def changeHandler(event):print"work ya bastard"
        nav.onChange(5,changeHandler)
        nav.observe()
        type(Key.DOWN)
        wait(1)
        type(Key.RIGHT)
        wait(1)
        type(Key.RIGHT)
        wait(1)
        type(Key.RIGHT)
        wait(1)

The onXXX() add an attribute to the region, that should be observed. This has to be done only one time. The region knows this stuff as long as it lives.
Saying observe() switches the observation on (in your case for about 3 seconds) and then stops it. If something changed in the region meanwhile the handler is called every time something changes.
Therefor, one usually stops the observation in the handler with the first event and gives the observation some time to wait.

So the above part would be e.g.

        def changeHandler(event):
            print"work ya bastard"
            event.region.somethingChanged = True
            event.region.stopObserver()
        nav.onChange(5,changeHandler)
        nav.somethingChanged = False
        nav.observe(10)
        if not nav.somethingChanged:
            print nab, "did not change within observation time"
            exit(1)

I have added some coding, to check, wether the handler was visited
(something changed) in the code following the observe.

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