stop a reg.observeInBackground(FOREVER) whitout event happening

Asked by juan on 2018-01-09

windows 10, windows 7
sikuli 1.1.1 build 2017-03-29_10:41

I have a script

def test(event):
def test1(event):

Settings.reg = Region(0,0,1279,1023)

while True:

I use forever because I do not know when the image will appear.
I have several small regions, and I observe them all at once.
On certain occasions, I need to stop the observation of all regions without the image appearing. I have to do this in mymaincode.
and then go back to observe, again in mymaincode
How can I do that?

Question information

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

In your main code just issue a

for every region you want to stop its observing.

juan (fogelmanjg) said : #2

thanks for response.

I tried with that line before asking ... but it does not stop observing
if I use the line event.stopObserver () inside the def: it works.
if I use the line event.stopObserver () in mymaincode it does not work and it says that event is not defined.
if I use the line Settings.reg.stopObserver () within the def or in mymaincode it does not work. keep observing.

RaiMan (raimund-hocke) said : #3

ok, I will check as soon as possible.

juan (fogelmanjg) said : #4

thanks for your time.
I'm going to try another pc to get rid of the doubt.

RaiMan (raimund-hocke) said : #5

tested with 1.1.2.

this works:

img = "img.png"

def handler(event):

onAppear(img, handler)

while True:
  m =
  if (m.x < 100 and m.y < 100): # condition 1
  if not SCREEN.isObserving(): # condition 2

- when the image gets visible, the script ends due to the stop in the handler and then condition 2

- when the image stays invisible after some time I move the mouse to top left corner of screen, which fires condition 1 and stops the observing and then the script ends due to condition 2

juan (fogelmanjg) said : #6

### example
def test(event):
if SCREEN.isObserving():
    popup("is observing")
    popup("is not observing")
if SCREEN.isObserving():
    popup("is observing")
    popup("is not observing")
while True:

With your example, I have created this other example, which has allowed me to solve my problem.
in my example if the image is on the screen when I run the script, move the mouse over the image and then show the popups, first is observing, second is not observing.
but if the image is not yet on the screen, it shows the popups, first is observing, second is not observing. If you show the image later, do not move the mouse.
in the first case the event is triggered before it can be stopped, when the image is already visible at the moment of starting the script, which is how it works.
I've tried it on my pc at home, which I have version 1.1.2 and it works fine.
in version 1.1.1 that I have at work (without internet to update) it does not work. I have to update it to version 1.1.2

thank you very much for your help.

juan (fogelmanjg) said : #7

Thanks RaiMan, that solved my question.