Sometimes you want to execute some code at a specified time or after a specified time period. EventGhost includes a small scheduler, that helps you to accomplish this.
EventGhost creates a single instance of this class that is accessible as eg.scheduler.
This function will call the callable func after waitTime seconds (expressed as a floating point number) with optional parameters, by adding it to the scheduler’s queue. A little example:
def MyTestFunc(myArgument): print "MyTestFunc was called with:", repr(myArgument) eg.scheduler.AddTask(10.0, MyTestFunc, "just some test data")
Ten seconds after invocation of the code it will print the following message to the log:
MyTestFunc was called with: 'just some test data'
The function will return an object, that you can use as the task identifier for CancelTask().
An object to identify the task.
This does the same as AddTask(), but the startTime parameter specifies an absolute time expressed in floating point seconds since the epoch. Take a look at the documentation of Python’s time module, for more information about this time format. Again a little example:
import time startTime = time.mktime((2007, 8, 15, 16, 53, 0, 0, 0, -1)) eg.scheduler.AddTaskAbsolute(startTime, eg.TriggerEvent, "MyEvent")
This will trigger the event “Main.MyEvent” at 16:53:00 on 15 August 2007. If you run this code after this point of time, the eg.TriggerEvent() will be called immediately.