ColorString/ColorSelectionDialog.py

changeset 1
e1f013dc03bb
child 11
3b7ec819a55d
equal deleted inserted replaced
0:78cb5b240094 1:e1f013dc03bb
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2014 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog to select a color by name.
8 """
9
10 from PyQt4.QtGui import QDialog, QColor, QPixmap, QIcon
11
12 from .Ui_ColorSelectionDialog import Ui_ColorSelectionDialog
13
14
15 class ColorSelectionDialog(QDialog, Ui_ColorSelectionDialog):
16 """
17 Class implementing a dialog to select a color by name.
18 """
19 def __init__(self, selectedName="", parent=None):
20 """
21 Constructor
22
23 @param selectedName name of the color to be selected initially
24 (string)
25 @param parent reference to the parent widget (QWidget)
26 """
27 super().__init__(parent)
28 self.setupUi(self)
29
30 for colorName in QColor.colorNames():
31 px = QPixmap(22, 22) # icon size 22x22 pixels
32 px.fill(QColor(colorName))
33 self.colorComboBox.addItem(QIcon(px), colorName)
34 if selectedName:
35 self.colorComboBox.setCurrentIndex(
36 self.colorComboBox.findText(selectedName))
37
38 msh = self.minimumSizeHint()
39 self.resize(max(self.size().width(), msh.width()), msh.height())
40
41 def getColor(self):
42 """
43 Public method to retrieve the selected color name.
44
45 @return color name (string)
46 """
47 return self.colorComboBox.currentText()

eric ide

mercurial