[error] NameError (name 'onEvent' is not defined)

Asked by Ray Bobak

from the documentation ....

Note on performance: Normally all the region methods are used as reg.onAppear(PS), where reg is a region object. If written as onAppear(PS) it operates on the default screen being the implicit region in this case. Using region.onEvent() instead will restrict the search to the region’s rectangle and speed up processing, if region is significantly smaller than the whole screen.

since I am running a 5760x1080 'screen' I thought it wise to not use the entire for an OnAppear() observer. When I try onEvent I get a name not defined. How can I limit rectangle of interest on a onAppear or similar function?

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
Carl (n223mm) said :
#1

I am pretty new at this so this may be a bit of a kludge, but maybe something like this:
    #Set screen regions to improve search speed somewhat. Divide into halfs and quarters.
    #TopHalf, LowerHalf, LeftHalf, RightHalf, TLQuarter, TRQuarter, BLQuarter, BRQuarter

    x = getX()
    y = getY()
    w = getW()
    h = getH()

    rTopHalf = Region(x,y,w,h/2)
    rTopHalf.highlight(1)
    rLowerHalf = Region(x,h/2,w,h/2)
    rLowerHalf.highlight(1)
    rLeftHalf = Region(x,y,w/2,h)
    rLeftHalf.highlight(1)
    rRightHalf = Region(w/2,y,w,h)
    rRightHalf.highlight(1)
    rTLQtr = Region(x,y,w/2,h/2)
    rTLQtr.highlight(1)
    rTRQtr = Region(w/2,y,w/2,h/2)
    rTRQtr.highlight(1)
    rBLQtr = Region(x,h/2,w/2,h/2)
    rBLQtr.highlight(1)
    rBRQtr = Region(w/2,h/2,w/2,h/2)
    rBRQtr.highlight(1)

    if not rTRQ.exists(yourseach.png):
        popup("Something not found")
        doAction
    else:
        popup("Something Found")
        doOtherAction

Revision history for this message
Ray Bobak (ray-bobak) said :
#2

Could have sworn I replied to this yesterday, but is not in here.

Yes, I know I can actually carve up the screen or even define a region that contains my target. What I wanted was the ability to get an observer running that could run in the background and check for my particular target, then call an event routine to process the event.

The onAppear() scans the entire screen, given the size of my real estate, it would consume a lot of processor scanning the screen when I already know where it will appear. The documentation talks about the onEvent restricting to a regions rectangle which would be perfect if it worked.

I suppose the alternative is to fire off threads to do the processing then try to figure out how to shut everything down at once without having to kill the IDE everytime.

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

onEvent is just a placeholder for the on... functions.
Use someRegion.onAppear()

Can you help with this problem?

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

To post a message you must log in.