Source code for HeaderLine

"""
:filename:     HeaderLine.py
:author:       roar@tordivel.no
:requirements: Scorpion 9.0.0.529 or higher

Scorpion plugin panel for parameter state signalling

::

  1.0.0.2, 11nov2015, RL: modified for autodoc
  1.0.0.1, 12sep2012, RL: created
"""

__version__ = '1.0.0.2'

from Scorpion import GetControlByHandle,RegisterCallback,GetStringValue,GetBoolValue,PluginChanged,SpbDialog,FontDialog,ColorDialog

[docs]class HeaderLinePlugin(object): def __init__(self,cntr,name): self.name=name #name of this instance self.text='' #static text self.textParam='' #parameter holding text self.stateParam='' #parameter holding ok/fail self.okColor='black' #panel font ok color self.okBackColor='btnface' #panel ok color self.failColor='red' #panel font fail color self.failBackColor='btnface' #panel fail color cntr.deleteControls() #delete previous added controls if any self.header=cntr.addControl('Panel') #add the header panel self.header.align=5 #clien self.header.bevelOuter=0 #no frame self.header.bevelInner=0 #no frame self.header.borderWidth=0 #acts like margins self.miConfig=self.header.addComponent('MenuItem') self.miConfig.caption='Properties' self.miConfig.onClick=self.miConfigClick self.miFont=self.header.addComponent('MenuItem') self.miFont.caption='Font' self.miFont.onClick=self.miFontClick RegisterCallback('Actions.BeforeStart',self.update) RegisterCallback('Actions.AfterInspect',self.update) RegisterCallback('Actions.AfterStop',self.update) RegisterCallback('System.AccessControlChanged',self.systemAccessControlChanged) self.update()
[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 xml ''' from SPB import CreateSpb spb=CreateSpb() spb.setText('type',self.__class__.__name__) spb.setInt('version',1) spb.setText('text',self.text) spb.setText('textParam',self.textParam) spb.setText('stateParam',self.stateParam) spb.setText('okColor',self.okColor) spb.setText('okBackColor',self.okBackColor) spb.setText('failColor',self.failColor) spb.setText('failBackColor',self.failBackColor) spb.setText('fontName',self.header.font.name) spb.setInt('fontSize',self.header.font.size) spb.setInt('fontStyle',self.header.font.style) spb.setInt('alignment',self.header.alignment) spb.setInt('borderWidth',self.header.borderWidth) return spb.xml
[docs] def setConfig(self,value): ''' set plugin configuration from the string 'value' ''' from SPB import CreateSpb spb=CreateSpb(value) if spb.getText('type')==self.__class__.__name__: if spb.getInt('version')==1: try: self.text=spb.getText('text') self.textParam=spb.getText('textParam') self.stateParam=spb.getText('stateParam') self.okColor=spb.getText('okColor') self.okBackColor=spb.getText('okBackColor') self.failColor=spb.getText('failColor') self.failBackColor=spb.getText('failBackColor') self.header.font.name=spb.getText('fontName') self.header.font.size=spb.getInt('fontSize') self.header.font.style=spb.getInt('fontStyle') self.header.alignment=spb.getInt('alignment') self.header.borderWidth=spb.getInt('borderWidth') finally: self.update()
[docs] def configure(self): ''' launch an input dialog for editing plugin ''' ok,cfg=SpbDialog('Plugin configuration',self.getConfig()) if ok: self.setConfig(cfg) PluginChanged(self)
[docs] def update(self): ''' ''' if self.stateParam<>'': if GetBoolValue(self.stateParam)==True: self.header.font.color=self.okColor self.header.color=self.okBackColor else: self.header.font.color=self.failColor self.header.color=self.failBackColor if self.textParam<>'': txt=GetStringValue(self.textParam) if txt<>None: self.header.caption=txt else: self.header.caption='invalid text parameter - "%s"'%self.textParam else: self.header.caption=self.text
[docs] def systemAccessControlChanged(self,settings,service): ''' callback when accesscontrol changes ''' self.miConfig.visible=settings or service self.miFont.visible=settings or service
[docs] def miConfigClick(self,sender,args): ''' launch configuration ''' self.configure()
[docs] def miFontClick(self,sender,args): ''' launch configuration ''' res=FontDialog(self.header.font.name,self.header.font.size,self.header.font.style) if res[0]: self.header.font.name=res[1] self.header.font.size=res[2] self.header.font.style=res[3] PluginChanged(self)
[docs]def CreatePlugin(hWnd, name=''): ''' Scorpion Plugin Stub - Required ''' cntr=GetControlByHandle(hWnd) return HeaderLinePlugin(cntr,name)