"""
:filename: SamplePlugin.py
:author: roar@tordivel.no
:requirements: Scorpion 9.0.0.494 or higher
Scorpion sample plugin for hosting controls inside a PluginManager
hosted panel/page
::
1.0.0.2, 11nov2015, RL: modified for autodoc
1.0.0.1, 03jun2015, RL: created
"""
__version__ = '1.0.0.2'
from Scorpion import GetControlByHandle,SpbDialog,PluginChanged
[docs]class SamplePlugin(object):
"""
The SamplePlugin class
``cntr`` - native Scorpion WinControl
``name`` - Scorpion supplied instance unique name
"""
def __init__(self,cntr,name):
"""Creates some sample controls in client window"""
self.name=name #name of this instance
self.cntr=cntr #the container control
self.cntr.deleteControls() #delete previous added controls if any
self.panel=self.cntr.addControl('Panel') #add a panel
self.panel.align=5 #client area
self.panel.bevelOuter=0 #hides the panel frame
self.panel.font.size=16 #enlarge the size
self.panel.caption='Sample Plugin' #set container panel caption
[docs] def __str__(self):
"""
Returns an instance unique name for the plugin.
The unique name is used for persistance key by the host application if the
plugin has configuration. Python objects default's to an instance name like
"<__main__.A object at 0x053E02D0>" where the address part will change for
each instance of the plugin.
This method is not required if the plugin don't have any configuration but
it's still good practice implementing.
"""
return '%s_%s'%(self.__class__.__name__,self.name)
[docs] def getConfig(self):
"""
Return the plugin configuration as a string, any format. The host application
don't care the content so any suitable string content may be used. It is still
recommended to use a format that is prepared for plugin upgrades so the plugin
will still work with configuration from a previous version of the plugin.
In this sample an spbxml object is used as this is suitable for querying the
configuration content. A string representation of a dictionary is also suitable.
The configuration persistance is maintained by the host application.
"""
from SPB import CreateSpb
spb=CreateSpb()
spb.setText('type',self.__class__.__name__)
spb.setInt('version',1) #set version for future use
return spb.xml
[docs] def setConfig(self,value):
"""
Set plugin configuration from the string 'value'. The host application sets the
configuration after the plugin is created.
``value`` - string representation of new configuration
"""
from SPB import CreateSpb
spb=CreateSpb(value)
if spb.getText('type')==self.__class__.__name__:
if spb.getInt('version')==1: #check version before usage
pass
[docs]def CreatePlugin(hWnd, name=''):
"""
Scorpion Plugin Stub - **Required** - called by Scorpion for plugin creation
``hWnd`` - parent window handle
``name`` - Scorpion supplied unique instance name
"""
cntr=GetControlByHandle(hWnd)
return SamplePlugin(cntr,name)