eric6/Preferences/ConfigurationPages/ConfigurationPageBase.py

branch
Variables Viewer
changeset 7012
cc3f83d1a605
parent 6942
2602857055c5
child 7229
53054eb5b15a
equal deleted inserted replaced
6995:ee314cf3b1c9 7012:cc3f83d1a605
7 Module implementing the base class for all configuration pages. 7 Module implementing the base class for all configuration pages.
8 """ 8 """
9 9
10 from __future__ import unicode_literals 10 from __future__ import unicode_literals
11 11
12 from PyQt5.QtCore import pyqtSlot 12 from PyQt5.QtCore import pyqtSlot, pyqtSignal
13 from PyQt5.QtGui import QIcon, QPixmap, QColor 13 from PyQt5.QtGui import QIcon, QPixmap, QColor
14 from PyQt5.QtWidgets import QWidget, QColorDialog, QFontDialog 14 from PyQt5.QtWidgets import QWidget, QColorDialog, QFontDialog
15 15
16 16
17 class ConfigurationPageBase(QWidget): 17 class ConfigurationPageBase(QWidget):
18 """ 18 """
19 Class implementing the base class for all configuration pages. 19 Class implementing the base class for all configuration pages.
20
21 @signal colourChanged(str, QColor) To inform about a new colour selection
20 """ 22 """
23 colourChanged = pyqtSignal(str, QColor)
24
21 def __init__(self): 25 def __init__(self):
22 """ 26 """
23 Constructor 27 Constructor
24 """ 28 """
25 super(ConfigurationPageBase, self).__init__() 29 super(ConfigurationPageBase, self).__init__()
66 button.setIcon(QIcon(pm)) 70 button.setIcon(QIcon(pm))
67 button.setProperty("colorKey", colourKey) 71 button.setProperty("colorKey", colourKey)
68 button.setProperty("hasAlpha", hasAlpha) 72 button.setProperty("hasAlpha", hasAlpha)
69 button.clicked.connect(lambda: self.__selectColourSlot(button)) 73 button.clicked.connect(lambda: self.__selectColourSlot(button))
70 self.__coloursDict[colourKey] = [colour, byName] 74 self.__coloursDict[colourKey] = [colour, byName]
75 self.colourChanged.emit(colourKey, colour)
71 76
72 @pyqtSlot() 77 @pyqtSlot()
73 def __selectColourSlot(self, button): 78 def __selectColourSlot(self, button):
74 """ 79 """
75 Private slot to select a color. 80 Private slot to select a color.
78 @type QPushButton 83 @type QPushButton
79 """ 84 """
80 colorKey = button.property("colorKey") 85 colorKey = button.property("colorKey")
81 hasAlpha = button.property("hasAlpha") 86 hasAlpha = button.property("hasAlpha")
82 87
88 colDlg = QColorDialog(self)
83 if hasAlpha: 89 if hasAlpha:
84 colour = QColorDialog.getColor( 90 colDlg.setOptions(QColorDialog.ShowAlphaChannel)
85 self.__coloursDict[colorKey][0], self, "", 91 # Set current colour last to avoid conflicts with alpha channel
86 QColorDialog.ShowAlphaChannel) 92 colDlg.setCurrentColor(self.__coloursDict[colorKey][0])
87 else: 93 colDlg.currentColorChanged.connect(
88 colour = QColorDialog.getColor(self.__coloursDict[colorKey][0], 94 lambda col: self.colourChanged.emit(colorKey, col))
89 self) 95 colDlg.exec_()
90 if colour.isValid(): 96
97 if colDlg.result() == colDlg.Accepted:
98 colour = colDlg.selectedColor()
91 size = button.iconSize() 99 size = button.iconSize()
92 pm = QPixmap(size.width(), size.height()) 100 pm = QPixmap(size.width(), size.height())
93 pm.fill(colour) 101 pm.fill(colour)
94 button.setIcon(QIcon(pm)) 102 button.setIcon(QIcon(pm))
95 self.__coloursDict[colorKey][0] = colour 103 self.__coloursDict[colorKey][0] = colour
104
105 # Update colour selection
106 self.colourChanged.emit(colorKey, self.__coloursDict[colorKey][0])
96 107
97 def saveColours(self, prefMethod): 108 def saveColours(self, prefMethod):
98 """ 109 """
99 Public method to save the colour selections. 110 Public method to save the colour selections.
100 111
127 if showFontInfo: 138 if showFontInfo:
128 fontSample.setText( 139 fontSample.setText(
129 "{0} {1}".format(font.family(), font.pointSize())) 140 "{0} {1}".format(font.family(), font.pointSize()))
130 else: 141 else:
131 font = fontVar 142 font = fontVar
132 return font 143 return font # __IGNORE_WARNING_M834__

eric ide

mercurial