← Back to team overview

sikuli-driver team mailing list archive

[Question #676658]: how does observeEvent work exactly ?

 

New question #676658 on Sikuli:
https://answers.launchpad.net/sikuli/+question/676658

So ive been reading the sikuliX api on observing events and Im not able to understand certain events that happen when i try coding it out myself.

I wrote this function that clicks a region, and after the click will observe that region for any change in pixels.


def observe_and_click(phone_region, pixel_region, handler, observe_time): 
    pixel_region.click() # make pixel click on region 
    phone_region.onChange(50,handler)    # observe for changes in region 
    phone_region.observe(observe_time)   # how long to observe for 

this is the handler function for the above. 

def handler(event):
    global i
    r = event.getRegion() # get the observing region for this event
    path = capture(r,"/Users/ongyichong/SikuliX/Scripts",str(i))
    i += 1
    print(path)
    r.stopObserver()

So every click of an event would trigger the handler function once since at the end of the handler function i make the observation stop. However my message log prints something like this:
[log] CLICK on L(55,109)@S(0)[0,0 1440x900] (109 msec)
/Users/ongyichong/SikuliX/Scripts/0.png
/Users/ongyichong/SikuliX/Scripts/1.png

/Users/ongyichong/SikuliX/Scripts/2.png

[log] CLICK on L(75,109)@S(0)[0,0 1440x900] (101 msec)
/Users/ongyichong/SikuliX/Scripts/3.png
/Users/ongyichong/SikuliX/Scripts/4.png
/Users/ongyichong/SikuliX/Scripts/5.png

/Users/ongyichong/SikuliX/Scripts/6.png

where i get like 3 - 4 print statements for every click i make ? shouldnt Stopobserver() cause the handler to be called once per observe_and_click function call ?  I have already tried reading the documentation but i cant seem to find any information that could explain this phenomenon. 

-- 
You received this question notification because your team Sikuli Drivers
is an answer contact for Sikuli.