[1.0.1] OnAppear()/observe() only works the first time for one image in same region

Bug #1201280 reported by RaiMan
14
This bug affects 2 people
Affects Status Importance Assigned to Milestone
SikuliX
Fix Committed
Critical
RaiMan

Bug Description

--- fixed with 1.1.0

see the docs:
http://sikulix-2014.readthedocs.org/en/latest/region.html#observing-visual-events-in-a-region

for how to repeat onAppear()/onVanish() in the same observe run
---------------------------------------------------------------

my purpose is to deal w/ 1 button which will appear several times in a game(actually it is the angrybird game) ,then i used the onappear()/observe() but ir can just deal w/ the 1 time the button shows ,following shows can not be deal ,below is my test code ,
what i think is that it can deal each time when button shows until the script end.

below is my test code :
 def myHandler(event):
    click("1373853815762.png")
    wait(5)
Settings.ObserveScanRate=1
onAppear(("1373853815762.png"),myHandler)
observe(FOREVER,background = True)
for i in range(1,5000):
    print "testing....."
    wait(5)

Tags: fkt-observe
RaiMan (raimund-hocke)
Changed in sikuli:
status: New → Fix Committed
importance: Undecided → High
assignee: nobody → RaiMan (raimund-hocke)
milestone: none → 1.1.0
RaiMan (raimund-hocke)
description: updated
summary: - OnAppear()/observe() only works the first time for one image in same
- region
+ [1.0] OnAppear()/observe() only works the first time for one image in
+ same region
RaiMan (raimund-hocke)
Changed in sikuli:
importance: High → Critical
description: updated
RaiMan (raimund-hocke)
tags: added: fkt-observe
RaiMan (raimund-hocke)
summary: - [1.0] OnAppear()/observe() only works the first time for one image in
- same region
+ [1.0.1 ok] OnAppear()/observe() only works the first time for one image
+ in same region
Revision history for this message
Greg (greg-boz) wrote : Re: [1.0.1 ok] OnAppear()/observe() only works the first time for one image in same region

This bug is still present in 1.1.0

RaiMan (raimund-hocke)
description: updated
summary: - [1.0.1 ok] OnAppear()/observe() only works the first time for one image
- in same region
+ [1.0.1] OnAppear()/observe() only works the first time for one image in
+ same region
Revision history for this message
RaiMan (raimund-hocke) wrote :

@Greg
I still have to revise the docs.

for you:
onAppear/onVanish detection is stopped after the first event in one observe run.
If you want to continue the observation, you have to say repeat() in the handler.

There are 2 options:
repeat() # immediately after return from handler continue detection of this event

or

repeat(time) # after return from handler pause for time seconds and then continue detection

Revision history for this message
Greg (greg-boz) wrote :

@RaiMan

Thank you for responding.

When I use onAppear(image, handler) the handler is then called and operates. The last line inside the handler is repeat(), but this does not remedy the problem as expected.

I have a while loop operating, but observe() and onAppear(), including the handlers I use within onAppear() are all defined and activated above the loop.

Therefore, there is no logical continuity within which I can place repeat() 'after return from handler', I can only place it within the handler code because the last line as onAppear() is not inside the loop.

Am I misunderstanding your advice?

Revision history for this message
Greg (greg-boz) wrote :

Something like this:

def found(event) :
    print "found it";repeat()
onAppear("1433207314491.png", found)
observe(background=True)
while True :
# sequential logic here

Revision history for this message
RaiMan (raimund-hocke) wrote :

ok, my suggestion was a bit careless, sorry.

repeat is an event function and hence has to be used in the handler.

def found(event) :
    print "found it"
    event.repeat()

onAppear("1433207314491.png", found)
observe(background=True)
while True :
# sequential logic here

So I guess, the observe is for handling some popup or other situation, that comes up asynchronously during your worflow in the loop. So if you are sure the onAppear-target has vanished at the time you issue the repeat(), using this without a wait time is ok.

Revision history for this message
Greg (greg-boz) wrote :

That solved it, thanks so very much!

Revision history for this message
Greg (greg-boz) wrote :

That solved my problem, but created another.

onAppear does not seem to refresh getLastMatch(), and there seems to be no way to pass the image that triggered onAppear to my handler. So the hander is triggered, but has no idea where to click in order to process operations.

Is there a workaround for this?

The documentation talks about explicit operations like find() and implicit operations like click() setting getLastMatch(), but onAppear() does not seem to do this.

I can't imagine this is by design, is this a documented bug, or am I missing a key concept?

Thanks for your help.

Revision history for this message
RaiMan (raimund-hocke) wrote :

the match is accessible as
event.getMatch()

as:
.getRegion() # the searchRegion
.getPattern() # the used Pattern (contains the image used)
.getCount() # how often the handler was visited

Revision history for this message
Greg (greg-boz) wrote :

That works, many thanks!

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.