eric6/Preferences/ConfigurationPages/EditorKeywordsPage.py

Wed, 30 Dec 2020 11:00:44 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 30 Dec 2020 11:00:44 +0100
branch
maintenance
changeset 7924
8a96736d465e
parent 7780
41420f82c0ac
child 8151
8c1445825e7b
permissions
-rw-r--r--

Updated copyright for 2021.

131
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7924
8a96736d465e Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7780
diff changeset
3 # Copyright (c) 2010 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
131
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing the editor highlighter keywords configuration page.
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3654
diff changeset
10 from PyQt5.QtCore import pyqtSlot
131
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11
6880
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
12 from E5Gui import E5MessageBox
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
13
131
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 from .ConfigurationPageBase import ConfigurationPageBase
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 from .Ui_EditorKeywordsPage import Ui_EditorKeywordsPage
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 import Preferences
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
19
131
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 class EditorKeywordsPage(ConfigurationPageBase, Ui_EditorKeywordsPage):
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 """
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 Class implementing the editor highlighter keywords configuration page.
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 """
6874
5a3a39442711 Lexers: extended the keyword set handling by introducing a keyword set description and some set adjustments (harmonized with SciTE).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
24 MaxKeywordSets = 8 # max. 8 sets are allowed
5a3a39442711 Lexers: extended the keyword set handling by introducing a keyword set description and some set adjustments (harmonized with SciTE).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
25
131
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 def __init__(self):
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 """
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 Constructor
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 """
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2408
diff changeset
30 super(EditorKeywordsPage, self).__init__()
131
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 self.setupUi(self)
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 self.setObjectName("EditorKeywordsPage")
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 # set initial values
2408
dc3a7c9d8f6e Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
35 import QScintilla.Lexers
dc3a7c9d8f6e Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
36 from QScintilla.Lexers.LexerContainer import LexerContainer
dc3a7c9d8f6e Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
37
131
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 self.__keywords = {
6874
5a3a39442711 Lexers: extended the keyword set handling by introducing a keyword set description and some set adjustments (harmonized with SciTE).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
39 "": {
5a3a39442711 Lexers: extended the keyword set handling by introducing a keyword set description and some set adjustments (harmonized with SciTE).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
40 "Sets": [""] * (self.MaxKeywordSets + 1),
5a3a39442711 Lexers: extended the keyword set handling by introducing a keyword set description and some set adjustments (harmonized with SciTE).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
41 "Descriptions": [""] * (self.MaxKeywordSets + 1),
5a3a39442711 Lexers: extended the keyword set handling by introducing a keyword set description and some set adjustments (harmonized with SciTE).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
42 "MaxSets": 0,
5a3a39442711 Lexers: extended the keyword set handling by introducing a keyword set description and some set adjustments (harmonized with SciTE).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
43 }
3654
ffeb85cdc72d Fixed and improved the CoffeeScript interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3178
diff changeset
44 }
ffeb85cdc72d Fixed and improved the CoffeeScript interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3178
diff changeset
45
3025
67064c71df21 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2964
diff changeset
46 languages = sorted(
67064c71df21 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2964
diff changeset
47 [''] + list(QScintilla.Lexers.getSupportedLanguages().keys()))
131
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 for lang in languages:
1457
45fe12e8533b Fixed a few issues related to the configurable keywords support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1446
diff changeset
49 if lang:
131
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 lex = QScintilla.Lexers.getLexer(lang)
1457
45fe12e8533b Fixed a few issues related to the configurable keywords support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1446
diff changeset
51 if isinstance(lex, LexerContainer):
45fe12e8533b Fixed a few issues related to the configurable keywords support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1446
diff changeset
52 continue
45fe12e8533b Fixed a few issues related to the configurable keywords support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1446
diff changeset
53 keywords = Preferences.getEditorKeywords(lang)[:]
6879
a862f60853f9 EditorKeywordsPage: changed initialisation logic to load default keywords if a keyword set is empty.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6874
diff changeset
54 if keywords:
a862f60853f9 EditorKeywordsPage: changed initialisation logic to load default keywords if a keyword set is empty.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6874
diff changeset
55 # set empty entries to default values
a862f60853f9 EditorKeywordsPage: changed initialisation logic to load default keywords if a keyword set is empty.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6874
diff changeset
56 for kwSet in range(1, self.MaxKeywordSets + 1):
a862f60853f9 EditorKeywordsPage: changed initialisation logic to load default keywords if a keyword set is empty.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6874
diff changeset
57 if not keywords[kwSet]:
a862f60853f9 EditorKeywordsPage: changed initialisation logic to load default keywords if a keyword set is empty.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6874
diff changeset
58 kw = lex.defaultKeywords(kwSet)
a862f60853f9 EditorKeywordsPage: changed initialisation logic to load default keywords if a keyword set is empty.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6874
diff changeset
59 if kw is None:
a862f60853f9 EditorKeywordsPage: changed initialisation logic to load default keywords if a keyword set is empty.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6874
diff changeset
60 kw = ""
a862f60853f9 EditorKeywordsPage: changed initialisation logic to load default keywords if a keyword set is empty.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6874
diff changeset
61 keywords[kwSet] = kw
a862f60853f9 EditorKeywordsPage: changed initialisation logic to load default keywords if a keyword set is empty.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6874
diff changeset
62 else:
1457
45fe12e8533b Fixed a few issues related to the configurable keywords support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1446
diff changeset
63 keywords = [""]
6874
5a3a39442711 Lexers: extended the keyword set handling by introducing a keyword set description and some set adjustments (harmonized with SciTE).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
64 descriptions = [""]
5a3a39442711 Lexers: extended the keyword set handling by introducing a keyword set description and some set adjustments (harmonized with SciTE).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
65 for kwSet in range(1, self.MaxKeywordSets + 1):
1457
45fe12e8533b Fixed a few issues related to the configurable keywords support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1446
diff changeset
66 kw = lex.keywords(kwSet)
45fe12e8533b Fixed a few issues related to the configurable keywords support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1446
diff changeset
67 if kw is None:
45fe12e8533b Fixed a few issues related to the configurable keywords support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1446
diff changeset
68 kw = ""
45fe12e8533b Fixed a few issues related to the configurable keywords support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1446
diff changeset
69 keywords.append(kw)
6874
5a3a39442711 Lexers: extended the keyword set handling by introducing a keyword set description and some set adjustments (harmonized with SciTE).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
70 descriptions = [""]
5a3a39442711 Lexers: extended the keyword set handling by introducing a keyword set description and some set adjustments (harmonized with SciTE).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
71 for kwSet in range(1, self.MaxKeywordSets + 1):
5a3a39442711 Lexers: extended the keyword set handling by introducing a keyword set description and some set adjustments (harmonized with SciTE).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
72 desc = lex.keywordsDescription(kwSet)
5a3a39442711 Lexers: extended the keyword set handling by introducing a keyword set description and some set adjustments (harmonized with SciTE).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
73 descriptions.append(desc)
6880
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
74 defaults = [""]
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
75 for kwSet in range(1, self.MaxKeywordSets + 1):
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
76 dkw = lex.defaultKeywords(kwSet)
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
77 if dkw is None:
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
78 dkw = ""
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
79 defaults.append(dkw)
6874
5a3a39442711 Lexers: extended the keyword set handling by introducing a keyword set description and some set adjustments (harmonized with SciTE).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
80 self.__keywords[lang] = {
5a3a39442711 Lexers: extended the keyword set handling by introducing a keyword set description and some set adjustments (harmonized with SciTE).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
81 "Sets": keywords,
5a3a39442711 Lexers: extended the keyword set handling by introducing a keyword set description and some set adjustments (harmonized with SciTE).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
82 "Descriptions": descriptions,
6880
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
83 "DefaultSets": defaults,
6874
5a3a39442711 Lexers: extended the keyword set handling by introducing a keyword set description and some set adjustments (harmonized with SciTE).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
84 "MaxSets": lex.maximumKeywordSet(),
5a3a39442711 Lexers: extended the keyword set handling by introducing a keyword set description and some set adjustments (harmonized with SciTE).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
85 }
5427
614e88cfbd84 Added some eye candy.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
86 self.languageCombo.addItem(
614e88cfbd84 Added some eye candy.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
87 QScintilla.Lexers.getLanguageIcon(lang, False),
614e88cfbd84 Added some eye candy.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
88 lang)
131
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 self.currentLanguage = ''
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 self.currentSet = 1
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 self.on_languageCombo_activated(self.currentLanguage)
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 def save(self):
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 """
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 Public slot to save the editor highlighter keywords configuration.
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 """
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 lang = self.languageCombo.currentText()
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 kwSet = self.setSpinBox.value()
6874
5a3a39442711 Lexers: extended the keyword set handling by introducing a keyword set description and some set adjustments (harmonized with SciTE).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
100 self.__keywords[lang]["Sets"][kwSet] = self.keywordsEdit.toPlainText()
131
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 for lang, keywords in self.__keywords.items():
6874
5a3a39442711 Lexers: extended the keyword set handling by introducing a keyword set description and some set adjustments (harmonized with SciTE).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
103 Preferences.setEditorKeywords(lang, keywords["Sets"])
131
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 @pyqtSlot(str)
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 def on_languageCombo_activated(self, language):
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 """
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 Private slot to fill the keywords edit.
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109
6879
a862f60853f9 EditorKeywordsPage: changed initialisation logic to load default keywords if a keyword set is empty.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6874
diff changeset
110 @param language selected language
a862f60853f9 EditorKeywordsPage: changed initialisation logic to load default keywords if a keyword set is empty.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6874
diff changeset
111 @type str
131
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 """
6880
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
113 self.defaultButton.setEnabled(bool(language))
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
114 self.allDefaultButton.setEnabled(bool(language))
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
115
131
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 if self.currentLanguage == language:
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 return
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 if self.setSpinBox.value() == 1:
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 self.on_setSpinBox_valueChanged(1)
6874
5a3a39442711 Lexers: extended the keyword set handling by introducing a keyword set description and some set adjustments (harmonized with SciTE).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
121 if self.__keywords[language]["MaxSets"]:
3654
ffeb85cdc72d Fixed and improved the CoffeeScript interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3178
diff changeset
122 first = 1
6874
5a3a39442711 Lexers: extended the keyword set handling by introducing a keyword set description and some set adjustments (harmonized with SciTE).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
123 last = self.__keywords[language]["MaxSets"]
3654
ffeb85cdc72d Fixed and improved the CoffeeScript interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3178
diff changeset
124 else:
6874
5a3a39442711 Lexers: extended the keyword set handling by introducing a keyword set description and some set adjustments (harmonized with SciTE).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
125 first, last = self.MaxKeywordSets + 1, 0
5a3a39442711 Lexers: extended the keyword set handling by introducing a keyword set description and some set adjustments (harmonized with SciTE).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
126 for kwSet in range(1, self.MaxKeywordSets + 1):
5a3a39442711 Lexers: extended the keyword set handling by introducing a keyword set description and some set adjustments (harmonized with SciTE).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
127 if self.__keywords[language]["Descriptions"][kwSet] != "":
3654
ffeb85cdc72d Fixed and improved the CoffeeScript interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3178
diff changeset
128 first = min(first, kwSet)
ffeb85cdc72d Fixed and improved the CoffeeScript interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3178
diff changeset
129 last = max(last, kwSet)
6874
5a3a39442711 Lexers: extended the keyword set handling by introducing a keyword set description and some set adjustments (harmonized with SciTE).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
130 self.setSpinBox.setEnabled(language != "" and
5a3a39442711 Lexers: extended the keyword set handling by introducing a keyword set description and some set adjustments (harmonized with SciTE).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
131 first <= self.MaxKeywordSets)
5a3a39442711 Lexers: extended the keyword set handling by introducing a keyword set description and some set adjustments (harmonized with SciTE).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
132 self.keywordsEdit.setEnabled(language != "" and
5a3a39442711 Lexers: extended the keyword set handling by introducing a keyword set description and some set adjustments (harmonized with SciTE).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
133 first <= self.MaxKeywordSets)
5a3a39442711 Lexers: extended the keyword set handling by introducing a keyword set description and some set adjustments (harmonized with SciTE).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
134 if first <= self.MaxKeywordSets:
131
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 self.setSpinBox.setMinimum(first)
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 self.setSpinBox.setMaximum(last)
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 self.setSpinBox.setValue(first)
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 else:
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 self.setSpinBox.setMinimum(0)
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 self.setSpinBox.setMaximum(0)
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 self.setSpinBox.setValue(0)
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 @pyqtSlot(int)
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 def on_setSpinBox_valueChanged(self, kwSet):
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 """
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 Private slot to fill the keywords edit.
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147
6879
a862f60853f9 EditorKeywordsPage: changed initialisation logic to load default keywords if a keyword set is empty.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6874
diff changeset
148 @param kwSet number of the selected keyword set
a862f60853f9 EditorKeywordsPage: changed initialisation logic to load default keywords if a keyword set is empty.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6874
diff changeset
149 @type int
131
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 """
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 language = self.languageCombo.currentText()
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 if self.currentLanguage == language and self.currentSet == kwSet:
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 return
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154
7263
c1af2e327675 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
155 self.__keywords[self.currentLanguage]["Sets"][self.currentSet] = (
131
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 self.keywordsEdit.toPlainText()
7263
c1af2e327675 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
157 )
131
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158
1446
e2658efcdaf4 Continued with QScintilla 2.6 support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
159 self.currentLanguage = language
131
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 self.currentSet = kwSet
6879
a862f60853f9 EditorKeywordsPage: changed initialisation logic to load default keywords if a keyword set is empty.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6874
diff changeset
161 self.setDescriptionLabel.setText("<b>{0}</b>".format(
a862f60853f9 EditorKeywordsPage: changed initialisation logic to load default keywords if a keyword set is empty.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6874
diff changeset
162 self.__keywords[language]["Descriptions"][kwSet]))
6874
5a3a39442711 Lexers: extended the keyword set handling by introducing a keyword set description and some set adjustments (harmonized with SciTE).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
163 self.keywordsEdit.setPlainText(
5a3a39442711 Lexers: extended the keyword set handling by introducing a keyword set description and some set adjustments (harmonized with SciTE).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
164 self.__keywords[language]["Sets"][kwSet])
6880
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
165
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
166 @pyqtSlot()
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
167 def on_defaultButton_clicked(self):
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
168 """
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
169 Private slot to set the current keyword set to default values.
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
170 """
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
171 if bool(self.keywordsEdit.toPlainText()):
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
172 ok = E5MessageBox.yesNo(
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
173 self,
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
174 self.tr("Reset to Default"),
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
175 self.tr("Shall the current keyword set really be reset to"
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
176 " default values?"))
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
177 else:
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
178 ok = True
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
179 if ok:
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
180 language = self.languageCombo.currentText()
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
181 kwSet = self.setSpinBox.value()
7263
c1af2e327675 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
182 self.__keywords[language]["Sets"][kwSet] = (
6880
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
183 self.__keywords[language]["DefaultSets"][kwSet]
7263
c1af2e327675 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
184 )
6880
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
185 self.keywordsEdit.setPlainText(
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
186 self.__keywords[language]["Sets"][kwSet])
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
187
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
188 @pyqtSlot()
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
189 def on_allDefaultButton_clicked(self):
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
190 """
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
191 Private slot to set all keyword sets of the current language to default
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
192 values.
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
193 """
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
194 ok = E5MessageBox.yesNo(
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
195 self,
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
196 self.tr("Reset All to Default"),
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
197 self.tr("Shall all keyword sets of the current language really be"
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
198 " reset to default values?"))
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
199 if ok:
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
200 language = self.languageCombo.currentText()
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
201 kwSet = self.setSpinBox.value()
7263
c1af2e327675 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
202 self.__keywords[language]["Sets"] = (
6880
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
203 self.__keywords[language]["DefaultSets"][:]
7263
c1af2e327675 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
204 )
6880
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
205 self.keywordsEdit.setPlainText(
51f8a56f0b42 EditorKeywordsPage: added the "Default" and "All to Default" buttons to reset one or all keyword sets of a language lexer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6879
diff changeset
206 self.__keywords[language]["Sets"][kwSet])
131
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
208
131
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209 def create(dlg):
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
210 """
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211 Module function to create the configuration page.
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213 @param dlg reference to the configuration dialog
6879
a862f60853f9 EditorKeywordsPage: changed initialisation logic to load default keywords if a keyword set is empty.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6874
diff changeset
214 @type ConfigurationWidget
a862f60853f9 EditorKeywordsPage: changed initialisation logic to load default keywords if a keyword set is empty.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6874
diff changeset
215 @return reference to the instantiated page
a862f60853f9 EditorKeywordsPage: changed initialisation logic to load default keywords if a keyword set is empty.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6874
diff changeset
216 @rtype ConfigurationPageBase
131
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
217 """
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
218 page = EditorKeywordsPage()
60d355abbcd8 Added capability to change the keywords of a syntax highlighter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
219 return page

eric ide

mercurial