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

From Reallusion Wiki!
Jump to: navigation, search
m (Description)
m
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{TOC}}
 
{{Parent|IC_Python_API:RL_Python_Modules|Modules}}
 
{{last_modified}}
 
 
 
{{TOC}}
 
{{TOC}}
 
{{Parent|IC_Python_API:RL_Python_Modules|Modules}}
 
{{Parent|IC_Python_API:RL_Python_Modules|Modules}}
Line 11: Line 7:
 
This class is used to setup a timed event.  Use [[#SetInterval ( self, nMSec )|SetInterval]] and [[#GetInterval ( self )|GetInterval]] to access and set the time interval.  Use [[#SetSingleShot ( self, bSingleShot )|SetSingleShot]] and [[#IsSingleShot ( self )|IsSingleShot]] to access and set the trigger state (single shot or repeatly trigger).  Use [[#RPyTimer.Start ( self )|Start]], [[#Stop ( self )|Stop]], and [[#IsRunning ( self )|IsRunning]] to control the execution of the Timer.
 
This class is used to setup a timed event.  Use [[#SetInterval ( self, nMSec )|SetInterval]] and [[#GetInterval ( self )|GetInterval]] to access and set the time interval.  Use [[#SetSingleShot ( self, bSingleShot )|SetSingleShot]] and [[#IsSingleShot ( self )|IsSingleShot]] to access and set the trigger state (single shot or repeatly trigger).  Use [[#RPyTimer.Start ( self )|Start]], [[#Stop ( self )|Stop]], and [[#IsRunning ( self )|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'''.
+
In order to receive trigger events, first create a new class and inherit from [[IC_Python_API:RLPy_RPyTimerCallback|RPyTimerCallback]] and register with [[#RegisterPyTimerCallback ( self, pCallback )|RegisterPyTimerCallback]]. When not in use, you can unregister the timer event with [[#UnregisterPyTimerCallback ( self, pCallback )|UnRegisterPyTimerCallback]].
  
See Also: [[IC_Python_API:RLPy_RPyTimerCallback|RPyTimerCallback]]
+
See Also: [[IC_Python_API:RLPy_RPyTimerCallback|RPyTimerCallback]].
  
<syntaxhighlight lang="python">
+
<syntaxhighlight lang="python" line='line'>
 
class MyPyTimerCallback(RLPy.RPyTimerCallback):
 
class MyPyTimerCallback(RLPy.RPyTimerCallback):
 
   def __init__(self):
 
   def __init__(self):
Line 21: Line 17:
 
   def Timeout(self):
 
   def Timeout(self):
 
       print ("timeout")
 
       print ("timeout")
Using Try catch??
+
 
# set timer
+
# Set Timer
 
timer = RLPy.RPyTimer()
 
timer = RLPy.RPyTimer()
 
timer.SetInterval(100)
 
timer.SetInterval(100)
 
timer.SetSingleShot(True)
 
timer.SetSingleShot(True)
 
print(timer.GetInterval())  # 100
 
print(timer.GetInterval())  # 100
# register callback
+
# Register the callback
timer_callback = MyPyTimerCallback() timer_callback crash issue??
+
timer_callback = MyPyTimerCallback()
 
timer.RegisterPyTimerCallback(timer_callback)
 
timer.RegisterPyTimerCallback(timer_callback)
# start timer
+
# Start the Timer
 
timer.Start()
 
timer.Start()
...
+
# Unregister the callback
# unregister callback
+
 
timer.UnregisterPyTimerCallback()
 
timer.UnregisterPyTimerCallback()
 
</syntaxhighlight>
 
</syntaxhighlight>
Line 41: Line 36:
 
=== GetInterval ( self ) ===
 
=== 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()'''.
+
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 ( self )|Start]].
 
+
See Also: [[#SetInterval ( self, nMSec )|SetInterval]]
+
 
+
==== Returns ====
+
:Timer interval ( milisecond ) - int
+
 
+
<syntaxhighlight lang="python">
+
timer = RLPy.RPyTimer()
+
timer.SetInterval(1000)
+
print (timer.GetInterval()) # 1000
+
</syntaxhighlight>
+
 
+
=== IsRunning ( self )  ===
+
 
+
Check if the Timer is currently running.
+
 
+
See Also: [[#Start ( self )|Start]], [[#Stop ( self )|Stop]]
+
 
+
==== Returns ====
+
:'''True''' if the timer is currenlty running, else '''False''' - bool
+
 
+
<syntaxhighlight lang="python">
+
timer = RLPy.RPyTimer()
+
timer.Start()
+
print (timer.IsRunning()) # True
+
</syntaxhighlight>
+
 
+
=== IsSingleShot ( self ) ===
+
 
+
Get the Timer trigger settings.  Return '''True''' if the trigger is single-shot and '''False''' for repeat trigger.
+
 
+
See Also: [[#SetSingleShot ( self, bSingleShot )|SetSingleShot]]
+
 
+
==== Returns ====
+
:'''True''' if trigger is single-shot, else '''False''' - bool
+
 
+
<syntaxhighlight lang="python">
+
timer = RLPy.RPyTimer()
+
timer.SetSingleShot(True)
+
print (timer.IsSingleShot()) # True
+
</syntaxhighlight>
+
 
+
=== RegisterPyTimerCallback ( self, pCallback ) ===
+
 
+
Register a Callback object with the Timer.
+
 
+
See Also: [[#UnregisterPyTimerCallback ( self, pCallback )|UnregisterPyTimerCallback]]
+
 
+
==== Parameters ====
+
:pCallback [IN] Callback object inherited from '''RPyTimerCallback''' - RLPy.RPyTimerCallback
+
 
+
<syntaxhighlight lang="python">
+
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)
+
</syntaxhighlight>
+
 
+
=== UnregisterPyTimerCallback ( self, pCallback ) ===
+
 
+
Unregister the Callback object for the Timer.
+
 
+
See Also: [[#RegisterPyTimerCallback ( self, pCallback )|RegisterPyTimerCallback]]
+
 
+
<syntaxhighlight lang="python">
+
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()
+
</syntaxhighlight>
+
 
+
=== 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 ( self )|GetInterval]]
+
 
+
==== Parameters ====
+
:nMSec [IN] Timer interval in milliseconds - int
+
 
+
<syntaxhighlight lang="python">
+
timer = RLPy.RPyTimer()
+
timer.SetInterval(1000)
+
print (timer.GetInterval()) # 1000
+
</syntaxhighlight>
+
 
+
=== 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 ( self )|IsSingleShot]]
+
 
+
==== Parameters ====
+
:bSingleShot [IN] Set to single-shot triggering - bool
+
 
+
<syntaxhighlight lang="python">
+
timer = RLPy.RPyTimer()
+
timer.SetSingleShot(True)
+
print (timer.IsSingleShot()) # True
+
</syntaxhighlight>
+
 
+
=== 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.
+
 
+
<syntaxhighlight lang="python">
+
timer = RLPy.RPyTimer()
+
timer.SetInterval(100)
+
timer.Start()
+
</syntaxhighlight>
+
 
+
=== Stop ( self ) ===
+
 
+
Stop the Timer.
+
 
+
<syntaxhighlight lang="python">
+
timer = RLPy.RPyTimer()
+
timer.SetInterval(100)
+
timer.Start()
+
# do something
+
timer.Stop()
+
</syntaxhighlight>
+
 
+
== 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 ( self, nMSec )|SetInterval]]
 
See Also: [[#SetInterval ( self, nMSec )|SetInterval]]
Line 189: Line 43:
 
:Timer interval ( milisecond ) - int
 
:Timer interval ( milisecond ) - int
  
<syntaxhighlight lang="python">
+
<syntaxhighlight lang="python" line='line'>
 
timer = RLPy.RPyTimer()
 
timer = RLPy.RPyTimer()
 
timer.SetInterval(1000)
 
timer.SetInterval(1000)
Line 204: Line 58:
 
:'''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" line='line'>
 
timer = RLPy.RPyTimer()
 
timer = RLPy.RPyTimer()
 
timer.Start()
 
timer.Start()
Line 219: Line 73:
 
:'''True''' if trigger is single-shot, else '''False''' - bool
 
:'''True''' if trigger is single-shot, else '''False''' - bool
  
<syntaxhighlight lang="python">
+
<syntaxhighlight lang="python" line='line'>
 
timer = RLPy.RPyTimer()
 
timer = RLPy.RPyTimer()
 
timer.SetSingleShot(True)
 
timer.SetSingleShot(True)
Line 232: Line 86:
  
 
==== Parameters ====
 
==== Parameters ====
:pCallback [IN] Callback object inherited from '''RPyTimerCallback''' - RLPy.RPyTimerCallback
+
:'''pCallback''' [IN] Callback object inherited from [[IC_Python_API:RLPy_RPyTimerCallback|RPyTimerCallback]]- [[IC_Python_API:RLPy_RPyTimerCallback|RPyTimerCallback]]
  
<syntaxhighlight lang="python">
+
<syntaxhighlight lang="python" line='line'>
 
class MyPyTimerCallback(RLPy.RPyTimerCallback):
 
class MyPyTimerCallback(RLPy.RPyTimerCallback):
 
   def __init__(self):
 
   def __init__(self):
Line 252: Line 106:
 
See Also: [[#RegisterPyTimerCallback ( self, pCallback )|RegisterPyTimerCallback]]
 
See Also: [[#RegisterPyTimerCallback ( self, pCallback )|RegisterPyTimerCallback]]
  
<syntaxhighlight lang="python">
+
<syntaxhighlight lang="python" line='line'>
 
class MyPyTimerCallback(RLPy.RPyTimerCallback):
 
class MyPyTimerCallback(RLPy.RPyTimerCallback):
 
   def __init__(self):
 
   def __init__(self):
Line 262: Line 116:
 
timer_callback = MyPyTimerCallback()
 
timer_callback = MyPyTimerCallback()
 
timer.RegisterPyTimerCallback(timer_callback)
 
timer.RegisterPyTimerCallback(timer_callback)
...
 
 
# unregister callback
 
# unregister callback
 
timer.UnregisterPyTimerCallback()
 
timer.UnregisterPyTimerCallback()
Line 274: Line 127:
  
 
==== Parameters ====
 
==== Parameters ====
:nMSec [IN] Timer interval in milliseconds - int
+
:'''nMSec''' [IN] Timer interval in milliseconds - int
  
<syntaxhighlight lang="python">
+
<syntaxhighlight lang="python" line='line'>
 
timer = RLPy.RPyTimer()
 
timer = RLPy.RPyTimer()
 
timer.SetInterval(1000)
 
timer.SetInterval(1000)
Line 289: Line 142:
  
 
==== Parameters ====
 
==== Parameters ====
:bSingleShot [IN] Set to single-shot triggering - bool
+
:'''bSingleShot''' [IN] Set to single-shot triggering - bool
  
<syntaxhighlight lang="python">
+
<syntaxhighlight lang="python" line='line'>
 
timer = RLPy.RPyTimer()
 
timer = RLPy.RPyTimer()
 
timer.SetSingleShot(True)
 
timer.SetSingleShot(True)
Line 301: Line 154:
 
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" line='line'>
 
timer = RLPy.RPyTimer()
 
timer = RLPy.RPyTimer()
 
timer.SetInterval(100)
 
timer.SetInterval(100)
Line 311: Line 164:
 
Stop the Timer.
 
Stop the Timer.
  
<syntaxhighlight lang="python">
+
<syntaxhighlight lang="python" line='line'>
 
timer = RLPy.RPyTimer()
 
timer = RLPy.RPyTimer()
 
timer.SetInterval(100)
 
timer.SetInterval(100)

Latest revision as of 00:03, 14 April 2020

Main article: Modules.
Last modified: 04/14/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 RPyTimerCallback and register with RegisterPyTimerCallback. When not in use, you can unregister the timer event with UnRegisterPyTimerCallback.

See Also: RPyTimerCallback.

 1 class MyPyTimerCallback(RLPy.RPyTimerCallback):
 2    def __init__(self):
 3        RLPy.RPyTimerCallback.__init__(self)
 4    def Timeout(self):
 5        print ("timeout")
 6 
 7 # Set Timer
 8 timer = RLPy.RPyTimer()
 9 timer.SetInterval(100)
10 timer.SetSingleShot(True)
11 print(timer.GetInterval())  # 100
12 # Register the callback
13 timer_callback = MyPyTimerCallback()
14 timer.RegisterPyTimerCallback(timer_callback)
15 # Start the Timer
16 timer.Start()
17 # Unregister the callback
18 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
1 timer = RLPy.RPyTimer()
2 timer.SetInterval(1000)
3 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
1 timer = RLPy.RPyTimer()
2 timer.Start()
3 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
1 timer = RLPy.RPyTimer()
2 timer.SetSingleShot(True)
3 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- RPyTimerCallback
1 class MyPyTimerCallback(RLPy.RPyTimerCallback):
2    def __init__(self):
3        RLPy.RPyTimerCallback.__init__(self)
4    def Timeout(self):
5        print ("timeout")
6  
7 timer = RLPy.RPyTimer()
8 timer_callback = MyPyTimerCallback()
9 timer.RegisterPyTimerCallback(timer_callback)

UnregisterPyTimerCallback ( self, pCallback )

Unregister the Callback object for the Timer.

See Also: RegisterPyTimerCallback

 1 class MyPyTimerCallback(RLPy.RPyTimerCallback):
 2    def __init__(self):
 3        RLPy.RPyTimerCallback.__init__(self)
 4    def Timeout(self):
 5        print ("timeout")
 6  
 7 timer = RLPy.RPyTimer()
 8 timer_callback = MyPyTimerCallback()
 9 timer.RegisterPyTimerCallback(timer_callback)
10 # unregister callback
11 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
1 timer = RLPy.RPyTimer()
2 timer.SetInterval(1000)
3 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
1 timer = RLPy.RPyTimer()
2 timer.SetSingleShot(True)
3 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.

1 timer = RLPy.RPyTimer()
2 timer.SetInterval(100)
3 timer.Start()

Stop ( self )

Stop the Timer.

1 timer = RLPy.RPyTimer()
2 timer.SetInterval(100)
3 timer.Start()
4 # do something
5 timer.Stop()