Re: [Sikuli-driver] [Question #664865]: Observing multiple images with priority

2018-02-23 Thread RaiMan
Question #664865 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/664865

Status: Open => Answered

RaiMan proposed the following answer:
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().

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

___
Mailing list: https://launchpad.net/~sikuli-driver
Post to : sikuli-driver@lists.launchpad.net
Unsubscribe : https://launchpad.net/~sikuli-driver
More help   : https://help.launchpad.net/ListHelp


[Sikuli-driver] [Question #664865]: Observing multiple images with priority

2018-02-23 Thread Lee Yen Liang
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.

___
Mailing list: https://launchpad.net/~sikuli-driver
Post to : sikuli-driver@lists.launchpad.net
Unsubscribe : https://launchpad.net/~sikuli-driver
More help   : https://help.launchpad.net/ListHelp