# -*- coding: utf-8 -*- """ :author: Jeremy Ernst :description: This module contains a class that is a menu widget that attaches to the "Add Component" button in the RigBuilderUI class. This menu widget searches for component classes, and adds them to the menu. """ from functools import partial from artv2.third_party.Qt import QtWidgets, QtCore, QtGui import artv2.tools.rigging.rig_builder.add_component_widget as add_component import artv2.utilities.component_utilities as component_utils import artv2.tools.system.logger.output_logger as logger class AvailableComponentsWidget(QtWidgets.QMenu): """ This class is a custom QMenu widget that attaches the to "Add Component" button in the RigBuilderUI instance. It is populated with available component classes as found in the artv2.components directory. :param parent: the parent widget of this class, which will be a RigBuilderUI instance. .. figure:: /images/available_components_widget.png :width: 197px :align: center :height: 334px :figclass: align-center The area in red is the AvailableComponentsWidget class. It is instantiated from the RigBuilderUI and attached to the QPushButton at the top. """ component_added = QtCore.Signal() # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # def __init__(self, parent=None): super(AvailableComponentsWidget, self).__init__(parent) self.logger = logger.OutputLogger(self.__class__.__name__) self.setMinimumWidth(200) self.setMaximumWidth(200) self._build_menu() # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # def _build_menu(self): components = component_utils.get_available_components() categories = {} for each in components: data = components.get(each) if data[0] not in categories.keys(): categories[data[0]] = [each] else: existing_data = list(categories.get(data[0])) existing_data.append(each) categories[data[0]] = existing_data for category in categories: header = QtWidgets.QAction(category, self) header.setDisabled(True) self.addAction(header) self.addSeparator() category_data = categories.get(category) for each in category_data: component_data = components.get(each) component = QtWidgets.QAction(" {0}".format(each), self) component.setData(component_data) component.triggered.connect(partial(self._add_component, component)) self.addAction(component) # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # def _add_component(self, action): data = action.data() self.logger.interface("{0}._add_component: Adding component {1}".format(self.__class__.__name__, data[2].__name__)) widget = add_component.AddComponentWidget(data, self, self.parent()) pos = QtGui.QCursor.pos() widget.move(pos.x() + 10, pos.y() + 10) widget.show()