最低限必要なBoxクラス
pythonコードで最低限実装しておくクラスがBoxクラスです。
今回は下記のようなスケルトンコードに必要なものを実装していく形になります
class MyOVBox(OVBox):
def __init__(self):
OVBox.__init__(self)
def initialize(self):
return
def process(self):
return
box = MyOVBox()
__init__()
で必要な変数を定義しておきます
initialize()
でOpenViBEからのinput値や、setting値を変数に代入します
process()
はOpenViBE実行中にループされるメソッドで、実際に動かしたい処理を書きます
試しに書いて動かしてみる
designerで新しくシナリオを作成します
BoxesのScriptingにあるPython scriptingボックスを配置します
Python scriptingボックスを右クリックしてmodify setting > newからName: Threshold, Type: integer, Default value: 10を入力してsettingを追加します
以下のコードをどこかに保存します
class MyOVBox(OVBox):
def __init__(self):
OVBox.__init__(self)
self.count = 0
self.threshold = 0
def initialize(self):
self.threshold = int(self.setting['Threshold']
def process(self):
self.count += 1
print(self.count)
if self.count >= self.threshold:
print('Count is threshold!')
self.count = 0
box = MyOVBox()
Settingで指定したthresholdの値になるまでカウントしていって、threshold値になったら再び0からカウントしなおすだけのコードです
Python scriptingボックスをダブルクリックして、Scriptから先ほど保存したpythonコードを指定します
RUNするとスクリプトが動き、Messageが流れます