← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #185349]: Script example of using an observer

 

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

    Status: Open => Answered

RaiMan proposed the following answer:
The code snippet from faq 1770 is exactly, how you can handle these
situations (since it was setup, to show the effect the scan rate, it
contains some extra coding).

--- your situation
supposing for an example
- you have a popup with fixed content (captured image imgPop)
- you know the region on the screen, where it should appear (regPop)
- in the main script, we want to know, that the popup handler is active

# the script template

def handler(e):
     regPop = e.region
     regPop.isHandling = True #starting
     # do something to make the popup vanish
     regPop.isHandling = False #finished

# main workflow
regPop = Region(x,y,w,h) # evaluated somehow
imgPop = "captured-image-of-popup.png"

regPop.isHandling = False # initialize to False

regPop.appear(imgPop, handler)
regPop.observe(FOREVER, background=True) # starts observing

# main workflow continues
click(something)
wait(something_else)
while regPop.isHandling: wait(1) # pause while popup handler is active
# more main workflow

Be aware: the mouse handling is exclusive inside the handler, while it is active. So try to make the handler as short and fast as possible, to reduce interferences with your main script to a minimum.
Very critical parts of your main workflow might be scripted using the above regPop.isHandling, so they only run, while the handler is not active.

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