Observing multiple images with priority

Asked by Lee Yen Liang on 2018-02-23

I've defined a sikuli module which is used to click on an image when something appears inside a region.

    # observer.py

    from sikuli import *

    class Observer:

        # When "observedImage" appears inside "region", double click on "reactImage"
        def __init__(self, region, observedImage, reactImage):
            self.region = region
            self.observedImage = observedImage
            self.reactImage = reactImage

        def start(self):
            self.region.onAppear(self.observedImage, self.appearHandler)
            self.region.observe(FOREVER, background = True)

        def appearHandler(self, event):

        def stop(self):

Here's how to use it:

    import observer
    import time

    observer.Observer(Region(111,222,333,444), "imageToBeDetected1.png", "imageToBeClicked1.png").start()
    observer.Observer(Region(555,666,66,666), "imageToBeDetected2.png", "imageToBeClicked2.png").start()

    while True:

The problem with the above code is that when `imageToBeDetected1` and `imageToBeDetected2` both appear in `Region(111,222,333,444)` and `Region(555,666,66,666)` respectively, my mouse will move between `imageToBeClicked1` and `imageToBeClicked2`. I want only `imageToBeDetected1` to be clicked in this situation.

`imageToBeDetected2` should be ignored when `imageToBeDetected1` and `imageToBeDetected2` both appear in `Region(111,222,333,444)` and `Region(555,666,66,666)`, respectively.

How can I modify my code so that `imageToBeDetected1` has a higher priority over `imageToBeDetected2`?

Or is there a better way to observe multiple images with sikuli?

Question information

English Edit question
Sikuli Edit question
No assignee Edit question
Last query:
Last reply:
RaiMan (raimund-hocke) said : #1

This is only manageable, if you use ONE handler function, where both situations are checked and handled accordingly.
It might be necessary, to check the existence of the other image in the handler, to decide.

Additionally you need some global state, that remembers what has been done so far, to decide what has to be done now.

This all only makes sense, if the situations come up asynchronously in parallel to some main workflow.
If this is not the case, it is easier to use if exists().

Can you help with this problem?

Provide an answer of your own, or ask Lee Yen Liang for more information if necessary.

To post a message you must log in.