How to scan all screens every time

Asked by Boomy Grunt

I'm using a script in various different systems. The monitor setup ranges from 1 to 4. (OS is always Windows 7)

Using the IDE, the pattern preview for an image always scans all visible parts. How am I able to use this behaviour in my own script?

The elements I'm looking for could appear on any screen and might span across multiple screens.

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
Best RaiMan (raimund-hocke) said :
#1

Will be available with next version.

Meanwhile you might use your own functions:

# a function aquivalent to exists()
def myExists(pat, wtime = getNumberScreens()):
    wtime = getNumberScreens() if wtime == 0 else wtime
    start = time.time()
    screens = [Screen(i) for i in range(getNumberScreens())]
    while wtime > time.time()-start:
        for screen in screens:
            if screen.exists(pat, 0):
                return screen.getLastMatch()
    return None

# a function aquivalent to find/wait
def myFind(pat, wtime = getNumberScreens()):
    wtime = getNumberScreens() if wtime == 0 else wtime
    start = time.time()
    screens = [Screen(i) for i in range(getNumberScreens())]
    while wtime > time.time()-start:
        for screen in screens:
            if screen.exists(pat, 0):
                return screen.getLastMatch()
    raise FindFailed("not found on any screen: " + str(pat))

# usages with click
click(myExists(some_pattern_or_image)) # will simply do nothing on not found
click(myFind(some_pattern_or_image)) # will raise FindFaild exception on not found

# as usual you might save the match
m = myExists(some_pattern_or_image)
if m:
    print "found"
else:
    print "not found"

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

BTW: spanning of an element over multiple screens will not be supported in the first run definitely, since currently a Region must always be inside the borders of a physical screen.

Revision history for this message
Boomy Grunt (noneathome) said :
#3

Thanks RaiMan, that solved my question.