プロジェクトのニーズと使用するデバイスに応じて、Switchboard のデバイス機能に対して追加や拡張を行うことができます。このページでは Python で独自のデバイス プラグインを作成する方法を説明します。C++ のナレッジがあれば、リスナーの拡張により受信するメッセージの種類を増やすことができます (ここでは説明しません)。
次の手順では、たたき台として Switchboard に対応した新しいデバイス プラグインである SampleDevice を作成する方法について説明します。
- このデバイス プラグインが Switchboard の読み込み時に検出されるように、命名規則「
<plugin_name>\plugin_<plugin_name>.py
」に従ってフォルダと Python ファイルを「\Engine\Plugins\VirtualProduction\Switchboard\Source\Switchboard\switchboard\devices\
」配下に作成します。- SampleDevice プラグインの場合は以下のファイルを作成します。
\Engine\Plugins\VirtualProduction\Switchboard\Source\Switchboard\switchboard\devices\sampledevice\plugin_sampledevice.py
。
- SampleDevice プラグインの場合は以下のファイルを作成します。
- 「
\Engine\Plugins\VirtualProduction\Switchboard\Source\Switchboard\switchboard\devices\device_base.py
」で定義されたDevice
クラスを拡張して「plugin_sampledevice.py
」ファイルとます。- 「
device_base.py
」からDevice
をインポートします。 Device
を継承して、新しいクラスDeviceSampleDevice
を作成します。- 「
switchboard/switchboard_logging.py
」からエラー報告に使用するLOGGER
をインポートします。
- 「
from switchboard.devices.device_base import Device
from switchboard.switchboard_logging import LOGGER
class DeviceSampleDevice(Device):`
def __init__(self, name, ip_address, **kwargs):
super().__init__(name, ip_address, **kwargs)
このファイルを Switchboard から検出できることを確認します。Switchboard を起動して [Add Device] ドロップダウン メニューを展開します。一覧に SampleDevice が表示されます。

- SampleDevice を Switchboard に追加するだけでは、ウィジェットがビューに作成されません。「
plugin_sampledevice.py
」でDeviceWidget
を拡張して SampleDevice ウィジェットを作成します。- 「
device_widget_base.py
」からDeviceWidget
をインポートします。 DeviceWidget
を継承して、新しいクラスDeviceWidgetSampleDevice
を作成します。
- 「
from switchboard.devices.device_base import Device
from switchboard.devices.device_widget_base import DeviceWidget
from switchboard.switchboard_logging import LOGGER
class DeviceSampleDevice(Device):
def __init__(self, name, ip_address, **kwargs):
super().__init__(name, ip_address, **kwargs)
class DeviceWidgetSampleDevice(DeviceWidget):
def __init__(self, name, device_hash, ip_address, icons, parent=None):
super().__init__(name, device_hash, ip_address, icons, parent=parent)
このウィジェットが Switchboard に表示されることを確認します。Switchboard を起動して SampleDevice を追加します。最小限の SampleDevice ウィジェットがビューに表示されます。

AddDeviceDialog
を継承する新しいクラスを作成し、それをDeviceSampleDevice
クラスのスタティック変数add_device_dialog
に割り当てることにより、新しい SampleDevice を追加する時にカスタム ダイアログを作成します。- 「
device_widget_base.py
」からAddDeviceDialog
をインポートします。 - PySide2 から Qt モジュールをインポートします。
AddDeviceDialog
を継承する新しいクラスAddSampleDeviceDialog
を作成し、基本クラスのコンストラクタ呼び出しで device_type パラメータに "SampleDevice" を設定します。- この新しいクラスのコンストラクタで、QLineEdit テキスト フィールドをダイアログに追加します。
DeviceSampleDevice
のadd_device_dialog
スタティック変数を、この新しいクラスでオーバーライドします。
- 「
from switchboard.devices.device_base import Device
from switchboard.devices.device_widget_base import AddDeviceDialog, DeviceWidget
from switchboard.switchboard_logging import LOGGER
from PySide2 import QtWidgets, QtGui, QtCore
class AddSampleDeviceDialog(AddDeviceDialog):
def __init__(self, existing_devices, parent=None):
super().__init__(device_type="SampleDevice", existing_devices=existing_devices, parent=parent)
# Create QTWidgets to add to the form
self.additional_text_field = QtWidgets.QLineEdit(self)
# Append the new options to the QTWidgets.QFormLayout object defined in the parent class
self.form_layout.addRow("Additional Text", self.additional_text_field)
class DeviceSampleDevice(Device):
# Override the add device dialog object associated with the device plugin
add_device_dialog = AddSampleDeviceDialog
def __init__(self, name, ip_address, **kwargs):
super().__init__(name, ip_address, **kwargs)
class DeviceWidgetSampleDevice(DeviceWidget):
def __init__(self, name, device_hash, ip_address, icons, parent=None):
super().__init__(name, device_hash, ip_address, icons, parent=parent)
この新しいデバイス ダイアログが Switchboard に表示されることを確認します。Switchboard を起動して SampleDevice を追加します。追加のテキスト フィールドがダイアログに表示されます。

- Switchboard の右側にデバイスのウィジェットを配置し、他の拡張ダイアログにタブを追加して、より多くの情報を共有できます。基本クラス
Device
のクラス メソッドplug_into_ui
をオーバーライドして、このタブを作成します。QtWidgets.QWidget
を継承して、新しいクラスSampleDeviceTabView
を作成します。DeviceSampleDevice
にクラス メンバーtab_view
を作成して、このウィジェットのインスタンスを保持します。DeviceSampleDevice
のクラス メソッドplug_into_ui
をオーバーライドし、新しいクラスSampleDeviceTabView
でtab_view
を初期化します。
from switchboard.devices.device_base import Device
from switchboard.devices.device_widget_base import AddDeviceDialog, DeviceWidget
from switchboard.switchboard_logging import LOGGER
from PySide2 import QtWidgets, QtGui, QtCore
class AddSampleDeviceDialog(AddDeviceDialog):
def __init__(self, existing_devices, parent=None):
super().__init__(device_type="SampleDevice", existing_devices=existing_devices, parent=parent)
# Create QTWidgets to add to the form
self.additional_text_field = QtWidgets.QLineEdit(self)
# Append the new options to the QTWidgets.QFormLayout self.form_layout object defined in the parent class
self.form_layout.addRow("Additional Text", self.additional_text_field)
class DeviceSampleDevice(Device):
add_device_dialog = AddSampleDeviceDialog # Override the default dialog for the plugin
tab_view = None
def __init__(self, name, ip_address, **kwargs):
super().__init__(name, ip_address, **kwargs)
@classmethod
def plug_into_ui(cls, menubar, tabs):
''' Implementation of base class function that allows plugin to inject UI elements.
'''
if not cls.tab_view:
cls.tab_view = SampleDeviceTabView(parent=tabs)
tabs.addTab(cls.tab_view, 'SampleDevice Tab')
class DeviceWidgetSampleDevice(DeviceWidget):
def __init__(self, name, device_hash, ip_address, icons, parent=None):
super().__init__(name, device_hash, ip_address, icons, parent=parent)
class SampleDeviceTabView(QtWidgets.QWidget):
def __init__(self, parent):
QtWidgets.QWidget.__init__(self, parent)

ここまでの手順で、Switchboard の新しいデバイス プラグインの作成方法を説明しました。より高度なサンプルについては、Switchboard の nDisplay デバイス プラグインを参照してください。