Source code for Result2DPanel

"""
:filename:     SamplePlugin.py
:author:       thor@tordivel.no
:requirements: Scorpion 9.0.0.492 or higher

Scorpion result panel plugin for displaying 2D results

::

  1.0.0.3, 11nov2015, RL: modified for autodoc
  1.0.0.2, 17sep2011, TV: added persistence for fontSize and propertyDialog
  1.0.0.1, 12jul2011, TV: created
"""

__version__ = '1.0.0.3'

from Scorpion import RegisterCallback,PluginChanged,GetControlByHandle,GetFloatValue,GetBoolValue,InputInt

[docs]class Plugin(object): def __init__(self,cntr,name): self.name=name cntr.deleteControls() #delete previous added controls if any self.panel=cntr.addControl('Panel',0,0) self.panel.align=5 #client self.panel.caption='Press Start to activate system' 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__'
[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('fontSize',self.panel.font.size) 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('fontSize')<>None: self.panel.font.size=spb.getInt('fontSize')
[docs] def configure(self): ''' configure the plugin, return bool whether changed or not ''' ok,result=InputInt('Set Property','fontSize',self.panel.font.size) if ok : self.panel.font.size=result return ok
[docs] def beforeStart(self): ''' beforeStart ''' self.panel.caption='-'
[docs] def afterStop(self): ''' afterStop ''' self.panel.caption='Press Start to activate system'
[docs] def afterInspect(self,Result): ''' afterInspect - update panel ''' x = GetFloatValue('Results.x') y = GetFloatValue('Results.y') angle = GetFloatValue('Results.angle') b0 = GetBoolValue('Results.valid') if b0 : self.panel.caption='x=%.1f,y=%.1f - angle=%.1f' % (x,y,angle) else: self.panel.caption='-'
[docs]def CreatePlugin(hWnd, name=''): ''' Scorpion Plugin Stub - Required ''' cntr=GetControlByHandle(hWnd) return Plugin(cntr,name)