Source code for PelletsResultPanel

"""
:filename:     PelletsResultPanel.py
:author:       Olav.Johan.Horgen@tordivel.no
:requirements: Scorpion 9.0.0.492 or higher

Scorpion plugin panel for pellets counting

::

  1.0.0.2, 11nov2015, RL: modified for autodoc
  1.0.0.1, 29aug2011, OJH: created
"""

__version__ = '1.0.0.2'

from Scorpion import RegisterCallback,PluginChanged,GetControlByHandle,GetValue,GetStringValue,GetBoolValue,GetIntValue

[docs]class PelletsResultPanel(object): def __init__(self,cntr,name): self.name=name cntr.deleteControls() #delete previous added controls if any self.resultPanel=cntr.addControl('Panel',2,2) # addControl(type control,top,left) self.resultPanel.width = (cntr.clientWidth * 2) / 4 -2 #self.resultPanel.height = cntr.clientHeight - 4 self.resultPanel.align = 3 #left self.resultPanel.anchors = 15 self.resultPanel.color = 'green' self.resultPanel.caption = '' self.Label_1 = self.resultPanel.addControl('Label',15,2) self.Label_2 = self.resultPanel.addControl('Label',15,(self.resultPanel.height / 2) + 2) #self.panel.align=5 #client merdString = self.getMerdName() self.Label_1.caption = merdString self.Label_1.font.size = 15 self.Label_2.caption = 'Pellets = ' self.Label_2.font.size = 15 RegisterCallback('System.AfterInspect',self.afterInspect) print 'Panel client width' , self.resultPanel.clientWidth print 'Panel client height' , self.resultPanel.clientHeight print 'Panel height' , self.resultPanel.height print 'Panel width' , self.resultPanel.width self.warningPanel = cntr.addControl('Panel',2,(cntr.clientWidth) / 2 +2) self.warningPanel.width = (cntr.clientWidth) / 4 - 2 self.warningPanel.color = 'yellow' self.warningPanel.align = 5 #self.pelletWarningPanel.anchors = 15 self.warningPanel.caption = '-' self.warningPanel.font.size = 15 self.alarmPanel = cntr.addControl('Panel',2,(cntr.clientWidth *3)/4 +2) self.alarmPanel.width = (cntr.clientWidth) / 4 - 2 self.alarmPanel.color = 'red' self.alarmPanel.align = 4 #self.toMuchPelletsPanel.anchors = 15 self.alarmPanel.caption = '-' self.alarmPanel.font.size = 15 #self.toMuchPelletsPanel.color = 'red' 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) 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: pass
[docs] def getMerdName(self): profile = GetStringValue('System.SystemName') profileName = profile.split(' ') merdNumber = str(profileName[1]) merdName = GetStringValue('Setup.MerdNavn') merdString = str(merdName) + ' ' + str(merdNumber) return merdString
[docs] def afterInspect(self,Result): ''' increment counter and update panel ''' # update the plugin self.alarmPanel.caption = str(GetIntValue('StateCounter.AlarmCountSinceMidnight')) self.warningPanel.caption = str(GetIntValue('StateCounter.WarningCountSinceMidnight')) self.Label_2.caption = 'Pellets = ' + str(GetValue('Results.pelletsPrImageInPeriod')) merdString = self.getMerdName() self.Label_1.caption = merdString if GetBoolValue('pellets.Value') == True: self.resultPanel.color = 'red' elif GetBoolValue('PelletsWarning.Value') == True: self.resultPanel.color = 'yellow' else: self.resultPanel.color = 'green' print 'after inspect called'
[docs]def CreatePlugin(hWnd, name=''): ''' Scorpion Plugin Stub - Required ''' cntr=GetControlByHandle(hWnd) return PelletsResultPanel(cntr,name)