← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #171701]: What is expected behavior with onAppear handlers

 

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

    Status: Open => Answered

RaiMan proposed the following answer:
The pairing is not onXXX() -- observer(), it is
one region  has one observer which has one handler and might have multiple onXXX

So if you want to have different handlers, you need to bind the observe
to different region objects (which might all be the whole screen):

reg1 = Screen(0)
reg1.onAppear(, handler1)
reg1.observe()

and so on.

The other possibility is, to have only one handler (which means one
region and one observer)  and you check inside the handler, what
happened (see docs: http://sikuli.org/docx/region.html#SikuliEvent).
The big challenge with multiple observes is to integrate them into the
workflow and set up some "communication" between the main workflow and
the handler. The easiest way is to implement a global dictionary
containing key/value pairs.

--- my experience:
observe only pays back on effort and complexity, if you run it in background (in parallel). Instead of using observe inline (the script waits) I find it always easier and more transparent to use exists(). With exists(,0) and small regions you might even check for some visuals (4 -5 for a cost of about 1 - 2 seconds) in "parallel".

On the Python script level, I even think, that the threading module
makes it easier, to detach some parallel processing than using
observe(,background = True).

I have a function "wait for multiple images", that just loops around
some exists(,0) for the specified waiting time and returns a structure
of the matches, that can be analyzed afterwards.

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