Source code for SimpleBatchControlPlugin

"""
:filename:     SimpleBatchControl.py
:author:       roar@tordivel.no
:requirements: Scorpion 10.0.0.536 or higher

The SimpleBatchControl class is a simple user interface to start/stop batches
in Scorpion and giving easy access to batch name and image storage folder for
the profile

  * startBatch
  * stopBatch
  * explore

::

  1.0.0.2, 11nov2015, RL: modified for autodoc
  1.0.0.1, 02may2012,  RL:
    created
    based on BatchControlPlugin 1.0.0.5
"""

__version__ = '1.0.0.2'

import os

from Scorpion import GetControlByHandle,GetStringValue,SetStringValue,GetBoolValue,GetLog
from Scorpion import ExecuteCmd,RegisterCallback,MessageDlg,InputStr,PluginChanged,GetTool

[docs]class SimpleBatchController(object): ''' The SimpleBatchControl class is a simple user interface to start/stop batches in Scorpion and giving easy access to batch name and image storage folder for the profile * startBatch * stopBatch * explore ''' def __init__(self,cntr,name): self.name=name cntr.deleteControls() #delete previous added controls if any self.cntr=cntr #keep a reference to host so we can hook up on size events self.cntr.onResize=self.cntrResize self.start=cntr.addControl('Button',10,10) self.start.caption='Start' self.start.onClick=self.startClick self.inspect=cntr.addControl('Button',self.start.right+8,self.start.top) if GetBoolValue('System.Running'): self.inspect.caption='Inspect' else: self.inspect.caption='Grab' self.inspect.onClick=self.inspectClick self.label=cntr.addControl('Label',self.inspect.right+16,self.start.top+4) self.label.caption='Batch' self.batch=cntr.addControl('Edit',self.label.right+12,self.start.top) self.batch.text=GetStringValue('System.Batch') self.batch.onChange=self.batchChange self.explore=cntr.addControl('Button',self.batch.right+8,self.start.top) self.explore.caption='Explore' self.explore.onClick=self.exploreClick self.cntrResize(None,None) #reposition controls RegisterCallback('Actions.BeforeStart',self.actionsBeforeStart) RegisterCallback('Actions.AfterStop',self.actionsAfterStop) RegisterCallback('System.QueryStop',self.systemQueryStop)
[docs] def getConfig(self): ''' returns plugin configuration as string ''' return 'font=%s|fontsize=%i|buttonwidth=%i|buttonheight=%i'%(self.cntr.font.name,self.cntr.font.size,self.start.width,self.start.height)
[docs] def setConfig(self,value): ''' set plugin configuration from the string 'value' ''' for cmd in value.split('|'): param=cmd.split('=') if len(param)==2: if param[0].lower()=='fontsize': self.cntr.font.size=int(param[1]) elif param[0].lower()=='font': self.cntr.font.name=param[1] elif param[0].lower()=='buttonwidth': self.start.width=int(param[1]) elif param[0].lower()=='buttonheight': self.start.height=int(param[1]) self.cntrResize(None,None) #reposition controls
[docs] def configure(self): ''' configure the plugin, return bool whether changed or not ''' ok,cfg=InputStr('configure','format: "font=<name>|fontsize=<value>|buttonwidth=<value>|buttonheight=<value>"',self.getConfig()) if ok: self.setConfig(cfg) return ok
[docs] def batchChange(self,sender,args): ''' update batch tag ''' SetStringValue('System.Batch',self.batch.text)
[docs] def actionsBeforeStart(self): ''' change button caption and disable controls ''' SetStringValue('System.Batch',self.batch.text) self.start.caption='Stop' self.inspect.caption='Inspect' self.label.enabled=False self.batch.enabled=False
[docs] def actionsAfterStop(self): ''' change button caption and enable controls ''' self.start.caption='Start' self.inspect.caption='Grab' self.label.enabled=True self.batch.enabled=True
[docs] def systemQueryStop(self): ''' acknowlegde stop ''' if MessageDlg('Stop batch',2,3)==6: #check for "Yes" return 0 #stop acknowlegded return 1 #stop denied
[docs] def startClick(self,sender,args): ''' start or stop ''' if GetBoolValue('System.Running'): if self.systemQueryStop()==0: ExecuteCmd('stop','') else: ExecuteCmd('start','')
[docs] def inspectClick(self,sender,args): ''' start or stop ''' ExecuteCmd('GrabExecute','')
[docs] def exploreClick(self,sender,args): ''' launch explorer in video folder ''' try: os.startfile(GetStringValue('System.Storage'),'open') except: print 'BatchControl.Explore failed'
[docs] def cntrResize(self,sender,args): ''' reposition explore button and resize batch edit ''' self.inspect.left = self.start.right+6 self.inspect.width = self.start.width self.inspect.height = self.start.height self.label.left = self.inspect.right+12 self.label.top = self.start.bottom-int((self.batch.height+self.label.height)/2) self.explore.width = self.start.width self.explore.height = self.start.height self.explore.left = self.cntr.clientWidth-self.explore.width-6 self.batch.left = self.label.right+6 self.batch.top = self.start.top+int((self.start.height-self.batch.height)/2) self.batch.right = self.explore.left-12
[docs]def CreatePlugin(hWnd, name=''): ''' Scorpion Plugin Stub - Required ''' cntr=GetControlByHandle(hWnd) return SimpleBatchController(cntr,name)