Validator widget example
Here we will add a widget to the previous validator plugin, that fetches and displays the root nodes of the node graph.
Create the validator widget Python file:
# :coding: utf-8
# :copyright: Copyright (c) 2014-2024 ftrack
from Qt import QtWidgets, QtCore, QtGui
from ftrack_qt.utils.decorators import invoke_in_qt_main_thread
from ftrack_framework_qt.widgets import BaseWidget
class MayaShowRootNodeWidget(BaseWidget):
'''Main class to represent a list of Maya node graph root nodes'''
name = 'maya_show_root_nodes'
ui_type = 'qt'
def __init__(
self,
event_manager,
client_id,
context_id,
plugin_config,
group_config,
on_set_plugin_option,
on_run_ui_hook,
parent=None,
):
self._node_list = None
super(MayaShowRootNodeWidget, self).__init__(
event_manager,
client_id,
context_id,
plugin_config,
group_config,
on_set_plugin_option,
on_run_ui_hook,
parent,
)
def pre_build_ui(self):
layout = QtWidgets.QHBoxLayout()
layout.setContentsMargins(0, 0, 0, 0)
layout.setAlignment(QtCore.Qt.AlignTop)
self.setLayout(layout)
self.setSizePolicy(
QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed
)
def build_ui(self):
'''build function widgets.'''
label = QtWidgets.QLabel("Current root nodes:")
self._list = QtWidgets.QListWidget()
# Add the widgets to the layout
self.layout().addWidget(label)
self.layout().addWidget(self._list)
def post_build_ui(self):
'''hook events'''
pass
def populate(self):
'''Fetch info from plugin to populate the widget'''
self.query_nodes()
def query_nodes(self):
'''Query All cameras from scene.'''
payload = {}
self.run_ui_hook(payload)
@invoke_in_qt_main_thread
def ui_hook_callback(self, ui_hook_result):
'''Handle the result of the UI hook.'''
super(MayaShowRootNodeWidget, self).ui_hook_callback(ui_hook_result)
self._list.clear();
self._list.addItems(ui_hook_result)
- You can add this to the tool-config