ColorString/ColorSelectionDialog.py

Sat, 23 Dec 2023 18:04:29 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 23 Dec 2023 18:04:29 +0100
branch
eric7
changeset 63
4f8151cc9b84
parent 62
970b0bcbd88c
child 64
22103a23447a
permissions
-rw-r--r--

Corrected some code style issues and converted some source code documentation to the new style.

# -*- coding: utf-8 -*-

# Copyright (c) 2014 - 2024 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing a dialog to select a color by name.
"""

from PyQt6.QtGui import QColor, QIcon, QPixmap
from PyQt6.QtWidgets import QDialog

from .Ui_ColorSelectionDialog import Ui_ColorSelectionDialog


class ColorSelectionDialog(QDialog, Ui_ColorSelectionDialog):
    """
    Class implementing a dialog to select a color by name.
    """

    def __init__(self, selectedName="", parent=None):
        """
        Constructor

        @param selectedName name of the color to be selected initially
        @type str
        @param parent reference to the parent widget
        @type QWidget
        """
        super().__init__(parent)
        self.setupUi(self)

        for colorName in QColor.colorNames():
            px = QPixmap(22, 22)  # icon size 22x22 pixels
            px.fill(QColor(colorName))
            self.colorComboBox.addItem(QIcon(px), colorName)
        if selectedName:
            self.colorComboBox.setCurrentIndex(
                self.colorComboBox.findText(selectedName)
            )

        msh = self.minimumSizeHint()
        self.resize(max(self.size().width(), msh.width()), msh.height())

    def getColor(self):
        """
        Public method to retrieve the selected color name.

        @return color name
        @rtype str
        """
        return self.colorComboBox.currentText()

eric ide

mercurial