Pass value from handler (on appear) to main script

Asked by spyros-liakos

Hello and really thanks for support.!!

Im trying to get the value from the handler to my main script. So when an observe is happen i can send my script flow to any direction....

The philosophy is to catch errors while the script is running and if so to call specific functions.

*Im not a great programmer thats why i'v been stuck.. and need help please... :)

My code:

#functions popup
def p1():
    popup("hi1")

def p2():
    popup("h2")

def p3():
    popup("h3")

def p4():
    popup("h4")

def p5():
    popup("h5")

#check if handler is activated
if myvar == 22:
    p5()
else:
    p1()

#handel for onappear
def handler():
    myvar = 11

#onappear method

onAppear("CalcImage.png", handler)
observe(FOREVER)
while True:
    observe()

The error ofcource: [error] NameError ( name 'myvar' is not defined )
*Working on Sikuli 1.1.0

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
spyros-liakos
Solved:
Last query:
Last reply:
Revision history for this message
masuo (masuo-ohara) said :
#1

Please explain what you want to do.
You can use try-except if you want to catch errors while the script is running.

if you want to debug your codes, the following codes work without error.
myvar = 0
if myvar == 22:
    p5()
else:
    p1()

Revision history for this message
spyros-liakos (spy-arts) said :
#2

Thanks for replying..!

I want to observe always for an error popup in the program i use. The error is a internet connection error. If this happen i know how to wait and solve it. But then i want the script to start from the begin..

For example i got this:

def start():
    click("start.png")

def play():
    click("play.png")

def finish():
    click("close.png")

#begin the script

for x in range(100)
    if error = True:
            finish()

   start()

    if error = True:
            finish()

    play()

    if error = True:
            finish()

    finish()

#the observe always

def handler():
    error = True
    #some function to solve the error

onAppear("error.png", handler)
observe(FOREVER)
while True:
    observe()

My think is to have an "if" before every function and if value "error = True" will pass all functions and start from the begin of the loop.

Revision history for this message
masuo (masuo-ohara) said :
#3

My sample codes may help you.

def handler(event):
    global count
    event.stopObserver()
    count = count + 1
    msg = "count=%d" % count
    popup(msg)
    observe(FOREVER, background = True)

onAppear("image.png",handler)
observe(FOREVER, background = True)
count = 0
while count < 10:
   popup("Dummy popup")
stopObserver()

Revision history for this message
spyros-liakos (spy-arts) said :
#4

Im done!! Thank you!!!