home *** CD-ROM | disk | FTP | other *** search
/ PC PowerPlay 56 / CDPowerplay56Disc2.iso / demos / blade / data1.cab / Program_Executable_Files / Lib / timerAux.py < prev    next >
Encoding:
Text File  |  2000-10-27  |  1.7 KB  |  56 lines

  1. ##########################################################
  2. #
  3. #    SCRIPT    : simplificacion de los timers
  4. #
  5. #    AUTH    : Yuio
  6. #
  7. #
  8. ##########################################################
  9.  
  10. import Bladex
  11.  
  12. TimerDictionary={} # dictionary of functions
  13.  
  14. def unhandledTimer( entName, startTime, totalTime, val, data ) :
  15.     print "unhandledTimer(",entName,",",startTime,",",totalTime,",",val,",",data,")"
  16.  
  17. def unhandledTimerEnd( entName ) :
  18.     print "unhandledTimerEnd(",entName,")"
  19.  
  20. def lock( entName, data, totalTime, handler=0, endhandler=0 ):
  21.     if (not handler) : handler = unhandledTimer
  22.     if (not endhandler) : endhandler = unhandledTimerEnd
  23.     TimerDictionary[entName]= Bladex.GetTime(), totalTime, entName, data, handler, endhandler
  24.  
  25. def unlock(entName):
  26.     del TimerDictionary[entName]
  27.  
  28. Bladex.CreateTimer("TimerAuxT",0.20)
  29. def run(entName):
  30.     ent = Bladex.GetEntity(entName)
  31.     TimerDictionary[entName] = Bladex.GetTime(), TimerDictionary[entName][1], TimerDictionary[entName][2], TimerDictionary[entName][3], TimerDictionary[entName][4], TimerDictionary[entName][5]
  32.     ent.SubscribeToList("TimerAuxT")
  33.     ent.TimerFunc = timerAuxHandler
  34.  
  35. def manualTermination(entName):
  36.     ent = Bladex.GetEntity(entName)
  37.     ent.RemoveFromList("TimerAuxT")
  38.     ent.TimerFunc = ""
  39.  
  40.     endhandler    = TimerDictionary[entName][5]
  41.     endhandler(entName)
  42.  
  43. def timerAuxHandler(ent, time):
  44.     end            = 0
  45.     time        = Bladex.GetTime()
  46.     startTime    = TimerDictionary[ent][0]
  47.     totalTime    = TimerDictionary[ent][1]
  48.     if (time>(startTime+totalTime)) :
  49.         time=startTime+totalTime
  50.         end = 1
  51.     handler        = TimerDictionary[ent][4]
  52.     val            = (time-startTime)/totalTime
  53.     handler( TimerDictionary[ent][2], startTime , totalTime, val, TimerDictionary[ent][3] )
  54.     if (end) : manualTermination(ent)
  55.  
  56.