class BaseColorDialog(BaseDialog, object): def_title = 'Select Color' maya_colors = [(.467, .467, .467), (.000, .000, .000), (.247, .247, .247), (.498, .498, .498), (0.608, 0, 0.157), (0, 0.016, 0.373), (0, 0, 1), (0, 0.275, 0.094), (0.145, 0, 0.263), (0.78, 0, 0.78), (0.537, 0.278, 0.2), (0.243, 0.133, 0.122), (0.6, 0.145, 0), (1, 0, 0), (0, 1, 0), (0, 0.255, 0.6), (1, 1, 1), (1, 1, 0), (0.388, 0.863, 1), (0.263, 1, 0.635), (1, 0.686, 0.686), (0.89, 0.675, 0.475), (1, 1, 0.384), (0, 0.6, 0.325), (0.627, 0.412, 0.188), (0.62, 0.627, 0.188), (0.408, 0.627, 0.188), (0.188, 0.627, 0.365), (0.188, 0.627, 0.627), (0.188, 0.404, 0.627), (0.435, 0.188, 0.627), (0.627, 0.188, 0.404)] def __init__(self, name='MayaColorDialog', parent=None, **kwargs): parent = parent or dcc.get_main_window() super(BaseColorDialog, self).__init__(name=name, parent=parent, **kwargs) self._color = None def get_color(self): return self._color color = property(get_color) def ui(self): self.color_buttons = list() super(BaseColorDialog, self).ui() grid_layout = layouts.GridLayout() grid_layout.setAlignment(Qt.AlignTop) self.main_layout.addLayout(grid_layout) color_index = 0 for i in range(0, 4): for j in range(0, 8): color_btn = QPushButton() color_btn.setMinimumHeight(35) color_btn.setMinimumWidth(35) self.color_buttons.append(color_btn) color_btn.setStyleSheet( 'background-color:rgb(%s,%s,%s);' % (self.maya_colors[color_index][0] * 255, self.maya_colors[color_index][1] * 255, self.maya_colors[color_index][2] * 255)) grid_layout.addWidget(color_btn, i, j) color_index += 1 selected_color_layout = layouts.HorizontalLayout() self.main_layout.addLayout(selected_color_layout) self.color_slider = QSlider(Qt.Horizontal) self.color_slider.setMinimum(0) self.color_slider.setMaximum(31) self.color_slider.setValue(2) self.color_slider.setStyleSheet( "QSlider::groove:horizontal {border: 1px solid #999999;height: 25px; /* the groove expands " "to the size of the slider by default. by giving it a height, it has a fixed size */background: " "qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #B1B1B1, stop:1 #c4c4c4);margin: 2px 0;}" "QSlider::handle:horizontal {background: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 #b4b4b4," " stop:1 #8f8f8f);border: 1px solid #5c5c5c;width: 10px;margin: -2px 0; /* handle is placed by " "default on the contents rect of the groove. Expand outside the groove */border-radius: 1px;}" ) selected_color_layout.addWidget(self.color_slider) color_label_layout = layouts.HorizontalLayout(margins=(10, 10, 10, 10)) self.main_layout.addLayout(color_label_layout) self.color_lbl = QLabel() self.color_lbl.setStyleSheet( "border: 1px solid black; background-color:rgb(0, 0, 0);") self.color_lbl.setMinimumWidth(45) self.color_lbl.setMaximumWidth(80) self.color_lbl.setMinimumHeight(80) self.color_lbl.setAlignment(Qt.AlignCenter) color_label_layout.addWidget(self.color_lbl) bottom_layout = layouts.HorizontalLayout() bottom_layout.setAlignment(Qt.AlignRight) self.main_layout.addLayout(bottom_layout) self.ok_btn = QPushButton('Ok') self.cancel_btn = QPushButton('Cancel') bottom_layout.addLayout(dividers.DividerLayout()) bottom_layout.addWidget(self.ok_btn) bottom_layout.addWidget(self.cancel_btn) def setup_signals(self): for i, btn in enumerate(self.color_buttons): btn.clicked.connect(partial(self._on_set_color, i)) self.color_slider.valueChanged.connect(self._on_set_color) self.ok_btn.clicked.connect(self._on_ok_btn) self.cancel_btn.clicked.connect(self._on_cancel_btn) def _on_set_color(self, color_index): self.color_lbl.setStyleSheet('background-color:rgb(%s,%s,%s);' % (self.maya_colors[color_index][0] * 255, self.maya_colors[color_index][1] * 255, self.maya_colors[color_index][2] * 255)) self.color_slider.setValue(color_index) def _on_set_slider(self, color_index): self._set_color(color_index=color_index) def _on_ok_btn(self): self._color = self.color_slider.value() self.close() def _on_cancel_btn(self): self._color = None self.close()
class UIOpenCvBaseNode(UINodeBase): def __init__(self, raw_node): super(UIOpenCvBaseNode, self).__init__(raw_node) self.imagePin = self._rawNode.getPinByName("img") if not self.imagePin: for pin in self._rawNode.outputs.values(): if pin.dataType == "ImagePin": self.imagePin = pin break if self.imagePin: self.actionViewImage = self._menu.addAction("ViewImage") self.actionViewImage.triggered.connect(self.viewImage) self.actionViewImage.setData( NodeActionButtonInfo( os.path.dirname(__file__) + "/resources/ojo.svg", ViewImageNodeActionButton)) self.actionRefreshImage = self._menu.addAction( "RefreshCurrentNode") self.actionRefreshImage.triggered.connect(self.refreshImage) self.actionRefreshImage.setData( NodeActionButtonInfo( os.path.dirname(__file__) + "/resources/reload.svg", NodeActionButtonBase)) self.displayImage = False self.resizable = True self.Imagelabel = QLabel("noImage") self.pixmap = QtGui.QPixmap() self.addWidget(self.Imagelabel) self.Imagelabel.setVisible(False) self.updateSize() self._rawNode.computed.connect(self.updateImage) @property def collapsed(self): return self._collapsed @collapsed.setter def collapsed(self, bCollapsed): if bCollapsed != self._collapsed: self._collapsed = bCollapsed self.aboutToCollapse(self._collapsed) for i in range(0, self.inputsLayout.count()): inp = self.inputsLayout.itemAt(i) inp.setVisible(not bCollapsed) for o in range(0, self.outputsLayout.count()): out = self.outputsLayout.itemAt(o) out.setVisible(not bCollapsed) for cust in range(0, self.customLayout.count()): out = self.customLayout.itemAt(cust) out.setVisible(not bCollapsed) if not self.displayImage: self.Imagelabel.setVisible(False) self.updateNodeShape() def updateImage(self, *args, **kwargs): if self.displayImage and not self.collapsed: if self.imagePin: img = self.imagePin.getData() self.setNumpyArray(img.image) def refreshImage(self): if self.imagePin: self._rawNode.processNode() if self.displayImage and not self.collapsed: if self.imagePin: img = self.imagePin.getData() self.setNumpyArray(img.image) self.Imagelabel.setVisible(True) else: self.Imagelabel.setVisible(False) def viewImage(self): self.displayImage = not self.displayImage self.refreshImage() self.updateNodeShape() self.updateSize() def setNumpyArray(self, image): if image.__class__.__name__ == "UMat": image = cv2.UMat.get(image) image = toQImage(image) self.pixmap = QtGui.QPixmap.fromImage(image, QtCore.Qt.ThresholdAlphaDither) self.updateSize() def paint(self, painter, option, widget): self.updateSize() super(UIOpenCvBaseNode, self).paint(painter, option, widget) def updateSize(self): if not self.pixmap.isNull(): scaledPixmap = self.pixmap.scaledToWidth( self.customLayout.geometry().width()) self.Imagelabel.setMaximumWidth( self.customLayout.geometry().width()) self.Imagelabel.setPixmap(scaledPixmap) def updateNodeShape(self): super(UIOpenCvBaseNode, self).updateNodeShape() self.updateSize() self.update()