Source code for InspectionCounter

"""
:filename:     InspectionCounter.py
:author:       roar@tordivel.no
:requirements: Scorpion 9.0.0.520 or higher

Scorpion plugin panel for simple inspection counting

::

  1.0.0.3, 11nov2015, RL: modified for autodoc
  1.0.0.2, 06sep2012, RL:
    removed print statements
    added header and version
  1.0.0.1, 12jul2011, RL:
    created
"""

__version__ = '1.0.0.3'

from Scorpion import RegisterCallback,PluginChanged,GetControlByHandle

[docs]class InspectionCounterPlugin(object): 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 RegisterCallback('Actions.BeforeStart',self.beforeStart) RegisterCallback('Actions.AfterStop',self.afterStop) RegisterCallback('System.AfterInspect',self.afterInspect)
[docs] def __str__(self): ''' return a unique persistance name for host application storage ''' return '%s_%s'%(self.__class__.__name__,self.name)
[docs] 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
[docs] 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')
[docs] def beforeStart(self): ''' reset inspection counter ''' self.count=0 self.panel.caption='Reset on Start'
[docs] def afterStop(self): ''' signal stopped ''' self.panel.caption='Inspections while running was %d'%self.count
[docs] def afterInspect(self,Result): ''' increment counter and update panel ''' self.count+=1 self.panel.caption='Inspections=%d' % self.count
[docs]def CreatePlugin(hWnd, name=''): ''' Scorpion Plugin Stub - Required ''' cntr=GetControlByHandle(hWnd) return InspectionCounterPlugin(cntr,name)