5 |
5 |
6 """ |
6 """ |
7 Module implementing the Editor Highlighting Styles configuration page. |
7 Module implementing the Editor Highlighting Styles configuration page. |
8 """ |
8 """ |
9 |
9 |
|
10 import enum |
10 import pathlib |
11 import pathlib |
11 |
12 |
12 from PyQt6.QtCore import QFile, QIODevice, Qt, pyqtSlot |
13 from PyQt6.QtCore import QFile, QIODevice, Qt, pyqtSlot |
13 from PyQt6.QtGui import QColor, QFont |
14 from PyQt6.QtGui import QColor, QFont |
14 from PyQt6.QtWidgets import ( |
15 from PyQt6.QtWidgets import ( |
29 from ..SubstyleDefinitionDialog import SubstyleDefinitionDialog |
30 from ..SubstyleDefinitionDialog import SubstyleDefinitionDialog |
30 from .ConfigurationPageBase import ConfigurationPageBase |
31 from .ConfigurationPageBase import ConfigurationPageBase |
31 from .Ui_EditorHighlightingStylesPage import Ui_EditorHighlightingStylesPage |
32 from .Ui_EditorHighlightingStylesPage import Ui_EditorHighlightingStylesPage |
32 |
33 |
33 |
34 |
|
35 class FontChangeMode(enum.Enum): |
|
36 """ |
|
37 Class defining the modes for font changes. |
|
38 """ |
|
39 |
|
40 FAMILYONLY = 0 |
|
41 SIZEONLY = 1 |
|
42 FAMILYANDSIZE = 2 |
|
43 FONT = 99 |
|
44 |
|
45 |
34 class EditorHighlightingStylesPage( |
46 class EditorHighlightingStylesPage( |
35 ConfigurationPageBase, Ui_EditorHighlightingStylesPage |
47 ConfigurationPageBase, Ui_EditorHighlightingStylesPage |
36 ): |
48 ): |
37 """ |
49 """ |
38 Class implementing the Editor Highlighting Styles configuration page. |
50 Class implementing the Editor Highlighting Styles configuration page. |
39 """ |
51 """ |
40 |
52 |
41 # TODO: change this to an enum |
|
42 FAMILYONLY = 0 |
|
43 SIZEONLY = 1 |
|
44 FAMILYANDSIZE = 2 |
|
45 FONT = 99 |
|
46 |
|
47 StyleRole = Qt.ItemDataRole.UserRole + 1 |
53 StyleRole = Qt.ItemDataRole.UserRole + 1 |
48 SubstyleRole = Qt.ItemDataRole.UserRole + 2 |
54 SubstyleRole = Qt.ItemDataRole.UserRole + 2 |
49 |
55 |
50 def __init__(self, lexers): |
56 def __init__(self, lexers): |
51 """ |
57 """ |
64 self.editSubstyleButton.setIcon(EricPixmapCache.getIcon("edit")) |
70 self.editSubstyleButton.setIcon(EricPixmapCache.getIcon("edit")) |
65 self.copySubstyleButton.setIcon(EricPixmapCache.getIcon("editCopy")) |
71 self.copySubstyleButton.setIcon(EricPixmapCache.getIcon("editCopy")) |
66 |
72 |
67 self.__fontButtonMenu = QMenu() |
73 self.__fontButtonMenu = QMenu() |
68 act = self.__fontButtonMenu.addAction(self.tr("Font")) |
74 act = self.__fontButtonMenu.addAction(self.tr("Font")) |
69 act.setData(self.FONT) |
75 act.setData(FontChangeMode.FONT) |
70 self.__fontButtonMenu.addSeparator() |
76 self.__fontButtonMenu.addSeparator() |
71 act = self.__fontButtonMenu.addAction(self.tr("Family and Size only")) |
77 act = self.__fontButtonMenu.addAction(self.tr("Family and Size only")) |
72 act.setData(self.FAMILYANDSIZE) |
78 act.setData(FontChangeMode.FAMILYANDSIZE) |
73 act = self.__fontButtonMenu.addAction(self.tr("Family only")) |
79 act = self.__fontButtonMenu.addAction(self.tr("Family only")) |
74 act.setData(self.FAMILYONLY) |
80 act.setData(FontChangeMode.FAMILYONLY) |
75 act = self.__fontButtonMenu.addAction(self.tr("Size only")) |
81 act = self.__fontButtonMenu.addAction(self.tr("Size only")) |
76 act.setData(self.SIZEONLY) |
82 act.setData(FontChangeMode.SIZEONLY) |
77 self.__fontButtonMenu.triggered.connect(self.__fontButtonMenuTriggered) |
83 self.__fontButtonMenu.triggered.connect(self.__fontButtonMenuTriggered) |
78 self.fontButton.setMenu(self.__fontButtonMenu) |
84 self.fontButton.setMenu(self.__fontButtonMenu) |
79 |
85 |
80 self.__allFontsButtonMenu = QMenu() |
86 self.__allFontsButtonMenu = QMenu() |
81 act = self.__allFontsButtonMenu.addAction(self.tr("Font")) |
87 act = self.__allFontsButtonMenu.addAction(self.tr("Font")) |
82 act.setData(self.FONT) |
88 act.setData(FontChangeMode.FONT) |
83 self.__allFontsButtonMenu.addSeparator() |
89 self.__allFontsButtonMenu.addSeparator() |
84 act = self.__allFontsButtonMenu.addAction(self.tr("Family and Size only")) |
90 act = self.__allFontsButtonMenu.addAction(self.tr("Family and Size only")) |
85 act.setData(self.FAMILYANDSIZE) |
91 act.setData(FontChangeMode.FAMILYANDSIZE) |
86 act = self.__allFontsButtonMenu.addAction(self.tr("Family only")) |
92 act = self.__allFontsButtonMenu.addAction(self.tr("Family only")) |
87 act.setData(self.FAMILYONLY) |
93 act.setData(FontChangeMode.FAMILYONLY) |
88 act = self.__allFontsButtonMenu.addAction(self.tr("Size only")) |
94 act = self.__allFontsButtonMenu.addAction(self.tr("Size only")) |
89 act.setData(self.SIZEONLY) |
95 act.setData(FontChangeMode.SIZEONLY) |
90 self.__allFontsButtonMenu.triggered.connect(self.__allFontsButtonMenuTriggered) |
96 self.__allFontsButtonMenu.triggered.connect(self.__allFontsButtonMenuTriggered) |
91 self.allFontsButton.setMenu(self.__allFontsButtonMenu) |
97 self.allFontsButton.setMenu(self.__allFontsButtonMenu) |
92 |
98 |
93 self.lexer = None |
99 self.lexer = None |
94 self.lexers = lexers |
100 self.lexers = lexers |
422 @type QAction |
428 @type QAction |
423 """ |
429 """ |
424 if act is None: |
430 if act is None: |
425 return |
431 return |
426 |
432 |
427 familyOnly = act.data() in [self.FAMILYANDSIZE, self.FAMILYONLY] |
433 familyOnly = act.data() in ( |
428 sizeOnly = act.data() in [self.FAMILYANDSIZE, self.SIZEONLY] |
434 FontChangeMode.FAMILYANDSIZE, |
|
435 FontChangeMode.FAMILYONLY, |
|
436 ) |
|
437 sizeOnly = act.data() in (FontChangeMode.FAMILYANDSIZE, FontChangeMode.SIZEONLY) |
429 self.__changeFont(False, familyOnly, sizeOnly) |
438 self.__changeFont(False, familyOnly, sizeOnly) |
430 |
439 |
431 def __allFontsButtonMenuTriggered(self, act): |
440 def __allFontsButtonMenuTriggered(self, act): |
432 """ |
441 """ |
433 Private slot used to change the font of all styles of a selected lexer. |
442 Private slot used to change the font of all styles of a selected lexer. |
436 @type QAction |
445 @type QAction |
437 """ |
446 """ |
438 if act is None: |
447 if act is None: |
439 return |
448 return |
440 |
449 |
441 familyOnly = act.data() in [self.FAMILYANDSIZE, self.FAMILYONLY] |
450 familyOnly = act.data() in ( |
442 sizeOnly = act.data() in [self.FAMILYANDSIZE, self.SIZEONLY] |
451 FontChangeMode.FAMILYANDSIZE, |
|
452 FontChangeMode.FAMILYONLY, |
|
453 ) |
|
454 sizeOnly = act.data() in (FontChangeMode.FAMILYANDSIZE, FontChangeMode.SIZEONLY) |
443 self.__changeFont(True, familyOnly, sizeOnly) |
455 self.__changeFont(True, familyOnly, sizeOnly) |
444 |
456 |
445 @pyqtSlot(bool) |
457 @pyqtSlot(bool) |
446 def on_eolfillCheckBox_clicked(self, on): |
458 def on_eolfillCheckBox_clicked(self, on): |
447 """ |
459 """ |