# -*- coding: utf-8 -*- """ :author: Jeremy Ernst :description: This module contains a class that creates an interface for selecting multiple components and resetting their settings or transforms or both. """ import artv2.utilities.interface_utilities as interface_utils import artv2.utilities.component_utilities as component_utils from artv2.third_party.Qt import QtWidgets, QtCore import artv2.tools.system.logger.output_logger as logger import pymel.core as pm # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # class GroupResetUI(interface_utils.ARTv2Window): """ This class creates a user interface for selecting components and resetting their settings and/or transforms. It is invoked from the RigBuilderUI toolbar. :param parent: the instance of the RigBuilderUI this widget will be parented to. .. figure:: /images/group_reset_ui.png :width: 198px :align: center :height: 429px :figclass: align-center """ SETTINGS_NAME = "GroupResetWIN" WINDOW_NAME = "artv2_group_reset_window" # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # def __init__(self, parent=None): super(GroupResetUI, self).__init__(200, 400, "Group Reset", parent) self.logger = logger.OutputLogger(self.__class__.__name__) self.parent_inst = parent self._build_interface() # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # def _build_interface(self): main_widget = QtWidgets.QWidget() main_layout = QtWidgets.QVBoxLayout(main_widget) self.setCentralWidget(main_widget) self.component_list = QtWidgets.QListWidget() self.component_list.setSortingEnabled(True) self.component_list.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection) self.component_list.setMinimumHeight(interface_utils.scale_by_dpi(240)) main_layout.addWidget(self.component_list) self._populate_list() self.settings_checkbox = QtWidgets.QCheckBox("Reset Settings") self.settings_checkbox.setChecked(False) main_layout.addWidget(self.settings_checkbox) self.transforms_checkbox = QtWidgets.QCheckBox("Reset Transformations") self.transforms_checkbox.setChecked(False) main_layout.addWidget(self.transforms_checkbox) spacer = QtWidgets.QSpacerItem(0, 0, QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Expanding) main_layout.addItem(spacer) button = QtWidgets.QPushButton("Reset") button.clicked.connect(self._reset) main_layout.addWidget(button) # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # def _populate_list(self): components = component_utils.get_all_component_names() for each in components.keys(): item = QtWidgets.QListWidgetItem() item.setData(QtCore.Qt.UserRole, components.get(each).nodeName()) item.setText(each) self.component_list.addItem(item) # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # def _reset(self): self.logger.interface("{0}._reset: Resetting selected components.".format(self.__class__.__name__)) selected = self.component_list.selectedItems() settings = self.settings_checkbox.isChecked() transforms = self.transforms_checkbox.isChecked() instances = [] for each in selected: data = each.data(QtCore.Qt.UserRole) inst = component_utils.get_component_instance(pm.PyNode(data)) instances.append(inst) if settings: inst.reset_settings() if transforms: if not inst.network_node.pinned.get(): inst.joint_mover.toggle_pin_component() if transforms: for instance in instances: instance.joint_mover.reset_movers("all") if instance.network_node.pinned.get(): instance.joint_mover.toggle_pin_component() del instance # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # def show_window(parent): """ Shows the GroupResetUI instance """ if pm.window("artv2_group_reset_window", exists=True): pm.deleteUI("artv2_group_reset_window") gui = GroupResetUI(parent) gui.show()