← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #261426]: Region.observe(60, True) is throwing an exception

 

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

Pierre Best posted a new comment:
import org.sikuli.basics.SikulixForJython
from sikuli import *


Settings.OcrTextSearch = True
Settings.OcrTextRead = True


_changes = []

def change_handler(event):
    global _changes

    for ec in event.changes:
        _changes.append(Region(ec))
    _changes.append(None)
    event.region.stopObserver()

def detect_menu_appear():
    _APP = 'notepad.exe'
    _TITLE = 'Notepad'
    _MENU_TITLE = 'Edit'


    try:
        np = App(_APP)

        np.open()

        for _ in range(10):
            mw = np.window(0)
            if mw:
                break
            time.sleep(0.1)
        if not mw:
            exit()

        title = None
        try:
            title = mw.find(_TITLE)
        except Sikuli.FindFailed:
            exit()
        if title is None:
            exit()
        if title.click(title) != 1:
            exit()

        edit_menu = None
        try:
            edit_menu = mw.find(_MENU_TITLE)
        except Sikuli.FindFailed:
            exit()
        if edit_menu is None:
            exit()

        menu_region = edit_menu.left(1).below().right().intersection(mw)
        menu_region.onChange(100, change_handler)

        global _changes
        _changes = []
        menu_region.observe(60, True)

        if edit_menu.click(edit_menu) != 1:
            exit()

        for _ in range(20):  # wait for the handler to terminate
            if len(_changes) == 0:
                time.sleep(1)
                continue


        for r in _changes[:-1]:
            sys.__stdout__.write('<%s>' % r)

    except:
        sei0, sei1 = sys.exc_info()[:2]
        sys.__stdout__.write('except->[<%s>, <%s>]\n' % (sei0, sei1))
        pass
    finally:
        np.close()


detect_menu_appear()

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