"""
:filename: CameraEditPlugin.py
:author: roar@tordivel.no
:requirements: Scorpion 9.0.0.494 or higher
Scorpion Plugin for access to camera configuration
::
1.0.0.5, 11nov2015, RL: modified for autodoc
1.0.0.4, 10aug2012, RL:
removed accessControl
halign and valign replaces hcenter and vcenter
1.0.0.3, 06aug2012, RL:
added vcenter and hcenter
1.0.0.2, 24dec2011, TV:
enable buttons both in service and setting when init
create standard header
1.0.0.1, 29sep2011, RL:
created
"""
__version__ = '1.0.0.5'
from Scorpion import GetControlByHandle,SpbDialog,PluginChanged,GetCamera
[docs]class CameraEditPlugin(object):
def __init__(self,cntr,name):
self.name=name #name of this instance
self.cntr=cntr #the container control
self.cntr.onResize=self.cntrResize #hook up to resize event to position controls
self.init() #initial state
self.addBttn('Configure','0','1') #add default button
[docs] def __str__(self):
'''
return a unique persistance name for host application storage
'''
return '%s_%s'%(self.__class__.__name__,self.name)
[docs] def init(self):
'''
reset all content and add the description label
'''
self.cntr.deleteControls() #delete previous added controls if any
self.bttns=[] #list of buttons
self.cams=[] #list of objects to edit
self.tabs=[] #list of index of tab to configure
self.desc=self.cntr.addControl('CaptionPanel') #add description label
self.desc.align=1 #top
self.desc.caption='Camera configuration' #default caption
self.halign=0 #bttn horizontal alignment, 0=left,1=center,2=right
self.valign=0 #bttn vertical alignment, 0=top,1=center,2=bottom
[docs] def positionControls(self):
'''
set button positions
'''
n=len(self.bttns)
if n>0:
if self.halign==0:
left=6
elif self.halign==1:
left=int(self.cntr.clientWidth/2 - (n*self.bttns[0].width+(n-1)*6)/2)
else:
left=self.cntr.clientWidth-(self.bttns[0].width+6)*len(self.bttns)
if self.desc.visible:
voffs=self.desc.bottom
else:
voffs=0
if self.valign==0:
top=voffs+6
elif self.valign==1:
top=voffs + int((self.cntr.clientHeight-voffs)/2 - self.bttns[0].height/2)
else:
top=self.cntr.clientHeight-self.bttns[0].height-6
for i in range(len(self.bttns)):
self.bttns[i].left=left
self.bttns[i].top=top
left+=self.bttns[i].width+6
[docs] def addBttn(self,caption,cam,tab):
'''
add a button to the plugin
'''
top=6
if self.desc.visible: top+=self.desc.bottom
bttn=self.cntr.addControl('Button',6,top)
bttn.caption=caption
bttn.left+=len(self.bttns)*(bttn.width+6) #adjust left position
bttn.tag=len(self.bttns) #button index
bttn.onClick=self.bttnClick
self.bttns.append(bttn)
self.cams.append(cam)
self.tabs.append(tab)
[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.setInt('count',len(self.bttns))
spb.setInt('halign',self.halign)
spb.setInt('valign',self.valign)
spb.setText('desc.caption',self.desc.caption)
spb.setBool('desc.visible',self.desc.visible)
for i in range(len(self.bttns)):
spb.setText('button%d.caption'%(i+1),self.bttns[i].caption)
spb.setText('button%d.camera'%(i+1),self.cams[i])
spb.setText('button%d.tab'%(i+1),self.tabs[i])
return spb.xml
[docs] def setConfig(self,value):
'''
set plugin configuration from the string 'value'
'''
self.init()
from SPB import CreateSpb
spb=CreateSpb(value)
if spb.getText('type')==self.__class__.__name__:
if spb.getInt('version')==1:
if spb.isEntry('halign'):self.halign=spb.getInt('halign')
if spb.isEntry('valign'):self.valign=spb.getInt('valign')
if spb.isEntry('desc.caption'):self.desc.caption=spb.getText('desc.caption')
if spb.isEntry('desc.visible'):self.desc.visible=spb.getBool('desc.visible')
if spb.isEntry('count'):
for i in range(spb.getInt('count')):
caption=spb.getText('button%d.caption'%(i+1))
cam=spb.getText('button%d.camera'%(i+1))
tab=spb.getText('button%d.tab'%(i+1))
if caption and cam and tab:
self.addBttn(caption,cam,tab)
else:
self.addBttn('Configure','0','1')
self.positionControls()
[docs] def cntrResize(self,sender,args):
'''
reposition controls
'''
self.positionControls()
[docs] def bttnClick(self,sender,args):
'''
callback when user clicks a button
'''
if sender in self.bttns:
c=GetCamera(self.cams[sender.tag]) #button tag holds the button index
c.edit(self.tabs[sender.tag]) #launch config dialog with given tab visible only
[docs]def CreatePlugin(hWnd, name=''):
'''
Scorpion Plugin Stub - Required
'''
cntr=GetControlByHandle(hWnd)
return CameraEditPlugin(cntr,name)