Difference between revisions of "IC Python API:RLPy RPyTimer"

From Reallusion Wiki!
Jump to: navigation, search
m
m
Line 11: Line 11:
 
See Also: [[#IC_Python_API:RLPy_RPyTimerCallback|RPyTimerCallback]]
 
See Also: [[#IC_Python_API:RLPy_RPyTimerCallback|RPyTimerCallback]]
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
class MyPyTimerCallback(RLPy.RPyTimerCallback):
 
class MyPyTimerCallback(RLPy.RPyTimerCallback):
 
   def __init__(self):
 
   def __init__(self):
Line 44: Line 44:
 
:Timer interval ( milisecond ) - int
 
:Timer interval ( milisecond ) - int
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
timer = RLPy.RPyTimer()
 
timer = RLPy.RPyTimer()
 
timer.SetInterval(1000)
 
timer.SetInterval(1000)
Line 59: Line 59:
 
:'''True''' if the timer is currenlty running, else '''False''' - bool
 
:'''True''' if the timer is currenlty running, else '''False''' - bool
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
timer = RLPy.RPyTimer()
 
timer = RLPy.RPyTimer()
 
timer.Start()
 
timer.Start()
Line 69: Line 69:
 
Get the Timer trigger settings.  Return '''True''' if the trigger is single-shot and '''False''' for repeat trigger.
 
Get the Timer trigger settings.  Return '''True''' if the trigger is single-shot and '''False''' for repeat trigger.
  
See Also: [[#SetSingleShot ( self, bSingleShot )|SetSingleShot()]]
+
See Also: [[#SetSingleShot ( self, bSingleShot )|SetSingleShot]]
  
 
==== Returns ====
 
==== Returns ====
 
:'''True''' if trigger is single-shot, else '''False''' - bool
 
:'''True''' if trigger is single-shot, else '''False''' - bool
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
timer = RLPy.RPyTimer()
 
timer = RLPy.RPyTimer()
 
timer.SetSingleShot(True)
 
timer.SetSingleShot(True)
Line 84: Line 84:
 
Register a Callback object with the Timer.
 
Register a Callback object with the Timer.
  
See Also: [[#UnregisterPyTimerCallback ( self, pCallback )|UnregisterPyTimerCallback()]]
+
See Also: [[#UnregisterPyTimerCallback ( self, pCallback )|UnregisterPyTimerCallback]]
  
 
==== Parameters ====
 
==== Parameters ====
 
:pCallback [IN] Callback object inherited from '''RPyTimerCallback''' - RLPy.RPyTimerCallback
 
:pCallback [IN] Callback object inherited from '''RPyTimerCallback''' - RLPy.RPyTimerCallback
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
class MyPyTimerCallback(RLPy.RPyTimerCallback):
 
class MyPyTimerCallback(RLPy.RPyTimerCallback):
 
   def __init__(self):
 
   def __init__(self):
Line 105: Line 105:
 
Unregister the Callback object for the Timer.
 
Unregister the Callback object for the Timer.
  
See Also: [[#RegisterPyTimerCallback ( self, pCallback )|RegisterPyTimerCallback()]]
+
See Also: [[#RegisterPyTimerCallback ( self, pCallback )|RegisterPyTimerCallback]]
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
class MyPyTimerCallback(RLPy.RPyTimerCallback):
 
class MyPyTimerCallback(RLPy.RPyTimerCallback):
 
   def __init__(self):
 
   def __init__(self):
Line 131: Line 131:
 
:nMSec [IN] Timer interval in milliseconds - int
 
:nMSec [IN] Timer interval in milliseconds - int
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
timer = RLPy.RPyTimer()
 
timer = RLPy.RPyTimer()
 
timer.SetInterval(1000)
 
timer.SetInterval(1000)
Line 146: Line 146:
 
:bSingleShot [IN] Set to single-shot triggering - bool
 
:bSingleShot [IN] Set to single-shot triggering - bool
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
timer = RLPy.RPyTimer()
 
timer = RLPy.RPyTimer()
 
timer.SetSingleShot(True)
 
timer.SetSingleShot(True)
Line 156: Line 156:
 
Start or restart the Timer.  If the Timer is already running, then this operation will stop the Timer first then start it again.  If the trigger is set to single-shot then the Timer event will activate one more time.
 
Start or restart the Timer.  If the Timer is already running, then this operation will stop the Timer first then start it again.  If the trigger is set to single-shot then the Timer event will activate one more time.
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
timer = RLPy.RPyTimer()
 
timer = RLPy.RPyTimer()
 
timer.SetInterval(100)
 
timer.SetInterval(100)
Line 166: Line 166:
 
Stop the Timer.
 
Stop the Timer.
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
timer = RLPy.RPyTimer()
 
timer = RLPy.RPyTimer()
 
timer.SetInterval(100)
 
timer.SetInterval(100)

Revision as of 01:31, 31 March 2020

Main article: Modules.
Last modified: 03/31/2020

Description

This class is used to setup a timed event. Use SetInterval and GetInterval to access and set the time interval. Use SetSingleShot and IsSingleShot to access and set the trigger state (single shot or repeatly trigger). Use Start, Stop, and IsRunning to control the execution of the Timer.

In order to receive trigger events, first create a new class and inherit from RLPyTimerCallback and register with RegisterPyTimerCallback. When not in use, you can unregister the timer event with UnRegisterPyTimerCallback.

See Also: RPyTimerCallback

class MyPyTimerCallback(RLPy.RPyTimerCallback):
   def __init__(self):
       RLPy.RPyTimerCallback.__init__(self)
   def Timeout(self):
       print ("timeout")
 Using Try catch??
# set timer
timer = RLPy.RPyTimer()
timer.SetInterval(100)
timer.SetSingleShot(True)
print(timer.GetInterval())  # 100
# register callback
timer_callback = MyPyTimerCallback() timer_callback crash issue??
timer.RegisterPyTimerCallback(timer_callback)
# start timer
timer.Start()
...
# unregister callback
timer.UnregisterPyTimerCallback()

Member Functions

GetInterval ( self )

Get the time interval for the event triggered by the timer in milliseconds. The default interval value is 0, which will cause the timer to start triggering immediately after Start().

See Also: SetInterval

Returns

Timer interval ( milisecond ) - int
timer = RLPy.RPyTimer()
timer.SetInterval(1000)
print (timer.GetInterval())	# 1000

IsRunning ( self )

Check if the Timer is currently running.

See Also: Start, Stop

Returns

True if the timer is currenlty running, else False - bool
timer = RLPy.RPyTimer()
timer.Start()
print (timer.IsRunning())	# True

IsSingleShot ( self )

Get the Timer trigger settings. Return True if the trigger is single-shot and False for repeat trigger.

See Also: SetSingleShot

Returns

True if trigger is single-shot, else False - bool
timer = RLPy.RPyTimer()
timer.SetSingleShot(True)
print (timer.IsSingleShot())	# True

RegisterPyTimerCallback ( self, pCallback )

Register a Callback object with the Timer.

See Also: UnregisterPyTimerCallback

Parameters

pCallback [IN] Callback object inherited from RPyTimerCallback - RLPy.RPyTimerCallback
class MyPyTimerCallback(RLPy.RPyTimerCallback):
   def __init__(self):
       RLPy.RPyTimerCallback.__init__(self)
   def Timeout(self):
       print ("timeout")
 
timer = RLPy.RPyTimer()
timer_callback = MyPyTimerCallback()
timer.RegisterPyTimerCallback(timer_callback)

UnregisterPyTimerCallback ( self, pCallback )

Unregister the Callback object for the Timer.

See Also: RegisterPyTimerCallback

class MyPyTimerCallback(RLPy.RPyTimerCallback):
   def __init__(self):
       RLPy.RPyTimerCallback.__init__(self)
   def Timeout(self):
       print ("timeout")
 
timer = RLPy.RPyTimer()
timer_callback = MyPyTimerCallback()
timer.RegisterPyTimerCallback(timer_callback)
...
# unregister callback
timer.UnregisterPyTimerCallback()

SetInterval ( self, nMSec )

Set the Timer trigger interval in milliseconds. The default interval value is 0, which will cause the timer to start triggering immediately after Start().

See Also: GetInterval

Parameters

nMSec [IN] Timer interval in milliseconds - int
timer = RLPy.RPyTimer()
timer.SetInterval(1000)
print (timer.GetInterval())	# 1000

SetSingleShot ( self, bSingleShot )

Set the Timer trigger state. Single-shot will only fire off the trigger event once, otherwise the event will fire off according to the Timer interval. The default setting is False.

See Also: IsSingleShot

Parameters

bSingleShot [IN] Set to single-shot triggering - bool
timer = RLPy.RPyTimer()
timer.SetSingleShot(True)
print (timer.IsSingleShot())	# True

Start ( self )

Start or restart the Timer. If the Timer is already running, then this operation will stop the Timer first then start it again. If the trigger is set to single-shot then the Timer event will activate one more time.

timer = RLPy.RPyTimer()
timer.SetInterval(100)
timer.Start()

Stop ( self )

Stop the Timer.

timer = RLPy.RPyTimer()
timer.SetInterval(100)
timer.Start()
# do something
timer.Stop()