Source code for ToolEdit
"""
:filename: ToolEdit.py
:author: thor@tordivel.no
:requirements: Scorpion 9.0.0.494 or higher
Scorpion button panel plugin for launching a tool configuration dialog
::
1.0.0.3, 11nov2015, RL: modified for autodoc
1.0.0.2, 17sep2011, RL: requirements : Scorpion 9.0.0.493 or higher
"""
__version__ = '1.0.0.3'
from Scorpion import PluginNotify,GetControlByHandle,ExecuteCmd,GetTool,SelectTagname,InputStr
[docs]class ToolEdit(object):
'''
ToolEdit
'''
def __init__(self,cntr,name):
self.name=name
cntr.deleteControls() #delete previous added controls if any
self.button=cntr.addControl('Button',0,0)
self.button.left=10
self.button.top=10
self.button.align = 5
self.button.anchors = 2
self.toolName='bt'
self.button.caption='Edit Tool'
self.button.font.bold=1
self.button.onClick=self.buttonClick
def __del__(self):
#print self,'__del__'
pass
[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):
'''
return plugin configuration as string
'''
import SPB
spb=SPB.CreateSpb()
spb.setText('caption',self.button.caption)
spb.setText('toolName',self.toolName)
return spb.xml
[docs] def setConfig(self,value):
'''
set plugin configuration from string
'''
import SPB
spb=SPB.CreateSpb(value)
try:
if spb.isEntry('caption'):self.button.caption=spb.getText('caption')
if spb.isEntry('toolName'):self.toolName=spb.getText('toolName')
except:
print self,': invalid configuration'
[docs] def configure(self):
'''
configure the plugin, return bool whether changed or not
'''
ok,result=InputStr('Set Property','caption - toolName | toolname',self.button.caption + ' - ' +self.toolName)
if ok :
list = result.split(' - ')
if len(list) == 2:
self.button.caption=list[0]
self.toolName=list[1]
else:
self.toolName=result
self.button.caption='Edit Tool'
return ok
[docs] def buttonClick(self,sender,args):
'''
button click handler
'''
if sender==self.button:
#print 'Edit ',self.toolName
tool = GetTool(self.toolName).edit()
[docs]def CreatePlugin(hWnd, name=''):
'''
Scorpion Plugin Stub - Required
'''
cntr=GetControlByHandle(hWnd)
return ToolEdit(cntr,name)