← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #183688]: How to restrict regions for the use of Region.text

 

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

    Status: Open => Answered

RaiMan proposed the following answer:
What you can try, is to use the onChange() action of Sikuli's observe
feature.

see docs: http://sikuli.org/docx/region.html#observing-visual-events-
in-a-region

example:

def handler(event):
    print "In Change Handler"
    for m in event.changes:
        event.region.changes.append(Region(m))
    event.region.changes.append(None)        
    event.region.stopObserver()
    
switchApp("Safari")
m = find("Newinversion.png") # to get a click point

r = m.left(1).right(500).above(1).below(500) # observed region
r.highlight(2) # within menu is expected

r.onChange(handler)
r.changes = [] 
r.observe(FOREVER, True) # background observation

rightClick(m) # main script continues

for i in range(20): # wait for the handler to terminate
    if len(r.changes) == 0: wait(1); continue
    if r.changes[-1]: wait(1); continue
if len(r.changes) < 2: 
    print "Sthg. went wrong"
    exit(1)

for reg in r.changes[:-1]: # check the result
    reg.highlight(2)

the idea: you know the region where the menu should popup inside. This
popping up menu changes the regions content. This is observed and as a
result you get the part of the region, that has changed - which should
be your popup menu.

It looks a bit complicated, but works. Since we want to know the changed region in our main script, we have to implement a storage to communicate this from the handler to the main script (r.changes  as a list/array).
After the rightClick() we have to wait for the handler to terminate, which is done by checking the content of r.changes during max 20 seconds.

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