What is expected behavior with onAppear handlers

Asked by Beth Griffin

To drive a Microsoft Visual Studio debug session, I did the following:

onAppear("BP1.png", BP1Handler) # Visual Studio stops at first breakpoint
observe()
type(Key.F5)
onAppear("BP2.png", BP2Handler)
observe()
type(Key.F5)
...

there are about 10 onAppear/observe pairs.

At the end of each handler, I have event.region.stopObserver(). Before that, I am looking at the contents of various Visual Studio views to make sure the contents are correct given the breakpoint.

My question is: how do I disable a handler.

I'm finding that after calling onAppear("BP2.png", BP2Handler), if BP1.png can still be found on the screen by the second observe(), then BP1Handler is getting called again, which doesn't make sense, since it does actions based on the specific breakpoint location. Being able to disable the handler would be great.

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

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.

Can you help with this problem?

Provide an answer of your own, or ask Beth Griffin for more information if necessary.

To post a message you must log in.