← Back to team overview

sikuli-driver team mailing list archive

[Question #266820]: onVanish not working on specific region

 

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

I am relatively new to Sikuli and python.I am running Sikuli on a MAC 10.9.5.
I am having trouble getting onVanish to work. I have extracted the relevant code to highlight the problem. The code is monitoring a game. As part of the game there is an image that moves periodically from one position to another. First consider the following 



def imageMoved(event):
	self.monitor = False
	event.region.stopObserver()


self.monitor = True
image = Image()
currentImageRegion = image.region()   # currentImageRegion redundant in this first version
if currentImageRegion.exists(imageScreenShot):

	onVanish(imageScreenShot, imageMoved) # THE CHANGED LINE

        observe(background = True)
        while self.monitor == True:
        	currentImageRegion.highlight(1)
		# monitoring stuff

Here currentImageRegion is redundant. Here I assume "onVanish(imageScreenShot, imageMoved)" is applied to the whole screen as the region. While running the game, as the image moves, onVanish is not triggered which I sort of would have expected.If I then minimise the game onVanish is triggered which I also would expect.

Now for the problem:- 


def imageMoved(event):
	self.monitor = False
	event.region.stopObserver()


self.monitor = True
image = Image()
currentImageRegion = image.region()
if currentImageRegion.exists(imageScreenShot):

	currentImageRegion.onVanish(imageScreenShot, imageMoved) # THE CHANGED LINE

        observe(background = True)
        while self.monitor == True:
        	currentImageRegion.highlight(1)
		# monitoring stuff


In this piece of code onVanish is applied to the region currentImageRegion. This is a small region around the initial position of the image. I know that it is as I can see it due to the "currentImageRegion.highlight(1)" statement. However, when the image moves out of this region the onVanish is not triggered (this is what I want). Further, if I minimise the game the onVanish is still not triggered. 

In conclusion it seems that onVanish is only working when applied to the whole screen and not a more specific region of the screen. Am I doing something wrong? Thanks in anticipation of any help.

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.