프로젝트의 요구 사항과 사용 중인 디바이스에 따라 스위치보드(Switchboard) 디바이스 기능을 추가 또는 확장해야 할 수 있습니다. 이 페이지에서는 Python을 사용하여 자체 디바이스 플러그인을 만드는 방법을 알아봅니다. 약간의 C++ 지식이 있으면 리스너를 확장하여 보다 다양한 메시지 타입을 수락하게 할 수도 있지만, 여기서는 다루지 않습니다.
다음은 출발점으로 삼을 수 있는 새 디바이스 플러그인 SampleDevice 를 생성하는 방법에 대한 안내입니다.
- 스위치보드에서 디바이스 플러그인이 로드 시 보이게 하려면
\Engine\Plugins\VirtualProduction\Switchboard\Source\Switchboard\switchboard\devices\의<플러그인_이름>\plugin_<플러그인_이름>.py와 같은 명명 규칙에 따라 폴더 및 Python 파일을 생성해야 합니다.- 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)
파일을 스위치보드에서 찾을 수 있는지 확인합니다. 스위치보드를 실행하고 디바이스 추가(Add Device) 드롭다운 메뉴를 펼칩니다. SampleDevice 가 목록에 나타납니다.

- 스위치보드에 SampleDevice를 추가해도 뷰에 위젯이 생성되지는 않습니다. SampleDevice 위젯을 생성하려면
DeviceWidget을plugin_sampledevice.py에서 다음과 같이 확장합니다.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)
스위치보드에 위젯이 표시되는지 확인합니다. 스위치보드를 실행하고 SampleDevice를 추가합니다. 최소한의 SampleDevice 위젯이 뷰에 표시됩니다.

AddDeviceDialog에서 상속받는 새 클래스를 생성하고 이를DeviceSampleDevice클래스의 스태틱 변수add_device_dialog에 할당하여 새 SampleDevice가 추가될 때 커스텀 대화창을 생성합니다.device_widget_base.py에서AddDeviceDialog를 임포트합니다.- Qt 모듈을 PySide2에서 임포트합니다.
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)
스위치보드에 새 디바이스 창이 표시되는지 확인합니다. 스위치보드를 실행하고 SampleDevice를 추가합니다. 대화창에 추가 텍스트 필드가 나타납니다.

- 디바이스의 스위치보드 오른쪽에도 다른 확장 대화창과 함께 탭으로 묶인 위젯을 두고 추가 정보를 공유할 수 있습니다. 이 탭을 생성하려면 클래스 메서드
plug_into_ui를Device베이스 클래스로부터 오버라이드합니다.QtWidgets.QWidget을 상속받는 새 클래스SampleDeviceTabView를 생성합니다.- 위젯 인스턴스를 담기 위해
DeviceSampleDevice에서 클래스 멤버tab_view를 생성합니다. -
DeviceSampleDevice에서 클래스 메서드plug_into_ui를 오버라이드하고tab_view를 새 클래스SampleDeviceTabView로 초기화합니다.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)

지금까지 스위치보드용 새 디바이스 플러그인을 생성하는 단계를 알아봤습니다. 고급 예시는 스위치보드용 nDisplay 디바이스 플러그인을 참고하세요.