|
from Scorpion import RegisterCallback,PluginChanged,GetControlByHandle class InspectionCounterPlugin(object): ''' InspectionCounterPlugin roar@tordivel.no 12jul2011 requirements : Scorpion 8.4.0.487 or higher ''' def __init__(self,cntr,name): self.name=name cntr.deleteControls() #delete previous added controls if any self.count = 0 self.panel=cntr.addControl('Panel',0,0) self.panel.align=5 #client self.panel.caption='Inspections=%d' % self.count self.panel.font.size = 15 RegisterCallback('Actions.BeforeStart',self.beforeStart) RegisterCallback('Actions.AfterStop',self.afterStop) RegisterCallback('System.AfterInspect',self.afterInspect) print self,'__init__' def __del__(self): print self,'__del__' def __str__(self): ''' return a unique persistance name for host application storage ''' return '%s_%s'%(self.__class__.__name__,self.name) def getConfig(self): ''' returns plugin configuration as string ''' from SPB import CreateSpb spb=CreateSpb() #create a spb instance, populate with the plugin configuration #and return the xml string spb.setInt('version',1) spb.setInt('count',self.count) return spb.xml def setConfig(self,value): ''' set plugin configuration from the string 'value' ''' from SPB import CreateSpb spb=CreateSpb(value) # TODO: extract plugin configuration from the spb object if spb.getInt('version')>0: if spb.getInt('count')<>None: self.count=spb.getInt('count') def beforeStart(self): ''' reset inspection counter ''' self.count=0 self.panel.caption='Reset on Start' def afterStop(self): ''' signal stopped ''' self.panel.caption='Inspections while running was %d'%self.count def afterInspect(self,Result): ''' increment counter and update panel ''' print self,'afterInspect' self.count+=1 self.panel.caption='Inspections=%d' % self.count def CreatePlugin(hWnd, name=''): ''' Scorpion Plugin Stub - Required ''' cntr=GetControlByHandle(hWnd) return InspectionCounterPlugin(cntr,name) |
|