# -*- coding: utf-8 -*- """ :author: Jeremy Ernst :description: This module contains a class that presents a widget for setting the parent joint of a component. """ import os from artv2.third_party.Qt import QtWidgets, QtCore, QtGui import artv2.utilities.interface_utilities as interface_utils import artv2.utilities.component_utilities as component_utils import artv2.tools.rigging.rig_builder.parent_list_widget as parent_list import pymel.core as pm class SetParentWidget(interface_utils.ARTv2Window): """ This class presents a widget for setting the parent joint of a component. It is invoked from the ComponentContextMenu. :param metanode: string name of the component’s network node that the parent will be set on. :param parent: the instance of the RigBuilderUI which will be this widget’s parent. .. figure:: /images/set_parent_widget.png :width: 220px :align: center :height: 108px :figclass: align-center """ SETTINGS_NAME = "SetComponentParentWIN" WINDOW_NAME = "artv2_set_component_parent_window" # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # def __init__(self, metanode, parent=None): super(SetParentWidget, self).__init__(220, 50, "Set Parent", parent) self.metanode = pm.PyNode(metanode) self._build_interface() # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # def _build_interface(self): main_widget = QtWidgets.QWidget() self.setCentralWidget(main_widget) main_layout = QtWidgets.QVBoxLayout(main_widget) parent_layout = QtWidgets.QHBoxLayout() main_layout.addLayout(parent_layout) parent_label = QtWidgets.QLabel("Parent:") parent_label.setMinimumWidth(interface_utils.scale_by_dpi(40)) parent_label.setMaximumWidth(interface_utils.scale_by_dpi(40)) parent_layout.addWidget(parent_label) self.parent_field = QtWidgets.QLineEdit() parent_button = QtWidgets.QPushButton() parent_button.setMinimumWidth(interface_utils.scale_by_dpi(25)) parent_button.setMaximumWidth(interface_utils.scale_by_dpi(25)) parent_button.setMinimumHeight(interface_utils.scale_by_dpi(25)) parent_button.setMaximumHeight(interface_utils.scale_by_dpi(25)) icon = QtGui.QIcon(os.path.join(self.icon_path, "general/search.png")) parent_button.setIconSize(QtCore.QSize(21, 21)) parent_button.setIcon(icon) parent_layout.addWidget(self.parent_field) parent_layout.addWidget(parent_button) self._populate_field() completer = QtWidgets.QCompleter(component_utils.get_all_created_joints()) completer.setCaseSensitivity(QtCore.Qt.CaseInsensitive) self.parent_field.setCompleter(completer) parent_button.clicked.connect(self._launch_parent_list) button_layout = QtWidgets.QHBoxLayout() main_layout.addLayout(button_layout) cancel_button = QtWidgets.QPushButton("Cancel") cancel_button.clicked.connect(self.close) confirm_button = QtWidgets.QPushButton("Set Parent") confirm_button.clicked.connect(self._set_parent) button_layout.addWidget(cancel_button) button_layout.addWidget(confirm_button) # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # def _populate_field(self): inst = component_utils.get_component_instance(self.metanode) self.parent_field.setText(inst.parent) del inst # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # def _launch_parent_list(self): widget = parent_list.ChooseParentList(self) pos = QtGui.QCursor.pos() widget.move(pos.x() + 10, pos.y() + 10) widget.exec_() # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # def _set_parent(self): inst = component_utils.get_component_instance(self.metanode) inst.parent = self.parent_field.text() del inst self.close()