onAppear with an array of images?

Asked by Ryan

https://pastebin.com/9fFre1Bm
How do I go about doing something like this? It sounded like a fairly simple concept when I started, but it seems like onAppear only works with individual images.

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

Yes, one event for one image (currently ;-)

This is the appropriate solution for version 1.1.0+:

r = Region(Region(2516,495,694,273))
leftSide = [("left1.png"), ("left2.png"), ("left3.png"), ("left4.png"), ("left5.png"), ("left6.png"), ("left7.png"), ("left8.png"), ("left9.png"), ("left10.png"), ("left11.png")]
rightSide = [("right1.png"), ("right2.png"), ("right3.png"), ("right4.png"), ("right5.png"), ("right6.png"), ("right7.png"), ("right8.png"), ("right9.png"), ("right10.png"), ("right11.png"), ("right12.png")]
neitherSide = [("center1.png"), ("center2.png"), ("center3.png"), ("center4.png")]

def moveLeft(event):
    type(Key.LEFT)
    event.repeat(0.2) # continue observation after 0.2 seconds

def moveRight(event):
    type(Key.RIGHT)
    event.repeat(0.2) # continue observation after 0.2 seconds

# register the events with region r
# one event == one image
for ls in leftSide:
  r.onAppear(ls, moveRight)
for rs in rightSide:
  r.onAppear(rs, moveLeft)
nor rs in neitherSide:
  r.onAppear(ns, moveRight)

# run the observation
r.observe(FOREVER)

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

Uuups, crazy copy and paste ;-)

for ls in leftSide:
  r.onAppear(ls, moveLeft)
for rs in rightSide:
  r.onAppear(rs, moveRight)
for ns in neitherSide:
  r.onAppear(ns, moveRight)

Be aware:
Since currently in one observe processing step, all events are checked in sequence, this one step will last about 5 - 10 seconds (about 25 events each about 0.3 seconds).

To make it faster, the most recommended approach is to make the region as small as possible.

Another possibility is to use a different Region object for each of the image groups left, right and neither, since the observe then could be run in background and would be delegated to 3 subprocesses.

rLeft = <someRegion>
for ls in leftSide:
  rLeft.onAppear(ls, moveLeft)
# same for left and neither

# run the observation
rLeft.observeInBackground(FOREVER)
# same for left and neither

# to keep the script alive
wait(FOREVER)

Revision history for this message
Ryan (rk-california) said :
#3

Thanks RaiMan, that solved my question.