Exemple #1
0
 def ChangeCol():
     qcd = QColorDialog(dialog)
     qcd.setWindowTitle('颜色选择')
     qcd.setCurrentColor(self.buttonColorVal)
     if qcd.exec() == QDialog.Accepted:
         self.buttonColorVal = qcd.selectedColor()
         self.buttonColor.setStyleSheet(
             'QWidget {background-color:%s}' %
             self.buttonColorVal.name())
Exemple #2
0
def getColor(context, initial, title):
    if not isLinux:
        return QColorDialog.getColor(initial=initial, title=title)
    dlg = QColorDialog(initial, context)
    dlg.setWindowTitle(title)
    dlg.setOption(QColorDialog.DontUseNativeDialog)
    color = QColor()
    if dlg.exec() == QDialog.Accepted:
        color = dlg.currentColor()
    return color
    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(),
                )
Exemple #4
0
 def selectDrawColor(self):
     self.setBScale(False)
     colorDialog = QColorDialog(self)
     colorDialog.setWindowTitle('Select Draw Color: ')
     colorDialog.setCurrentColor(Qt.red)
     if colorDialog.exec_() == QColorDialog.Accepted:
         drawColor = colorDialog.selectedColor()
         self.canvas.setDrawColor(drawColor)
         red = drawColor.red()
         green = drawColor.green()
         blue = drawColor.blue()
         self.cfg.set('file', 'drawColorRed', str(red))
         self.cfg.set('file', 'drawColorGreen', str(green))
         self.cfg.set('file', 'drawColorBlue', str(blue))
         self.cfg.write(open('SWQT.ini', 'w'))
Exemple #5
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
Exemple #6
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
Exemple #7
0
    def on_pressed(self):
        """Button pressed event handler

        Shows color dialog and sets the chosen color.

        """

        dlg = QColorDialog(self.parent())

        dlg.setCurrentColor(self.color)
        dlg.setWindowTitle(self.title)

        dlg.setWindowFlags(Qt.Tool | Qt.FramelessWindowHint)
        dlg.setWindowModality(Qt.ApplicationModal)
        dlg.setOptions(QColorDialog.DontUseNativeDialog)

        p = self.mapFromGlobal(QCursor.pos())
        p.setX(p.x() + (self.rect().width() / 2))
        p.setY(p.y() + (self.rect().height() / 2))
        dlg.move(self.mapToGlobal(p))

        if dlg.exec_():
            self.color = dlg.currentColor()
            self.colorChanged.emit()
Exemple #8
0
 def handle_select_color_btn(self):
     dialog = QColorDialog(self)
     dialog.setWindowTitle("Select Text Color")
     dialog.colorSelected.connect(
         lambda c: self.set_watermark_color(color=c))
     dialog.show()
Exemple #9
0
class ThemeDialog(QDialog, Ui_dialogTheme):
    def __init__(self, parent=None):
        QDialog.__init__(self, parent)
        self.fenetre = parent
        self.setupUi(self)
        self.verticalLayout_5.setContentsMargins(0, 0, 0, 0)
        icon = QIcon()
        icon.addPixmap(QPixmap(ICON_APP), QIcon.Normal, QIcon.Off)
        self.setWindowIcon(icon)
        self.theme = parent.theme
        self.langage = ""
        self.mot = ""
        self.codeCouleur = ""
        self.colorDialog = QColorDialog(self)
        self.colorDialog.setWindowTitle("Selectionnez une couleur")
        self.colorDialog.setWindowIcon(icon)

        #Initialisation de certains éléments
        #Chargement des themes prédéefinis
        fichier_themes_predefinis = AppFile(THEME_PREDEFINIS)
        self.themes = fichier_themes_predefinis.lire()
        if self.themes is not None:
            for nom, fichier in self.themes:
                self.comboBoxThemes.addItem(nom)

        self.couleur.setEnabled(False)
        if self.theme.themeGeneral.environnement in ("sombre", "noir"):
            self.comboBoxGeneral.setCurrentIndex(0)
        else:
            self.comboBoxGeneral.setCurrentIndex(1)
        #Ajout des langages
        for lang in LANGUAGES.keys():
            self.listLangages.addItem(lang.upper())
        self.rafraichirMots()
        #Slots
        self.comboBoxThemes.currentTextChanged.connect(
            self.on_comboBoxThemes_textChanged)
        self.listLangages.itemClicked.connect(self.on_langageClicked)
        self.listMots.itemClicked.connect(self.on_motClicked)
        self.pushButtonChangerCouleur.clicked.connect(self.on_changerCouleur)
        self.colorDialog.currentColorChanged.connect(self.on_colorChanged)
        self.checkBoxItalique.clicked.connect(self.on_checkBoxFont_clicked)
        self.checkBoxGras.clicked.connect(self.on_checkBoxFont_clicked)
        self.comboBoxGeneral.currentTextChanged.connect(
            self.on_comboBoxGeneral_textChanged)
        self.show()

    def on_comboBoxThemes_textChanged(self, text):
        #Recherche du fichier theme
        nomFichierNouveau = ""
        for nom, fichier in self.themes:
            if nom == text:
                nomFichierNouveau = fichier
        fichierNouveau = VPThemeFile(appFolder + "/themes/" +
                                     nomFichierNouveau)
        theme = fichierNouveau.lire()
        if theme is not None and type(theme) == VPTheme:
            self.theme = theme
            self.rafraichirTabs()

    def on_comboBoxGeneral_textChanged(self, text):
        """Lorsqu'on change le thème général"""
        if text.lower().find("sombre") >= 0 or text.lower().find("noir") >= 0:
            self.theme.setStylesWidgets("sombre")
        else:
            self.theme.setStylesWidgets("clair")
        message = "Ce nouveau thème sera pris en compte au prochain démarrage de l'application"
        messageBox = QMessageBox.information(self, "Message", message,
                                             QMessageBox.Ok)

    def rafraichirMots(self):
        """Actualiser la partie des mots"""
        langagesSelectionnes = self.listLangages.selectedItems()
        if len(langagesSelectionnes) > 0:
            langage = langagesSelectionnes[0].text().upper()
        else:
            langage = self.listLangages.item(0).text().upper()
            self.listLangages.setCurrentRow(0)
        #On efface la liste des mots
        self.listMots.clear()
        for mot in LANGUAGES[langage]["coloration"]:
            self.listMots.addItem(mot)
        self.langage = langage
        self.listMots.setCurrentRow(0)
        self.rafraichirCouleurs()

    def on_langageClicked(self, item):
        """Lorsqu'on change de langage"""
        self.rafraichirMots()

    def rafraichirCouleurs(self):
        """Mettre à jour la zone couleurs"""
        motsSelectionnes = self.listMots.selectedItems()
        if len(motsSelectionnes) > 0:
            mot = motsSelectionnes[0].text()
        else:
            mot = None
        self.mot = mot
        if mot is not None:
            if self.langage != "":
                self.codeCouleur = self.theme.coloration[
                    self.langage][mot]["couleur"]
                self.couleur.setStyleSheet("min-height:45px;background:" +
                                           self.codeCouleur + ";")
                self.checkBoxItalique.setChecked(
                    self.theme.coloration[self.langage][mot]["italique"])
                self.checkBoxGras.setChecked(
                    self.theme.coloration[self.langage][mot]["gras"])
                self.colorDialog.setCurrentColor(QColor(self.codeCouleur))

    def on_motClicked(self):
        """Lorsqu'on change de mot"""
        self.rafraichirCouleurs()

    def on_changerCouleur(self):
        """Lorsqu'on clique sur le bouton changer couleur"""
        self.colorDialog.show()

    def on_colorChanged(self, color):
        """Lorsqu'on change la couleur dans QColorDialog"""
        self.couleur.setStyleSheet("min-height:45px;background:" +
                                   color.name() + ";")
        self.theme.coloration[self.langage][self.mot]["couleur"] = color.name()
        self.rafraichirTabs()

    def on_checkBoxFont_clicked(self):
        """Quand on clique sur un checkbox dans la zone font"""
        self.theme.coloration[self.langage][
            self.mot]["italique"] = self.checkBoxItalique.checkState()
        self.theme.coloration[self.langage][
            self.mot]["gras"] = self.checkBoxGras.checkState()
        self.rafraichirTabs()

    def rafraichirTabs(self):
        """Mise à jour des TabText"""
        tabs = self.fenetre.tabs
        for tabText in tabs.tabtexts:
            tabText.theme = self.theme
            tabText.coloration()

    def closeEvent(self, event):
        """Quand on ferme la boîte"""
        fichier_theme.ecrire(self.theme)
        event.accept()