8 """ |
8 """ |
9 |
9 |
10 import os |
10 import os |
11 |
11 |
12 from PyQt6.QtCore import pyqtSlot, Qt, QFileInfo, QFile, QIODevice |
12 from PyQt6.QtCore import pyqtSlot, Qt, QFileInfo, QFile, QIODevice |
13 from PyQt6.QtGui import QPalette, QFont, QColor |
13 from PyQt6.QtGui import QFont, QColor |
14 from PyQt6.QtWidgets import ( |
14 from PyQt6.QtWidgets import ( |
15 QColorDialog, QFontDialog, QInputDialog, QMenu, QTreeWidgetItem, QDialog |
15 QColorDialog, QFontDialog, QInputDialog, QMenu, QTreeWidgetItem, QDialog |
16 ) |
16 ) |
17 |
17 |
18 from .ConfigurationPageBase import ConfigurationPageBase |
18 from .ConfigurationPageBase import ConfigurationPageBase |
198 while itm is not None: |
198 while itm is not None: |
199 style, substyle = self.__stylesForItem(itm) |
199 style, substyle = self.__stylesForItem(itm) |
200 self.__styleOneItem(itm, style, substyle) |
200 self.__styleOneItem(itm, style, substyle) |
201 itm = self.styleElementList.itemBelow(itm) |
201 itm = self.styleElementList.itemBelow(itm) |
202 |
202 |
|
203 def __styleSample(self, color, paper, font=None): |
|
204 """ |
|
205 Private method to style the sample text. |
|
206 |
|
207 @param color foreground color for the sample |
|
208 @type QColor |
|
209 @param paper background color for the sample |
|
210 @type QColor |
|
211 @param font font for the sample (defaults to None) |
|
212 @type QFont (optional) |
|
213 """ |
|
214 if font: |
|
215 self.sampleText.setFont(font) |
|
216 |
|
217 self.sampleText.setStyleSheet( |
|
218 "QLineEdit {{ color: {0}; background-color: {1}; }}".format( |
|
219 color.name(), paper.name() |
|
220 ) |
|
221 ) |
|
222 |
203 @pyqtSlot(QTreeWidgetItem, QTreeWidgetItem) |
223 @pyqtSlot(QTreeWidgetItem, QTreeWidgetItem) |
204 def on_styleElementList_currentItemChanged(self, current, previous): |
224 def on_styleElementList_currentItemChanged(self, current, previous): |
205 """ |
225 """ |
206 Private method to handle a change of the current row. |
226 Private method to handle a change of the current row. |
207 |
227 |
217 colour = self.lexer.color(style, substyle) |
237 colour = self.lexer.color(style, substyle) |
218 paper = self.lexer.paper(style, substyle) |
238 paper = self.lexer.paper(style, substyle) |
219 eolfill = self.lexer.eolFill(style, substyle) |
239 eolfill = self.lexer.eolFill(style, substyle) |
220 font = self.lexer.font(style, substyle) |
240 font = self.lexer.font(style, substyle) |
221 |
241 |
222 self.sampleText.setFont(font) |
242 self.__styleSample(colour, paper, font=font) |
223 pl = self.sampleText.palette() |
|
224 pl.setColor(QPalette.ColorRole.Text, colour) |
|
225 pl.setColor(QPalette.ColorRole.Base, paper) |
|
226 self.sampleText.setPalette(pl) |
|
227 self.sampleText.repaint() |
|
228 self.eolfillCheckBox.setChecked(eolfill) |
243 self.eolfillCheckBox.setChecked(eolfill) |
229 |
244 |
230 selectedOne = len(self.styleElementList.selectedItems()) == 1 |
245 selectedOne = len(self.styleElementList.selectedItems()) == 1 |
231 self.defaultSubstylesButton.setEnabled( |
246 self.defaultSubstylesButton.setEnabled( |
232 selectedOne and substyle < 0 and self.lexer.isBaseStyle(style)) |
247 selectedOne and substyle < 0 and self.lexer.isBaseStyle(style)) |
243 style and lexer. |
258 style and lexer. |
244 """ |
259 """ |
245 style, substyle = self.__currentStyles() |
260 style, substyle = self.__currentStyles() |
246 colour = QColorDialog.getColor(self.lexer.color(style, substyle)) |
261 colour = QColorDialog.getColor(self.lexer.color(style, substyle)) |
247 if colour.isValid(): |
262 if colour.isValid(): |
248 pl = self.sampleText.palette() |
263 paper = self.lexer.paper(style, substyle) |
249 pl.setColor(QPalette.ColorRole.Text, colour) |
264 self.__styleSample(colour, paper) |
250 self.sampleText.setPalette(pl) |
|
251 self.sampleText.repaint() |
|
252 for selItem in self.styleElementList.selectedItems(): |
265 for selItem in self.styleElementList.selectedItems(): |
253 style, substyle = self.__stylesForItem(selItem) |
266 style, substyle = self.__stylesForItem(selItem) |
254 self.lexer.setColor(colour, style, substyle) |
267 self.lexer.setColor(colour, style, substyle) |
255 selItem.setForeground(0, colour) |
268 selItem.setForeground(0, colour) |
256 |
269 |
259 """ |
272 """ |
260 Private method used to select the background colour of the selected |
273 Private method used to select the background colour of the selected |
261 style and lexer. |
274 style and lexer. |
262 """ |
275 """ |
263 style, substyle = self.__currentStyles() |
276 style, substyle = self.__currentStyles() |
264 colour = QColorDialog.getColor(self.lexer.paper(style, substyle)) |
277 paper = QColorDialog.getColor(self.lexer.paper(style, substyle)) |
265 if colour.isValid(): |
278 if paper.isValid(): |
266 pl = self.sampleText.palette() |
279 colour = self.lexer.color(style, substyle) |
267 pl.setColor(QPalette.ColorRole.Base, colour) |
280 self.__styleSample(colour, paper) |
268 self.sampleText.setPalette(pl) |
|
269 self.sampleText.repaint() |
|
270 for selItem in self.styleElementList.selectedItems(): |
281 for selItem in self.styleElementList.selectedItems(): |
271 style, substyle = self.__stylesForItem(selItem) |
282 style, substyle = self.__stylesForItem(selItem) |
272 self.lexer.setPaper(colour, style, substyle) |
283 self.lexer.setPaper(colour, style, substyle) |
273 selItem.setBackground(0, colour) |
284 selItem.setBackground(0, colour) |
274 |
285 |
279 selected lexer. |
290 selected lexer. |
280 """ |
291 """ |
281 style, substyle = self.__currentStyles() |
292 style, substyle = self.__currentStyles() |
282 colour = QColorDialog.getColor(self.lexer.paper(style, substyle)) |
293 colour = QColorDialog.getColor(self.lexer.paper(style, substyle)) |
283 if colour.isValid(): |
294 if colour.isValid(): |
284 pl = self.sampleText.palette() |
295 paper = self.lexer.paper(style, substyle) |
285 pl.setColor(QPalette.ColorRole.Base, colour) |
296 self.__styleSample(colour, paper) |
286 self.sampleText.setPalette(pl) |
|
287 self.sampleText.repaint() |
|
288 |
297 |
289 itm = self.styleElementList.topLevelItem(0) |
298 itm = self.styleElementList.topLevelItem(0) |
290 while itm is not None: |
299 while itm is not None: |
291 style, substyle = self.__stylesForItem(itm) |
300 style, substyle = self.__stylesForItem(itm) |
292 self.lexer.setPaper(colour, style, substyle) |
301 self.lexer.setPaper(colour, style, substyle) |