eric6/Preferences/ConfigurationPages/ConfigurationPageBase.py

branch
Variables Viewer
changeset 7012
cc3f83d1a605
parent 6942
2602857055c5
child 7229
53054eb5b15a
--- a/eric6/Preferences/ConfigurationPages/ConfigurationPageBase.py	Fri May 03 23:01:00 2019 +0200
+++ b/eric6/Preferences/ConfigurationPages/ConfigurationPageBase.py	Mon May 13 22:29:15 2019 +0200
@@ -9,7 +9,7 @@
 
 from __future__ import unicode_literals
 
-from PyQt5.QtCore import pyqtSlot
+from PyQt5.QtCore import pyqtSlot, pyqtSignal
 from PyQt5.QtGui import QIcon, QPixmap, QColor
 from PyQt5.QtWidgets import QWidget, QColorDialog, QFontDialog
 
@@ -17,7 +17,11 @@
 class ConfigurationPageBase(QWidget):
     """
     Class implementing the base class for all configuration pages.
+    
+    @signal colourChanged(str, QColor) To inform about a new colour selection
     """
+    colourChanged = pyqtSignal(str, QColor)
+    
     def __init__(self):
         """
         Constructor
@@ -68,6 +72,7 @@
         button.setProperty("hasAlpha", hasAlpha)
         button.clicked.connect(lambda: self.__selectColourSlot(button))
         self.__coloursDict[colourKey] = [colour, byName]
+        self.colourChanged.emit(colourKey, colour)
         
     @pyqtSlot()
     def __selectColourSlot(self, button):
@@ -80,20 +85,26 @@
         colorKey = button.property("colorKey")
         hasAlpha = button.property("hasAlpha")
         
+        colDlg = QColorDialog(self)
         if hasAlpha:
-            colour = QColorDialog.getColor(
-                self.__coloursDict[colorKey][0], self, "",
-                QColorDialog.ShowAlphaChannel)
-        else:
-            colour = QColorDialog.getColor(self.__coloursDict[colorKey][0],
-                                           self)
-        if colour.isValid():
+            colDlg.setOptions(QColorDialog.ShowAlphaChannel)
+        # Set current colour last to avoid conflicts with alpha channel
+        colDlg.setCurrentColor(self.__coloursDict[colorKey][0])
+        colDlg.currentColorChanged.connect(
+            lambda col: self.colourChanged.emit(colorKey, col))
+        colDlg.exec_()
+        
+        if colDlg.result() == colDlg.Accepted:
+            colour = colDlg.selectedColor()
             size = button.iconSize()
             pm = QPixmap(size.width(), size.height())
             pm.fill(colour)
             button.setIcon(QIcon(pm))
             self.__coloursDict[colorKey][0] = colour
         
+        # Update colour selection
+        self.colourChanged.emit(colorKey, self.__coloursDict[colorKey][0])
+        
     def saveColours(self, prefMethod):
         """
         Public method to save the colour selections.
@@ -129,4 +140,4 @@
                     "{0} {1}".format(font.family(), font.pointSize()))
         else:
             font = fontVar
-        return font
+        return font  # __IGNORE_WARNING_M834__

eric ide

mercurial