"""
:filename: CameraPropertyControlPlugin.py
:author: roar@tordivel.no
:requirements: * Scorpion 9.0.0.494 or higher
* FireGrab 3.0.0.42 or higher
* TISCameraExt.dll 1.0.0.1 or higher
CameraPropertyControlPlugin - Plugin for camera property control
::
1.0.0.3, 11nov2015, RL: modified for autodoc
1.0.0.2, 24dec2011, TV:
set verbose=0
create standard header
1.0.0.1, 24nov2011, RL: created
"""
__version__ = '1.0.0.3'
from Scorpion import RegisterCallback,PluginChanged,PluginNotify,GetControlByHandle,GetCamera,SpbDialog
[docs]class CameraPropertyControlPlugin(object):
'''
CameraPropertyControlPlugin - Plugin for camera property control
'''
[docs] class CameraPropertyControlContainer(object):
'''
Container for single camera property controls
'''
def __init__(self,owner,property,top):
self.owner=owner
self.property=property
self.lblProp=self.owner.gbCamera.addControl('Label',10,top)
self.eValue=self.owner.gbCamera.addControl('Edit',160,top-2)
self.eValue.width=50
self.bSet=self.owner.gbCamera.addControl('Button',self.eValue.right+6,top-2)
self.bSet.width=50
self.bSet.height=self.eValue.height
self.bGet=self.owner.gbCamera.addControl('Button',self.bSet.right+6,top-2)
self.bGet.width=50
self.bGet.height=self.eValue.height
self.cbAuto=self.owner.gbCamera.addControl('CheckBox',self.bGet.right+6,top)
self.cbAuto.width=50
self.bOnePush=self.owner.gbCamera.addControl('Button',self.cbAuto.right+6,top-2)
self.bOnePush.width=50
self.bOnePush.height=self.eValue.height
self.bSet.caption='Set'
self.bGet.caption='Get'
self.cbAuto.caption='Auto'
self.bOnePush.caption='OnePush'
self.bOnePush.visible=False
self.bSet.onClick=self.setClick
self.bGet.onClick=self.getClick
self.cbAuto.onClick=self.autoClick
self.bOnePush.onClick=self.onePushClick
self.update()
# camera accessors
[docs] def getRange(self):
r=self.owner.camera.getPropertyRange(self.property)
if r<>None:return r
return ''
[docs] def getValue(self):
return self.owner.camera.getProperty(self.property)
[docs] def setValue(self,value):
self.owner.camera.setProperty(self.property,value)
PluginNotify(self.owner,'SetValue',(self.property,value))
[docs] def getAuto(self):
return self.owner.camera.getProperty(self.property+'.flags')==1
[docs] def setAuto(self,value):
if value: flags=1
else: flags=2
self.owner.camera.setProperty(self.property+'.flags',flags)
PluginNotify(self.owner,'SetAuto',(self.property,flags))
[docs] def onePush(self):
from ctypes import cdll
from os import path
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,'Focus'):
print 'OnePush Focus failed'
dll.CloseDevice(handle)
print 'Unable to load TISCameraExt.dll'
# update controls due to camera state
[docs] def update(self):
camOpen=self.owner.camera.open
if camOpen:
self.lblProp.caption='%s %s'%(self.property,self.getRange())
self.eValue.text=str(self.getValue())
self.cbAuto.checked=self.getAuto()
else:
self.lblProp.caption=self.property
self.eValue.text=''
self.lblProp.enabled=camOpen
self.eValue.enabled=camOpen
self.bSet.enabled=camOpen
self.bGet.enabled=camOpen
self.cbAuto.enabled=camOpen
self.bOnePush.enabled=camOpen
# control callback methods
[docs] def setClick(self,sender,args):
self.setValue(int(self.eValue.text))
self.update()
[docs] def getClick(self,sender,args):
self.update()
[docs] def autoClick(self,sender,args):
self.setAuto(self.cbAuto.checked)
self.update()
[docs] def onePushClick(self,sender,args):
self.onePush()
def __init__(self,cntr,name):
'''
initiate plugin with default values
'''
self.name=name
self.cameraNo=0 #default camera index
self.props='Exposure' #default property
self.cpccs=[] #list of CameraPropertyControlContainer's
self.camera=GetCamera(str(self.cameraNo)) #default camera
self.verbose=0 #debug level, 0=None, 1=debug printouts
cntr.deleteControls() #delete previous added controls if any
self.gbCamera=cntr.addControl('GroupBox')
self.gbCamera.align=5
self.createControls()
self.pStatus=cntr.addControl('Panel',6,16) #set owner to ctrl so it wont be removed when
self.pStatus.height=8 #deleting all groupbox controls in createControls
self.pStatus.width=8
self.pStatus.bevelInner=0
self.pStatus.bevelOuter=1
self.pStatus.caption=''
RegisterCallback('Camera.Open',self.cameraOpen)
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 createControls(self):
'''
create controls for each property defined
'''
self.gbCamera.caption=self.camera.name
self.gbCamera.deleteControls()
self.cpccs=[]
top=26
for prop in self.props.split(';'):
if prop<>'':
self.cpccs.append(self.CameraPropertyControlContainer(self,prop,top))
top+=24
[docs] def update(self):
'''
update controls due to camera state
'''
self.gbCamera.caption=self.camera.name
camOpen=self.camera.open
if camOpen: self.pStatus.color='lime'
else: self.pStatus.color='red'
for cpcc in self.cpccs:
cpcc.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)
props=''
for cpcc in self.cpccs:
if cpcc.getValue()<>None:spb.setInt('%s.value'%cpcc.property,cpcc.getValue())
if cpcc.getAuto()<>None:spb.setBool('%s.auto'%cpcc.property,cpcc.getAuto())
spb.setBool('%s.showAuto'%cpcc.property,cpcc.cbAuto.visible)
spb.setBool('%s.showOnePush'%cpcc.property,cpcc.bOnePush.visible)
props+=cpcc.property+';'
spb.setText('properties',self.props)
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.camera=GetCamera(str(self.cameraNo))
self.gbCamera.caption=self.camera.name
self.props=spb.getText('properties')
self.createControls()
for cpcc in self.cpccs:
if spb.getInt('%s.value'%cpcc.property)<>None: cpcc.setValue(spb.getInt('%s.value'%cpcc.property))
if spb.getBool('%s.auto'%cpcc.property)<>None: cpcc.setAuto(spb.getBool('%s.auto'%cpcc.property))
cpcc.cbAuto.visible=spb.getBool('%s.showAuto'%cpcc.property)==True
cpcc.bOnePush.visible=spb.getBool('%s.showOnePush'%cpcc.property)==True
[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 CreatePlugin(hWnd, name=''):
'''
Scorpion Plugin Stub - Required
'''
cntr=GetControlByHandle(hWnd)
return CameraPropertyControlPlugin(cntr,name)