← Back to team overview

sikuli-driver team mailing list archive

[Question #664865]: Observing multiple images with priority

 

New question #664865 on Sikuli:
https://answers.launchpad.net/sikuli/+question/664865

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):
            doubleClick(self.reactImage)
            event.repeat()
    
        def stop(self):
            self.region.stopObserver()

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:
      print('waiting')
      time.sleep(1)
      
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?

-- 
You received this question notification because your team Sikuli Drivers
is an answer contact for Sikuli.