Source code for TISOnePushPlugin

"""
:filename:     TISOnePushPlugin.py
:author:       roar@tordivel.no
:requirements: * Scorpion 9.0.0.496 or higher
               * FireGrab 3.0.0.42 or higher
               * TISCameraExt.dll 1.0.0.1 or higher

Scorpion GUI plugin for controlling camera properties
Based on The Imaging Source "IC Imaging Control 3.2 SDK"

Plugin for camera property control

::

  1.0.0.2, 11nov2015, RL: modified for autodoc
  1.0.0.1, 24nov2011, RL: created
"""

__version__ = '1.0.0.2'

from Scorpion import RegisterCallback,PluginChanged,PluginNotify,GetControlByHandle,GetCamera,SpbDialog

[docs]class TISOnePushPlugin(object): """ Scorpion GUI plugin for controlling camera properties Based on The Imaging Source "IC Imaging Control 3.2 SDK" Plugin for camera property control """ def __init__(self,cntr,name): ''' initiate plugin with default values ''' self.host=cntr #keep a copy of host so we can hook into resize self.name=name #remember name as it is used in __str__ method self.cameraNo=0 #default camera index self.align=1 #0=left,1=center,2=right self.fontSize=8 #button fontsize self.showTuning=True #flag for showing +/- buttons self.property='Focus' #default property self.camera=GetCamera(str(self.cameraNo)) #default camera self.step=1 #property step on pluss/minus self.verbose=0 #debug level, 0=None, 1=debug printouts cntr.deleteControls() #delete previous added controls if any self.host.onResize=self.resize #hook up into resize event self.gbCamera=cntr.addControl('GroupBox') self.gbCamera.caption=self.property self.gbCamera.align=5 self.pStatus=self.gbCamera.addControl('Panel',6,16) self.pStatus.height=8 self.pStatus.width=8 self.pStatus.bevelInner=0 self.pStatus.bevelOuter=1 self.pStatus.caption='' self.bOnePush=self.gbCamera.addControl('Button',16,16) self.bOnePush.caption='Auto' self.bMinus=self.gbCamera.addControl('Button') self.bMinus.caption='-' self.bPlus=self.gbCamera.addControl('Button') self.bPlus.caption='+' self.bOnePush.onClick=self.onePushClick self.bMinus.onClick=self.minusClick self.bPlus.onClick=self.plussClick RegisterCallback('Camera.Open',self.cameraOpen) self.setFontSize(self.fontSize) self.resize(self.gbCamera,None) self.update() if self.verbose:print self,'__init__'
[docs] def __del__(self): ''' do nessesary cleanup if any ''' if self.verbose:print self,'__del__'
[docs] def __str__(self): ''' return a unique persistance name for host application storage ''' return '%s_%s'%(self.__class__.__name__,self.name.replace('.','_'))
[docs] def setFontSize(self,value): self.fontSize=value self.bOnePush.font.size=self.fontSize self.bMinus.font.size=self.fontSize self.bPlus.font.size=self.fontSize
[docs] def update(self): ''' update controls due to camera state ''' camOpen=self.camera.open if camOpen: self.pStatus.color='lime' else: self.pStatus.color='red' self.bOnePush.enabled=camOpen self.bMinus.enabled=camOpen self.bPlus.enabled=camOpen self.bMinus.visible=self.showTuning self.bPlus.visible=self.showTuning
[docs] def getValue(self): ''' get camera property value ''' return self.camera.getProperty(self.property)
[docs] def setValue(self,value): ''' set camera property value ''' self.camera.setProperty(self.property,value)
[docs] def onePush(self): ''' call camera property onePush ''' from ctypes import cdll from os import path try: cdll.LoadLibrary(path.dirname(__file__)+"\\TIS_DShowLib09.dll") cdll.LoadLibrary(path.dirname(__file__)+"\\TIS_UDSHL09_vc9.dll") dll=cdll.LoadLibrary(path.dirname(__file__)+"\\TISCameraExt.dll") handle = dll.OpenDevice(GetCamera('0').name) if handle>-1: if not dll.OnePush(handle,self.property): print 'OnePush %s failed'%self.property dll.CloseDevice(handle) except Exception,msg: print 'Error loading TID dlls',msg # control callback methods
[docs] def resize(self,sender,args): ''' resize controls ''' self.bOnePush.height=self.gbCamera.height-24 #height due to client height if self.align==0: self.bOnePush.left=16 self.bOnePush.width=self.bOnePush.height #square button elif self.align==1: self.bOnePush.left=16 self.bOnePush.width=self.gbCamera.clientWidth-self.bOnePush.left-6-int(self.showTuning)*(6+self.bOnePush.height/2) else: self.bOnePush.width=self.bOnePush.height #square button self.bOnePush.left=self.gbCamera.clientWidth-self.bOnePush.width-6-int(self.showTuning)*(6+self.bOnePush.height/2) self.pStatus.left=self.bOnePush.left-10 self.bMinus.height=int(self.bOnePush.height/2)-1 self.bMinus.width=self.bMinus.height self.bMinus.top=self.bOnePush.top self.bMinus.left=self.bOnePush.right+6 self.bPlus.height=self.bMinus.height self.bPlus.width=self.bPlus.height self.bPlus.left=self.bMinus.left self.bPlus.top=self.bOnePush.bottom-self.bPlus.height
[docs] def onePushClick(self,sender,args): self.onePush() if self.verbose:print self,'onePush' PluginNotify(self,'OnePush',self.property)
[docs] def minusClick(self,sender,args): self.setValue(self.getValue()-self.step) if self.verbose:print self,'minus',self.getValue() PluginNotify(self,'Minus',(self.property,self.getValue()))
[docs] def plussClick(self,sender,args): self.setValue(self.getValue()+self.step) if self.verbose:print self,'plus',self.getValue() PluginNotify(self,'Plus',(self.property,self.getValue()))
[docs] def cameraOpen(self,Camera,Open): ''' callback when camera opens/closes ''' cam=GetCamera(Camera) if cam.index==self.cameraNo: self.camera=cam self.update()
[docs] def getConfig(self): ''' returns plugin configuration as string ''' from SPB import CreateSpb spb=CreateSpb() spb.name=self.__class__.__name__ #create a spb instance, populate with the plugin configuration #and return the xml string spb.setInt('version',1) spb.setInt('cameraNo',self.cameraNo) spb.setInt('step',self.step) spb.setInt('align',self.align) spb.setInt('fontSize',self.fontSize) spb.setText('property',self.property) spb.setText('caption',self.gbCamera.caption) spb.setText('onePushCaption',self.bOnePush.caption) spb.setBool('showTuning',self.showTuning) 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.name==self.__class__.__name__: if spb.getInt('version')==1: self.cameraNo=spb.getInt('cameraNo') self.step=spb.getInt('step') self.align=spb.getInt('align') self.fontSize=spb.getInt('fontSize') self.property=spb.getText('property') self.gbCamera.caption=spb.getText('caption') self.bOnePush.caption=spb.getText('onePushCaption') self.showTuning=spb.getBool('showTuning') self.setFontSize(self.fontSize) self.camera=GetCamera(str(self.cameraNo)) self.resize(self,None) 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 CreatePlugin(hWnd, name=''): ''' Scorpion Plugin Stub - Required ''' cntr=GetControlByHandle(hWnd) return TISOnePushPlugin(cntr,name)