def on_bTest_clicked(self):
        """
        Private method to test the selected options.
        """
        if self.rColor.isChecked():
            if not self.eColor.currentText():
                QColorDialog.getColor()
            else:
                coStr = self.eColor.currentText()
                if coStr.startswith('#'):
                    coStr = "QColor('{0}')".format(coStr)
                else:
                    coStr = "QColor({0})".format(coStr)
                try:
                    exec('from PyQt5.QtCore import Qt;'
                         ' QColorDialog.getColor({0}, None, "{1}")'.format(
                             coStr, self.eTitle.text()))
                except:
                    E5MessageBox.critical(
                        self, self.tr("QColorDialog Wizard Error"),
                        self.tr(
                            """<p>The colour <b>{0}</b> is not valid.</p>""").
                        format(coStr))

        elif self.rRGBA.isChecked():
            QColorDialog.getColor(
                QColor(self.sRed.value(), self.sGreen.value(),
                       self.sBlue.value(), self.sAlpha.value()), None,
                self.eTitle.text(),
                QColorDialog.ColorDialogOptions(QColorDialog.ShowAlphaChannel))
예제 #2
0
    def getColorPolygonAndBrushStyle(
            initial_color: Union[QColor, Qt.GlobalColor, QGradient] = QColor(),
            initial_polygon: NodePolygon = NodePolygon.Circle,
            initial_brushstyle: Qt.BrushStyle = Qt.NoBrush,
            parent: Optional[QWidget] = None, title: str = '',
            options: Union[QColorDialog.ColorDialogOptions,
                           QColorDialog.ColorDialogOption] = QColorDialog.ColorDialogOptions()) \
            -> (QColor, NodePolygon):

        dlg = QColorDialog(parent)

        # Add buttons to select polygon
        polygons_group = QButtonGroup(parent)
        polygons_layout = QHBoxLayout(parent)
        for p in NodePolygon:
            if p == NodePolygon.Custom:
                continue

            button = QToolButton(parent)
            button.setCheckable(True)
            button.setText(p.name)
            button.setIcon(QIcon(nodePolygonToPixmap(p, button.iconSize())))

            if p == initial_polygon:
                button.setChecked(True)
            polygons_group.addButton(button)
            polygons_group.setId(button, p.value)
            polygons_layout.addWidget(button)
        dlg.layout().insertLayout(dlg.layout().count()-1, polygons_layout)

        # Add buttons to select brush style
        brushstyle_group = QButtonGroup(parent)
        brushstyle_layout = QHBoxLayout(parent)
        for p in NODE_BRUSH_STYLES:
            button = QToolButton(parent)
            button.setCheckable(True)
            button.setIcon(QIcon(nodeBrushStyleToPixmap(p, button.iconSize())))

            if p == initial_brushstyle:
                button.setChecked(True)
            brushstyle_group.addButton(button)
            brushstyle_group.setId(button, p)
            brushstyle_layout.addWidget(button)
        dlg.layout().insertLayout(dlg.layout().count()-1, brushstyle_layout)

        if title:
            dlg.setWindowTitle(title)
        dlg.setOptions(options)
        dlg.setCurrentColor(initial_color)
        dlg.exec_()
        return (dlg.selectedColor(),
                NodePolygon(polygons_group.checkedId()),
                brushstyle_group.checkedId(),
                )
예제 #3
0
def getColor(
    parent=None,
    title="",
    color=None,
    alpha=False,
):
    """Ask the user a color."""
    global _savedColor
    if color is None:
        color = _savedColor
    dlg = QColorDialog(color, parent)
    options = QColorDialog.ColorDialogOptions()
    if alpha:
        options |= QColorDialog.ShowAlphaChannel
    if not QSettings().value("native_dialogs/colordialog", True, bool):
        options |= QColorDialog.DontUseNativeDialog
    dlg.setOptions(options)
    dlg.setWindowTitle(title or app.caption(_("Select Color")))
    if dlg.exec_():
        _savedColor = dlg.selectedColor()
        return _savedColor