Register a python instance method to be called on a Scorpion system event.
Syntax:
RegisterCallback(event,method)
UnregisterCallback(event,method)
The callback handler are named <group>.<name>
-
Actions.AfterInspect
-
System.ToolApply
The parameters are given by the Central definition:
-
AfterInspect()
-
ToolApply(Tool)
Note 1: The return value of a callback method is
not used by Scorpion, if such return should be used the central method
should be used instead.
Note 2: If a plugin is registered with RegisterPlugin
all Callbacks are unregistered in "Central Stop".
Example 1: Class foo - hooking on AfterInspect event
class foo:
def __init__(self):
RegisterCallback('Actions.AfterInspect',self.AfterInpect)
def AfterInspect(self):
print self,'update'
Example 2: Custom Timer class
class TimerClass:
def __init__(self,name='TIMERCLASS'):
self.name=name
RegisterCallback('System.MouseDown',self.MouseDown)
RegisterCallback('System.Timer',self.Timer)
self.timer=GetTimerList().addTimer(self.name,1000)
def __del__(self):
GetTimerList().killTimer('T1')
UnregisterCallback('System.MouseDown',self.MouseDown)
UnregisterCallback('System.Timer',self.Timer)
def Timer(self,Timer):
if Timer==self.name:
t=GetTimerList().getTimer(self.name) #get the timer object
t.active=t.count<25 #deactivate timer
print 'Timer',t.name,t.count
def MouseDown(self,Image,Shift,X,Y):
print 'MouseDown',Image,Shift,X,Y
t=GetTimerList().getTimer(self.name) #get the timer object
if not t.active:
t.count=0 #reset counter
t.active=t.count<25 #reactivate timer
usage:
t=TimerClass('MyTimer')
|