Checking for sequntial visual events using Observe

Asked by Sanjay

Hello,

I need to check for change in the visual events in a particular region of the window ,for eg : sending message icon ,Send succesful icon or unsuccesful send icon . What is the best way to handle this scenario ? Right now i am creating Sikuli events with in the region for each of these events and waiting for them sequentially , I am using global flags(setting them in the corresponding events) to move to the next sequence Eg:
 #Check for Sending
 onAppear(target,_checkForStatusChange_sending)
 observe(10,background=False)

.......
#Check for Sent
 onAppear(target,_checkForStatusChange_sent)
 observe(60,background=False)

#check for unsent
#Check for Sent
 onAppear(target,_checkForStatusChange_unsent)
 observe(10,background=False)

The sequence is failing at the second onAppear , the sikuli is not waiting for 60 secs at all .
Is there is something wrong in the way i am using them ?

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
j (j-the-k) said :
#1

Can you post your "_checkForStatusChange_sending" method?

You register the second onAppear listener to the same region as the first, so your first onAppear handler is still active if you run the observe() for the second time and may get triggered.

Revision history for this message
Sanjay (otlasanju) said :
#2

Hi j(j-the-k),
Thanks for taking your time to help me with my problem.
I have modified the code as below, now i have only one observe running ,but the handlers are not able to handle all the events, I am missing some events on a regular basis, so i have totally discarded the events and just waiting for the images to appear in a while loop ,which seems to do the job pretty good so far

with searchRegion:
            onAppear(Pattern("UnsuccesfullSend.png").similar(0.9),_checkForStatusChange_unsent)
            onAppear(Pattern("SuccesfuSent.png").similar(0.9),_checkForStatusChange_Sent)
           #onAppear(Pattern("SendingMessage.png").similar(0.9),_checkForStatusChange_sending)
            onAppear(Pattern("MacroError.PNG").similar(0.9),_checkForUnknownErrors)
          #onChange(75,_onChange)
           observe(FOREVER,background=False)

And my handler are like this

def _checkForStatusChange_sending(event):
    #print "Yes Found it"
    print "in _checkForStatusChange_sending"
    tblog.infoLog( "in _checkForStatusChange_sending")
    print event.pattern
    event.region.highlight(1)
    if event.pattern == "SendingMessage.png":
        print "SENDING_FLAG = True"
        global SENDING_FLAG
        SENDING_FLAG = True
        #print SENDING_FLAG
        #event.region.stopObserver() # stops the observation
def _checkForStatusChange_Sent(event):

    #event.region.highlight(1)
    print event.pattern
    match = event.match
    print match
    cp = match.getTopLeft().offset(10,10) # select a pixel, that has the background color
    .......................................
    Some Logging stuff
    .......................................
    event.region.stopObserver() # stops the observation

def _checkForStatusChange_unsent(event):

    #print event.pattern
    #event.region.highlight(1)
    match = event.match
    print match
    cp = match.getTopLeft().offset(10,10) # select a pixel, that has the background color
    ......................................
    SOME LOGGING
    ......................................
    event.region.stopObserver() # stops the observation

def _checkForUnknownErrors(event):
    #if exists(event.pattern):
    print "in _checkForUnknownErrors"
    #print event.pattern
    tblog.errorLog("Unknown Error")
    global UNKNOWN_ERROR
    UNKNOWN_ERROR = True
    event.region.stopObserver() # stops the observation

# print event.match

Revision history for this message
RaiMan (raimund-hocke) said :
#3

to leave it open

Can you help with this problem?

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

To post a message you must log in.