# -*- coding: utf-8 -*- """ :author: Jeremy Ernst :description: This module contains the class for creating and displaying the load template interface. """ import artv2.utilities.interface_utilities as interface_utils from artv2.third_party.Qt import QtWidgets import artv2.tools.system.logger.output_logger as logger import artv2.utilities.general_utilities as utils import artv2.components.base_components.template as template import pymel.core as pm # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # class LoadTemplateUI(interface_utils.ARTv2Window): """ This class creates the Load Template interface for loading a template from disk. The interface allows the user to select components to load, as well as what information to load (positions, settings, overrides) and that information is then passed onto the template class for processing. This is invoked from the RigBuilderUI toolbar. :param path: the path on disk of a template file. :param parent: the instance of the RigBuilderUI this widget will be parented to .. figure:: /images/loadTemplateUI.png :width: 382px :align: center :height: 304px :figclass: align-center """ SETTINGS_NAME = "LoadTemplateWIN" WINDOW_NAME = "artv2_load_template_window" # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # def __init__(self, path, parent=None): super(LoadTemplateUI, self).__init__(380, 270, "Load Template", parent) self.path = path self.parent_inst = parent self.logger = logger.OutputLogger(self.__class__.__name__) self._build_interface() # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # def _build_interface(self): main_widget = QtWidgets.QWidget() main_layout = QtWidgets.QHBoxLayout(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.setMinimumWidth(interface_utils.scale_by_dpi(170)) self.component_list.setMaximumWidth(interface_utils.scale_by_dpi(170)) main_layout.addWidget(self.component_list) right_layout = QtWidgets.QVBoxLayout() main_layout.addLayout(right_layout) self.settings_checkbox = QtWidgets.QCheckBox("Load Settings") self.settings_checkbox.setToolTip("Load settings for the selected components.") self.settings_checkbox.setChecked(True) self.positions_checkbox = QtWidgets.QCheckBox("Load Positions") self.positions_checkbox.setToolTip("Load positions for the selected components.") self.positions_checkbox.setChecked(True) self.overrides_checkbox = QtWidgets.QCheckBox("Load Joint Name Overrides") self.overrides_checkbox.setToolTip("Load joint name overrides for the selected components.") self.overrides_checkbox.setChecked(True) self.aim_checkbox = QtWidgets.QCheckBox("Turn on Aim Mode") self.aim_checkbox.setChecked(False) self.aim_checkbox.setToolTip("When a component is loaded, should aim mode automatically be turned on?") right_layout.addWidget(self.settings_checkbox) right_layout.addWidget(self.positions_checkbox) right_layout.addWidget(self.overrides_checkbox) right_layout.addWidget(self.aim_checkbox) spacer = QtWidgets.QSpacerItem(0, 0, QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Expanding) right_layout.addSpacerItem(spacer) button = QtWidgets.QPushButton("Load Selected") button.clicked.connect(self._load) right_layout.addWidget(button) self._populate_list() # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # def _populate_list(self): data = utils.load_from_file(self.path) for key in data.keys(): self.component_list.addItem(key) # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # def _load(self): self.logger.interface("{0}._load: Loading template.".format(self.__class__.__name__)) components = [] selected_items = self.component_list.selectedItems() for each in selected_items: components.append(each.text()) template_instance = template.Template(self.path) template_instance.load_settings = self.settings_checkbox.isChecked() template_instance.load_positions = self.positions_checkbox.isChecked() template_instance.load_overrides = self.overrides_checkbox.isChecked() aim = self.aim_checkbox.isChecked() template_instance.load_template(components, aim=aim) self.close() self.parent_inst.update_list() # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # def show_window(parent, path): """ Shows the LoadTemplateUI instance """ if pm.window("artv2_load_template_window", exists=True): pm.deleteUI("artv2_load_template_window") gui = LoadTemplateUI(path, parent) gui.show()