Tue, 08 Nov 2022 11:14:44 +0100
Changed the way editor lexers are instantiated.
3557
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1 | # -*- coding: utf-8 -*- |
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
2 | |
8881
54e42bc2437a
Updated copyright for 2022.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8318
diff
changeset
|
3 | # Copyright (c) 2014 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
3557
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
4 | # |
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
5 | |
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
6 | """ |
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
7 | Module implementing a Gettext lexer with some additional methods. |
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
8 | """ |
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
9 | |
8318
962bce857696
Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8312
diff
changeset
|
10 | from PyQt6.Qsci import QsciLexerPO |
3557
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
11 | |
9473
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9413
diff
changeset
|
12 | from eric7 import Preferences |
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9413
diff
changeset
|
13 | |
3557
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
14 | from .Lexer import Lexer |
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
15 | |
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
16 | |
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
17 | class LexerPO(Lexer, QsciLexerPO): |
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
18 | """ |
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
19 | Subclass to implement some additional lexer dependant methods. |
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
20 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
21 | |
3557
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
22 | def __init__(self, parent=None): |
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
23 | """ |
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
24 | Constructor |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
25 | |
3557
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
26 | @param parent parent widget of this lexer |
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
27 | """ |
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
28 | QsciLexerPO.__init__(self, parent) |
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
29 | Lexer.__init__(self) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
30 | |
3557
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
31 | self.commentString = "#" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
32 | |
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
|
33 | self.keywordSetDescriptions = [] |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
34 | |
3557
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
35 | def initProperties(self): |
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
36 | """ |
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
37 | Public slot to initialize the properties. |
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
38 | """ |
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
39 | self.setFoldComments(Preferences.getEditor("PoFoldComment")) |
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
40 | self.setFoldCompact(Preferences.getEditor("AllFoldCompact")) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
41 | |
3557
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
42 | def isCommentStyle(self, style): |
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
43 | """ |
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
44 | Public method to check, if a style is a comment style. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
45 | |
3557
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
46 | @param style style to check (integer) |
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
47 | @return flag indicating a comment style (boolean) |
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
48 | """ |
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
49 | return style in [QsciLexerPO.Comment, QsciLexerPO.ProgrammerComment] |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
50 | |
3557
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
51 | def isStringStyle(self, style): |
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
52 | """ |
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
53 | Public method to check, if a style is a string style. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
54 | |
3557
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
55 | @param style style to check (integer) |
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
56 | @return flag indicating a string style (boolean) |
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
57 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
58 | return style in [ |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
59 | QsciLexerPO.MessageIdText, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
60 | QsciLexerPO.MessageStringText, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
61 | QsciLexerPO.MessageContextText, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
62 | ] |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
63 | |
3557
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
64 | def defaultKeywords(self, kwSet): |
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
65 | """ |
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
66 | Public method to get the default keywords. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
67 | |
3557
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
68 | @param kwSet number of the keyword set (integer) |
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
69 | @return string giving the keywords (string) or None |
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
70 | """ |
3ea8ba471d96
Added support for the QScintilla Gettext lexer (QsciLexerPO) as of QScintilla 2.8.2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
71 | return QsciLexerPO.keywords(self, kwSet) |
9484
d2eb8f0a5bf0
Changed the way editor lexers are instantiated.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
72 | |
d2eb8f0a5bf0
Changed the way editor lexers are instantiated.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
73 | |
d2eb8f0a5bf0
Changed the way editor lexers are instantiated.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
74 | def createLexer(variant="", parent=None): |
d2eb8f0a5bf0
Changed the way editor lexers are instantiated.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
75 | """ |
d2eb8f0a5bf0
Changed the way editor lexers are instantiated.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
76 | Function to instantiate a lexer object. |
d2eb8f0a5bf0
Changed the way editor lexers are instantiated.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
77 | |
d2eb8f0a5bf0
Changed the way editor lexers are instantiated.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
78 | @param variant name of the language variant |
d2eb8f0a5bf0
Changed the way editor lexers are instantiated.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
79 | @type str |
d2eb8f0a5bf0
Changed the way editor lexers are instantiated.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
80 | @param parent parent widget of this lexer |
d2eb8f0a5bf0
Changed the way editor lexers are instantiated.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
81 | @type QObject |
d2eb8f0a5bf0
Changed the way editor lexers are instantiated.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
82 | @return instantiated lexer object |
d2eb8f0a5bf0
Changed the way editor lexers are instantiated.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
83 | @rtype LexerPO |
d2eb8f0a5bf0
Changed the way editor lexers are instantiated.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
84 | """ |
d2eb8f0a5bf0
Changed the way editor lexers are instantiated.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
85 | return LexerPO(parent=parent) |