src/eric7/Preferences/ConfigurationPages/ConfigurationPageBase.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9473
3f23dbf37dbe
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
13 13
14 14
15 class ConfigurationPageBase(QWidget): 15 class ConfigurationPageBase(QWidget):
16 """ 16 """
17 Class implementing the base class for all configuration pages. 17 Class implementing the base class for all configuration pages.
18 18
19 @signal colourChanged(str, QColor) To inform about a new colour selection 19 @signal colourChanged(str, QColor) To inform about a new colour selection
20 """ 20 """
21
21 colourChanged = pyqtSignal(str, QColor) 22 colourChanged = pyqtSignal(str, QColor)
22 23
23 def __init__(self): 24 def __init__(self):
24 """ 25 """
25 Constructor 26 Constructor
26 """ 27 """
27 super().__init__() 28 super().__init__()
28 29
29 self.__coloursDict = {} 30 self.__coloursDict = {}
30 31
31 def polishPage(self): 32 def polishPage(self):
32 """ 33 """
33 Public slot to perform some polishing actions. 34 Public slot to perform some polishing actions.
34 """ 35 """
35 return 36 return
36 37
37 def saveState(self): 38 def saveState(self):
38 """ 39 """
39 Public method to save the current state of the widget. 40 Public method to save the current state of the widget.
40 """ 41 """
41 return 42 return
42 43
43 def setState(self, state): 44 def setState(self, state):
44 """ 45 """
45 Public method to set the state of the widget. 46 Public method to set the state of the widget.
46 47
47 @param state state data generated by saveState 48 @param state state data generated by saveState
48 """ 49 """
49 return 50 return
50 51
51 def initColour(self, colourKey, button, prefMethod, byName=False, 52 def initColour(self, colourKey, button, prefMethod, byName=False, hasAlpha=False):
52 hasAlpha=False):
53 """ 53 """
54 Public method to initialize a colour selection button. 54 Public method to initialize a colour selection button.
55 55
56 @param colourKey key of the colour resource (string) 56 @param colourKey key of the colour resource (string)
57 @param button reference to a button to show the colour on (QPushButton) 57 @param button reference to a button to show the colour on (QPushButton)
58 @param prefMethod preferences method to get the colour 58 @param prefMethod preferences method to get the colour
59 @param byName flag indicating to retrieve/save by colour name 59 @param byName flag indicating to retrieve/save by colour name
60 (boolean) 60 (boolean)
69 button.setProperty("colorKey", colourKey) 69 button.setProperty("colorKey", colourKey)
70 button.setProperty("hasAlpha", hasAlpha) 70 button.setProperty("hasAlpha", hasAlpha)
71 button.clicked.connect(lambda: self.__selectColourSlot(button)) 71 button.clicked.connect(lambda: self.__selectColourSlot(button))
72 self.__coloursDict[colourKey] = [colour, byName] 72 self.__coloursDict[colourKey] = [colour, byName]
73 self.colourChanged.emit(colourKey, colour) 73 self.colourChanged.emit(colourKey, colour)
74 74
75 @pyqtSlot() 75 @pyqtSlot()
76 def __selectColourSlot(self, button): 76 def __selectColourSlot(self, button):
77 """ 77 """
78 Private slot to select a color. 78 Private slot to select a color.
79 79
80 @param button reference to the button been pressed 80 @param button reference to the button been pressed
81 @type QPushButton 81 @type QPushButton
82 """ 82 """
83 colorKey = button.property("colorKey") 83 colorKey = button.property("colorKey")
84 hasAlpha = button.property("hasAlpha") 84 hasAlpha = button.property("hasAlpha")
85 85
86 colDlg = QColorDialog(self) 86 colDlg = QColorDialog(self)
87 if hasAlpha: 87 if hasAlpha:
88 colDlg.setOptions(QColorDialog.ColorDialogOption.ShowAlphaChannel) 88 colDlg.setOptions(QColorDialog.ColorDialogOption.ShowAlphaChannel)
89 # Set current color last to avoid conflicts with alpha channel 89 # Set current color last to avoid conflicts with alpha channel
90 colDlg.setCurrentColor(self.__coloursDict[colorKey][0]) 90 colDlg.setCurrentColor(self.__coloursDict[colorKey][0])
91 colDlg.currentColorChanged.connect( 91 colDlg.currentColorChanged.connect(
92 lambda col: self.colourChanged.emit(colorKey, col)) 92 lambda col: self.colourChanged.emit(colorKey, col)
93 )
93 colDlg.exec() 94 colDlg.exec()
94 95
95 if colDlg.result() == QDialog.DialogCode.Accepted: 96 if colDlg.result() == QDialog.DialogCode.Accepted:
96 colour = colDlg.selectedColor() 97 colour = colDlg.selectedColor()
97 size = button.iconSize() 98 size = button.iconSize()
98 pm = QPixmap(size.width(), size.height()) 99 pm = QPixmap(size.width(), size.height())
99 pm.fill(colour) 100 pm.fill(colour)
100 button.setIcon(QIcon(pm)) 101 button.setIcon(QIcon(pm))
101 self.__coloursDict[colorKey][0] = colour 102 self.__coloursDict[colorKey][0] = colour
102 103
103 # Update color selection 104 # Update color selection
104 self.colourChanged.emit(colorKey, self.__coloursDict[colorKey][0]) 105 self.colourChanged.emit(colorKey, self.__coloursDict[colorKey][0])
105 106
106 def saveColours(self, prefMethod): 107 def saveColours(self, prefMethod):
107 """ 108 """
108 Public method to save the colour selections. 109 Public method to save the colour selections.
109 110
110 @param prefMethod preferences method to set the colour 111 @param prefMethod preferences method to set the colour
111 """ 112 """
112 for key in self.__coloursDict: 113 for key in self.__coloursDict:
113 if self.__coloursDict[key][1]: 114 if self.__coloursDict[key][1]:
114 prefMethod(key, self.__coloursDict[key][0].name()) 115 prefMethod(key, self.__coloursDict[key][0].name())
115 else: 116 else:
116 prefMethod(key, self.__coloursDict[key][0]) 117 prefMethod(key, self.__coloursDict[key][0])
117 118
118 def selectFont(self, fontSample, fontVar, showFontInfo=False, 119 def selectFont(self, fontSample, fontVar, showFontInfo=False, options=None):
119 options=None):
120 """ 120 """
121 Public method used by the font selection buttons. 121 Public method used by the font selection buttons.
122 122
123 @param fontSample reference to the font sample widget (QLineEdit) 123 @param fontSample reference to the font sample widget (QLineEdit)
124 @param fontVar reference to the variable containing the font (QFont) 124 @param fontVar reference to the variable containing the font (QFont)
125 @param showFontInfo flag indicating to show some font info 125 @param showFontInfo flag indicating to show some font info
126 as the sample (boolean) 126 as the sample (boolean)
127 @param options options for the font dialog 127 @param options options for the font dialog
132 options = QFontDialog.FontDialogOption(0) 132 options = QFontDialog.FontDialogOption(0)
133 font, ok = QFontDialog.getFont(fontVar, self, "", options) 133 font, ok = QFontDialog.getFont(fontVar, self, "", options)
134 if ok: 134 if ok:
135 fontSample.setFont(font) 135 fontSample.setFont(font)
136 if showFontInfo: 136 if showFontInfo:
137 fontSample.setText( 137 fontSample.setText("{0} {1}".format(font.family(), font.pointSize()))
138 "{0} {1}".format(font.family(), font.pointSize()))
139 else: 138 else:
140 font = fontVar 139 font = fontVar
141 return font # __IGNORE_WARNING_M834__ 140 return font # __IGNORE_WARNING_M834__

eric ide

mercurial