src/eric7/Preferences/ConfigurationPages/DiffColoursPage.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
18 18
19 class DiffColoursPage(ConfigurationPageBase, Ui_DiffColoursPage): 19 class DiffColoursPage(ConfigurationPageBase, Ui_DiffColoursPage):
20 """ 20 """
21 Class implementing the Diff colours configuration page. 21 Class implementing the Diff colours configuration page.
22 """ 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 self.setupUi(self) 29 self.setupUi(self)
29 self.setObjectName("DiffColoursPage") 30 self.setObjectName("DiffColoursPage")
30 31
31 self.__coloursDict = {} 32 self.__coloursDict = {}
32 33
33 monospacedFont = Preferences.getEditorOtherFonts("MonospacedFont") 34 monospacedFont = Preferences.getEditorOtherFonts("MonospacedFont")
34 self.__allSamples = ( 35 self.__allSamples = (
35 self.textSample, 36 self.textSample,
36 self.addedSample, 37 self.addedSample,
37 self.removedSample, 38 self.removedSample,
38 self.replacedSample, 39 self.replacedSample,
39 self.contextSample, 40 self.contextSample,
40 self.headerSample, 41 self.headerSample,
41 self.whitespaceSample 42 self.whitespaceSample,
42 ) 43 )
43 for sample in self.__allSamples: 44 for sample in self.__allSamples:
44 sample.setFont(monospacedFont) 45 sample.setFont(monospacedFont)
45 46
46 # set initial values 47 # set initial values
47 self.__initColour( 48 self.__initColour(
48 "TextColor", 49 "TextColor",
49 self.textButton, 50 self.textButton,
50 self.__updateSampleTextColour, 51 self.__updateSampleTextColour,
51 lambda: self.__selectTextColour(self.textButton), 52 lambda: self.__selectTextColour(self.textButton),
52 self.textSample) 53 self.textSample,
54 )
53 self.__initColour( 55 self.__initColour(
54 "AddedColor", 56 "AddedColor",
55 self.addedButton, 57 self.addedButton,
56 self.__updateSampleBackgroundColour, 58 self.__updateSampleBackgroundColour,
57 lambda: self.__selectBackgroundColour(self.addedButton), 59 lambda: self.__selectBackgroundColour(self.addedButton),
58 self.addedSample) 60 self.addedSample,
61 )
59 self.__initColour( 62 self.__initColour(
60 "RemovedColor", 63 "RemovedColor",
61 self.removedButton, 64 self.removedButton,
62 self.__updateSampleBackgroundColour, 65 self.__updateSampleBackgroundColour,
63 lambda: self.__selectBackgroundColour(self.removedButton), 66 lambda: self.__selectBackgroundColour(self.removedButton),
64 self.removedSample) 67 self.removedSample,
68 )
65 self.__initColour( 69 self.__initColour(
66 "ReplacedColor", 70 "ReplacedColor",
67 self.replacedButton, 71 self.replacedButton,
68 self.__updateSampleBackgroundColour, 72 self.__updateSampleBackgroundColour,
69 lambda: self.__selectBackgroundColour(self.replacedButton), 73 lambda: self.__selectBackgroundColour(self.replacedButton),
70 self.replacedSample) 74 self.replacedSample,
75 )
71 self.__initColour( 76 self.__initColour(
72 "ContextColor", 77 "ContextColor",
73 self.contextButton, 78 self.contextButton,
74 self.__updateSampleBackgroundColour, 79 self.__updateSampleBackgroundColour,
75 lambda: self.__selectBackgroundColour(self.contextButton), 80 lambda: self.__selectBackgroundColour(self.contextButton),
76 self.contextSample) 81 self.contextSample,
82 )
77 self.__initColour( 83 self.__initColour(
78 "HeaderColor", 84 "HeaderColor",
79 self.headerButton, 85 self.headerButton,
80 self.__updateSampleBackgroundColour, 86 self.__updateSampleBackgroundColour,
81 lambda: self.__selectBackgroundColour(self.headerButton), 87 lambda: self.__selectBackgroundColour(self.headerButton),
82 self.headerSample) 88 self.headerSample,
89 )
83 self.__initColour( 90 self.__initColour(
84 "BadWhitespaceColor", 91 "BadWhitespaceColor",
85 self.whitespaceButton, 92 self.whitespaceButton,
86 self.__updateSampleBackgroundColour, 93 self.__updateSampleBackgroundColour,
87 lambda: self.__selectBackgroundColour(self.whitespaceButton), 94 lambda: self.__selectBackgroundColour(self.whitespaceButton),
88 self.whitespaceSample) 95 self.whitespaceSample,
89 96 )
97
90 def save(self): 98 def save(self):
91 """ 99 """
92 Public slot to save the Diff colours configuration. 100 Public slot to save the Diff colours configuration.
93 """ 101 """
94 for key in self.__coloursDict: 102 for key in self.__coloursDict:
95 Preferences.setDiffColour(key, self.__coloursDict[key][0]) 103 Preferences.setDiffColour(key, self.__coloursDict[key][0])
96 104
97 def __initColour(self, colourKey, button, initSlot, selectSlot, 105 def __initColour(self, colourKey, button, initSlot, selectSlot, sampleWidget):
98 sampleWidget):
99 """ 106 """
100 Private method to initialize a colour selection button. 107 Private method to initialize a colour selection button.
101 108
102 @param colourKey key of the diff colour 109 @param colourKey key of the diff colour
103 @type str 110 @type str
104 @param button reference to the button 111 @param button reference to the button
105 @type QPushButton 112 @type QPushButton
106 @param initSlot slot to be called to initialize the sample 113 @param initSlot slot to be called to initialize the sample
114 button.setProperty("colorKey", colourKey) 121 button.setProperty("colorKey", colourKey)
115 button.clicked.connect(selectSlot) 122 button.clicked.connect(selectSlot)
116 self.__coloursDict[colourKey] = [colour, sampleWidget] 123 self.__coloursDict[colourKey] = [colour, sampleWidget]
117 if initSlot: 124 if initSlot:
118 initSlot(colourKey) 125 initSlot(colourKey)
119 126
120 @pyqtSlot() 127 @pyqtSlot()
121 def __selectTextColour(self, button): 128 def __selectTextColour(self, button):
122 """ 129 """
123 Private slot to select the text colour. 130 Private slot to select the text colour.
124 131
125 @param button reference to the button been pressed 132 @param button reference to the button been pressed
126 @type QPushButton 133 @type QPushButton
127 """ 134 """
128 colorKey = button.property("colorKey") 135 colorKey = button.property("colorKey")
129 136
130 colour = QColorDialog.getColor(self.__coloursDict[colorKey][0], self) 137 colour = QColorDialog.getColor(self.__coloursDict[colorKey][0], self)
131 if colour.isValid(): 138 if colour.isValid():
132 self.__coloursDict[colorKey][0] = colour 139 self.__coloursDict[colorKey][0] = colour
133 self.__updateSampleTextColour(colorKey) 140 self.__updateSampleTextColour(colorKey)
134 141
135 @pyqtSlot() 142 @pyqtSlot()
136 def __selectBackgroundColour(self, button): 143 def __selectBackgroundColour(self, button):
137 """ 144 """
138 Private slot to select a background colour. 145 Private slot to select a background colour.
139 146
140 @param button reference to the button been pressed 147 @param button reference to the button been pressed
141 @type QPushButton 148 @type QPushButton
142 """ 149 """
143 colorKey = button.property("colorKey") 150 colorKey = button.property("colorKey")
144 151
145 colour = QColorDialog.getColor( 152 colour = QColorDialog.getColor(
146 self.__coloursDict[colorKey][0], self, "", 153 self.__coloursDict[colorKey][0],
147 QColorDialog.ColorDialogOption.ShowAlphaChannel) 154 self,
155 "",
156 QColorDialog.ColorDialogOption.ShowAlphaChannel,
157 )
148 if colour.isValid(): 158 if colour.isValid():
149 self.__coloursDict[colorKey][0] = colour 159 self.__coloursDict[colorKey][0] = colour
150 self.__updateSampleBackgroundColour(colorKey) 160 self.__updateSampleBackgroundColour(colorKey)
151 161
152 @pyqtSlot() 162 @pyqtSlot()
153 def __updateSampleTextColour(self, colourKey): 163 def __updateSampleTextColour(self, colourKey):
154 """ 164 """
155 Private slot to update the text colour of all samples. 165 Private slot to update the text colour of all samples.
156 166
157 @param colourKey key of the diff colour 167 @param colourKey key of the diff colour
158 @type str 168 @type str
159 """ 169 """
160 colour = self.__coloursDict[colourKey][0] 170 colour = self.__coloursDict[colourKey][0]
161 for key in self.__coloursDict: 171 for key in self.__coloursDict:
163 self.__coloursDict[key][1].setStyleSheet( 173 self.__coloursDict[key][1].setStyleSheet(
164 "QLineEdit {{ color: {0}; }}".format(colour.name()) 174 "QLineEdit {{ color: {0}; }}".format(colour.name())
165 ) 175 )
166 else: 176 else:
167 self.__coloursDict[key][1].setStyleSheet( 177 self.__coloursDict[key][1].setStyleSheet(
168 "QLineEdit {{ color: {0}; background-color: {1}; }}" 178 "QLineEdit {{ color: {0}; background-color: {1}; }}".format(
169 .format(colour.name(), self.__coloursDict[key][0].name()) 179 colour.name(), self.__coloursDict[key][0].name()
180 )
170 ) 181 )
171 182
172 def __updateSampleBackgroundColour(self, colourKey): 183 def __updateSampleBackgroundColour(self, colourKey):
173 """ 184 """
174 Private slot to update the background colour of a sample. 185 Private slot to update the background colour of a sample.
175 186
176 @param colourKey key of the diff colour 187 @param colourKey key of the diff colour
177 @type str 188 @type str
178 """ 189 """
179 sample = self.__coloursDict[colourKey][1] 190 sample = self.__coloursDict[colourKey][1]
180 if sample: 191 if sample:
181 colour = self.__coloursDict[colourKey][0] 192 colour = self.__coloursDict[colourKey][0]
182 sample.setStyleSheet( 193 sample.setStyleSheet(
183 "QLineEdit {{ color: {0}; background-color: {1}; }}" 194 "QLineEdit {{ color: {0}; background-color: {1}; }}".format(
184 .format(self.__coloursDict["TextColor"][0].name(), 195 self.__coloursDict["TextColor"][0].name(), colour.name()
185 colour.name()) 196 )
186 ) 197 )
187 198
188 199
189 def create(dlg): 200 def create(dlg):
190 """ 201 """
191 Module function to create the configuration page. 202 Module function to create the configuration page.
192 203
193 @param dlg reference to the configuration dialog 204 @param dlg reference to the configuration dialog
194 @return reference to the instantiated page (ConfigurationPageBase) 205 @return reference to the instantiated page (ConfigurationPageBase)
195 """ 206 """
196 page = DiffColoursPage() 207 page = DiffColoursPage()
197 return page 208 return page

eric ide

mercurial