def __init__(self, parent=None, color=(128, 128, 128)): QtGui.QPushButton.__init__(self, parent) self.setColor(color) self.colorDialog = QtGui.QColorDialog() self.colorDialog.setOption(QtGui.QColorDialog.ShowAlphaChannel, True) self.colorDialog.setOption(QtGui.QColorDialog.DontUseNativeDialog, True) self.colorDialog.currentColorChanged.connect(self.dialogColorChanged) self.colorDialog.rejected.connect(self.colorRejected) self.colorDialog.colorSelected.connect(self.colorSelected) #QtCore.QObject.connect(self.colorDialog, QtCore.SIGNAL('currentColorChanged(const QColor&)'), self.currentColorChanged) #QtCore.QObject.connect(self.colorDialog, QtCore.SIGNAL('rejected()'), self.currentColorRejected) self.clicked.connect(self.selectColor) self.setMinimumHeight(15) self.setMinimumWidth(15)
def __init__(self, *args, **kargs): """ Create a new GradientEditorItem. All arguments are passed to :func:`TickSliderItem.__init__ <pyqtgraph.TickSliderItem.__init__>` =============== ================================================================================= **Arguments:** orientation Set the orientation of the gradient. Options are: 'left', 'right' 'top', and 'bottom'. allowAdd Default is True. Specifies whether ticks can be added to the item. tickPen Default is white. Specifies the color of the outline of the ticks. Can be any of the valid arguments for :func:`mkPen <pyqtgraph.mkPen>` =============== ================================================================================= """ self.currentTick = None self.currentTickColor = None self.rectSize = 15 self.gradRect = QtGui.QGraphicsRectItem( QtCore.QRectF(0, self.rectSize, 100, self.rectSize)) self.backgroundRect = QtGui.QGraphicsRectItem( QtCore.QRectF(0, -self.rectSize, 100, self.rectSize)) self.backgroundRect.setBrush(QtGui.QBrush(QtCore.Qt.DiagCrossPattern)) self.colorMode = 'rgb' TickSliderItem.__init__(self, *args, **kargs) self.colorDialog = QtGui.QColorDialog() self.colorDialog.setOption(QtGui.QColorDialog.ShowAlphaChannel, True) self.colorDialog.setOption(QtGui.QColorDialog.DontUseNativeDialog, True) self.colorDialog.currentColorChanged.connect(self.currentColorChanged) self.colorDialog.rejected.connect(self.currentColorRejected) self.colorDialog.accepted.connect(self.currentColorAccepted) self.backgroundRect.setParentItem(self) self.gradRect.setParentItem(self) self.setMaxDim(self.rectSize + self.tickSize) self.rgbAction = QtGui.QAction('RGB', self) self.rgbAction.setCheckable(True) self.rgbAction.triggered.connect(lambda: self.setColorMode('rgb')) self.hsvAction = QtGui.QAction('HSV', self) self.hsvAction.setCheckable(True) self.hsvAction.triggered.connect(lambda: self.setColorMode('hsv')) # Because v0.10.0 ColorMap does not support HSV mode self.hsvAction.setEnabled(False) self.menu = QtGui.QMenu() ## build context menu of gradients l = self.length self.length = 100 # global Gradients if 'gradients' in kargs: if kargs['gradients'] is not None: self.gradients = kargs['gradients'] else: self.gradients = customGradients else: self.gradients = customGradients for g in self.gradients: px = QtGui.QPixmap(100, 15) p = QtGui.QPainter(px) self.restoreState(self.gradients[g]) grad = self.getGradient() brush = QtGui.QBrush(grad) p.fillRect(QtCore.QRect(0, 0, 100, 15), brush) p.end() label = QtGui.QLabel() label.setPixmap(px) label.setContentsMargins(1, 1, 1, 1) labelName = QtGui.QLabel(g) hbox = QtGui.QHBoxLayout() hbox.addWidget(labelName) hbox.addWidget(label) widget = QtGui.QWidget() widget.setLayout(hbox) act = QtGui.QWidgetAction(self) act.setDefaultWidget(widget) act.triggered.connect(self.contextMenuClicked) act.name = g self.menu.addAction(act) self.length = l self.menu.addSeparator() self.menu.addAction(self.rgbAction) self.menu.addAction(self.hsvAction) for t in list(self.ticks.keys()): self.removeTick(t) self.addTick(0, QtGui.QColor(0, 0, 0), True) self.addTick(1, QtGui.QColor(255, 0, 0), True) self.setColorMode('rgb') self.updateGradient()