Source code for CameraStatus

"""
:filename:     CameraStatus.py
:author:       roar@tordivel.no
:requirements: Scorpion 9.0.0.524 or higher

Scorpion plugin for showing camera status as ``diodes``

::

  1.0.0.3, 11nov2015, RL: modified for autodoc
  1.0.0.2, 21aug2012, RL:
    changed color priority - open/simulation/error
    adjusted label position
  1.0.0.1, 09aug2012, RL: initial version
"""

__version__ = '1.0.0.3'

from Scorpion import RegisterCallback,GetCameras,GetBoolValue,GetControlByHandle

[docs]class CameraStatusPlugin(object): def __init__(self,cntr,name): self.name=name #current instance name self.cntr=cntr #keep a reference to container self.statusPanels=[] #list of all statuspanels self.cntr.deleteControls() #delete previous added controls if any self.cntr.onResize=self.cntrResize self.gbStatus=self.cntr.addControl('GroupBox') #add the statuspanel container self.gbStatus.align=5 #client self.gbStatus.caption='Camera Status' self.createControls() #initial control creation self.update() #update status RegisterCallback('Camera.Open',self.cameraOpen) RegisterCallback('System.CameraError',self.systemCameraError)
[docs] def __str__(self): ''' return a unique persistance name for host application storage ''' return '%s_%s'%(self.__class__.__name__,self.name)
[docs] def createControls(self): ''' create label and all status panels ''' PANELSIZE=12 HOFFS=4 cams=GetCameras() self.gbStatus.deleteControls() #delete previous added controls if any self.statusPanels=[] self.lblOpen=self.gbStatus.addControl('Label',8,int(self.gbStatus.clientHeight/2)-2) self.lblOpen.caption='Open' left=self.lblOpen.right+2*HOFFS for i in range(cams.count): panel=self.gbStatus.addControl('Panel',left,self.lblOpen.top+1) panel.caption='' panel.hint=cams.getCamera(i).name panel.showHint=True panel.width=PANELSIZE panel.height=PANELSIZE panel.bevelInner=1 panel.bevelOuter=0 left=panel.right+HOFFS self.statusPanels.append(panel)
[docs] def update(self): ''' update plugin ''' cams=GetCameras() #verify configuration if cams.count<>len(self.statusPanels): self.createControls() #update color for all panels for i in range(cams.count): cam=cams.getCamera(i) if cam.open: self.statusPanels[i].color='lime' elif GetBoolValue('System.CameraSimulation'): self.statusPanels[i].color='white' else: self.statusPanels[i].color='red'
[docs] def cntrResize(self,sender,args): ''' resize controls due to panel changes ''' self.lblOpen.top=int(self.gbStatus.clientHeight/2)-2 for p in self.statusPanels: p.top=self.lblOpen.top+1
[docs] def cameraOpen(self,Camera,Open): ''' callback when camera open changes ''' self.update()
[docs] def systemCameraError(self,CameraNo,Camera): ''' update status for actual camera ''' self.update()
[docs]def CreatePlugin(hWnd, name=''): ''' Scorpion Plugin Stub - Required ''' cntr=GetControlByHandle(hWnd) return CameraStatusPlugin(cntr,name)