← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #211455]: Creating time markers in sikuli

 

Question #211455 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/211455

    Status: Open => Answered

RaiMan proposed the following answer:
start = time.time()
is not a timer.

it just stores the time at the moment this statement is processed into the value start.
So later on all around the place, where you have access to the variable start, you can check the time, that elapsed since start:
elapsed = time.time() - start

So without stepping into subprocessing or even event processing, you
need a function that starts a new timer and can be asked, wether a given
time has elapsed and a global storage for the timer values.

basic timer function:

def timer(name, elapse=0):
    if elapse > 0: # we start a timer
        exec("Settings.myTimer" + str(name) + "=time.time()+" + str(elapse)
    else # we check the timer
        rest = eval("Settings.myTimer" + str(name)) - time.time()
        if rest > 0: return False # not yet elapsed
        else return True

usage:
timer(1, 100) will start now and elapse in 100 seconds
# ... some code
if timer(1): print "timer1: time is over"

As global storage for the timer values I use the Sikuli Settings class.

Since the timer not really does anything, it is just storing a value for
later comparison, you do not need a "reset".

just repeating the above sequence would give a new value to
Settings.myTimer1

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