Lets say I have a main script. Can I call functions in other scripts (to avoid having a huge main script...)?
Walter
def TestFunc():
print "Hello world!"
eg.globals.TestFunc = TestFunc
eg.globals.TestFunc()
ind = 1
while ind < 5:
SunUpDown() #(my main function)
remain = int(time.strftime("%S", time.localtime()))
time.sleep(60-remain)
An additional thread would to. You could also trigger an event aftter x seconds with thr TriggerEvent action class, or use the newly introduced scheduler.krambriw wrote:But is there a way to avoid that the whole eg also sleeps during the sleep period?
Thread???
import time
try:
i
except NameError:
i = 0
def MyFunc():
if i == 0:
print "ok to print"
def MyTestFunc(myArgument):
print "MyTestFunc was called with:", repr(myArgument)
eg.TriggerEvent("egEvent_OFF")
ind = 1
while ind < 3:
MyFunc()
i = 1
print ind
eg.plugins.System.MuteOn()
# eg.plugins.TellStick.TurnOn(2)
eg.TriggerEvent("egEvent_ON")
eg.scheduler.AddTask(5.0, MyTestFunc, "Setting device off")
remain = int(time.strftime("%S", time.localtime()))
print 60-remain
time.sleep(60-remain)
eg.plugins.System.MuteOff()
ind += 1
time.sleep(5)
eg.StopMacro()
//-----------------------------------------------------------------------
//
//-----------------------------------------------------------------------
void myApp::Delay(int ms)
{
bDelay = true;
parent->SetTimer(TIMER_DELAY, ms, 0);
while (bDelay){
Sleep(10);
SafeYield();
}
}
//-----------------------------------------------------------------------
//
//-----------------------------------------------------------------------
void myApp::SafeYield()
{
tagMSG Msg;
while (PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE)){
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
}
//-----------------------------------------------------------------------
//
//-----------------------------------------------------------------------
void myApp::OnTimer(UINT nIDEvent)
{
switch(nIDEvent)
{
case TIMER_DELAY: //Delay timer
KillTimer(nIDEvent);
if(workObj)
workObj->bDelay = false;
break;
.
.
.
.
def MySunsetFunc():
if EverythingIsAlright():
eg.TriggerEvent("SunsetLightOn")
nextTime = CalculateNextSunsetFromNow()
eg.scheduler.AddTaskAbsolute(nextTime, MySunsetFunc)
nextTime = CalculateNextSunsetFromNow()
eg.scheduler.AddTaskAbsolute(nextTime, MySunsetFunc)
Users browsing this forum: No registered users and 2 guests