src/eric7/QScintilla/Lexers/LexerQSS.py

branch
eric7
changeset 9209
b99e7fd55fd3
parent 8881
54e42bc2437a
child 9221
bf71ee032bb4
equal deleted inserted replaced
9208:3fc8dfeb6ebe 9209:b99e7fd55fd3
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2005 - 2022 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a QSS lexer with some additional methods.
8 """
9
10 import contextlib
11
12 from PyQt6.Qsci import QsciLexerCSS
13
14 from .Lexer import Lexer
15 import Preferences
16
17
18 class LexerQSS(Lexer, QsciLexerCSS):
19 """
20 Subclass to implement some additional lexer dependent methods.
21 """
22 def __init__(self, parent=None):
23 """
24 Constructor
25
26 @param parent parent widget of this lexer
27 """
28 QsciLexerCSS.__init__(self, parent)
29 Lexer.__init__(self)
30
31 self.commentString = "#"
32 self.streamCommentString = {
33 'start': '/* ',
34 'end': ' */'
35 }
36
37 self.keywordSetDescriptions = [
38 self.tr("CSS1 Properties"),
39 self.tr("Pseudo-Classes"),
40 self.tr("CSS2 Properties"),
41 self.tr("CSS3 Properties"),
42 self.tr("Pseudo-Elements"),
43 self.tr("Browser-Specific CSS Properties"),
44 self.tr("Browser-Specific Pseudo-Classes"),
45 self.tr("Browser-Specific Pseudo-Elements"),
46 ]
47
48 def initProperties(self):
49 """
50 Public slot to initialize the properties.
51 """
52 self.setFoldComments(Preferences.getEditor("CssFoldComment"))
53 self.setFoldCompact(Preferences.getEditor("AllFoldCompact"))
54 with contextlib.suppress(AttributeError):
55 self.setHSSLanguage(
56 Preferences.getEditor("CssHssSupport"))
57 self.setLessLanguage(
58 Preferences.getEditor("CssLessSupport"))
59 self.setSCSSLanguage(
60 Preferences.getEditor("CssSassySupport"))
61
62 def isCommentStyle(self, style):
63 """
64 Public method to check, if a style is a comment style.
65
66 @param style style to check (integer)
67 @return flag indicating a comment style (boolean)
68 """
69 return style in [QsciLexerCSS.Comment]
70
71 def isStringStyle(self, style):
72 """
73 Public method to check, if a style is a string style.
74
75 @param style style to check (integer)
76 @return flag indicating a string style (boolean)
77 """
78 return style in [QsciLexerCSS.DoubleQuotedString,
79 QsciLexerCSS.SingleQuotedString]
80
81 def defaultKeywords(self, kwSet):
82 """
83 Public method to get the default keywords.
84
85 @param kwSet number of the keyword set (integer)
86 @return string giving the keywords (string) or None
87 """
88 if kwSet == 1:
89 return (
90 "alternate-background-color background background-color"
91 " background-image background-repeat background-position"
92 " background-attachment background-clip background-origin"
93 " border border-top border-right border-bottom border-left"
94 " border-color border-top-color border-right-color"
95 " border-bottom-color border-left-color border-image"
96 " border-radius border-top-left-radius"
97 " border-top-right-radius border-bottom-right-radius"
98 " border-bottom-left-radius border-style border-top-style"
99 " border-right-style border-bottom-style border-left-style"
100 " border-width border-top-width border-right-width"
101 " border-bottom-width border-left-width bottom button-layout"
102 " color dialogbuttonbox-buttons-have-icons font font-family"
103 " font-size font-style font-weight gridline-color"
104 " height icon-size image image-position left"
105 " lineedit-password-character margin margin-top margin-right"
106 " margin-bottom margin-left max-height max-width"
107 " messagebox-text-interaction-flags min-height min-width"
108 " opacity outline padding padding-top padding-right"
109 " padding-bottom padding-left"
110 " paint-alternating-row-colors-for-empty-area"
111 " position right selection-background-color selection-color"
112 " show-decoration-selected spacing subcontrol-origin"
113 " subcontrol-position text-align text-decoration"
114 " top width"
115 ""
116 " backward-icon cd-icon computer-icon desktop-icon"
117 " dialog-apply-icon dialog-cancel-icon dialog-close-icon"
118 " dialog-discard-icon dialog-help-icon dialog-no-icon"
119 " dialog-ok-icon dialog-open-icon dialog-reset-icon"
120 " dialog-save-icon dialog-yes-icon directory-closed-icon"
121 " directory-icon directory-link-icon directory-open-icon"
122 " dockwidget-close-icon downarrow-icon dvd-icon file-icon"
123 " file-link-icon filedialog-contentsview-icon"
124 " filedialog-detailedview-icon filedialog-end-icon"
125 " filedialog-infoview-icon filedialog-listview-icon"
126 " filedialog-new-directory-icon"
127 " filedialog-parent-directory-icon filedialog-start-icon"
128 " floppy-icon forward-icon harddisk-icon home-icon"
129 " leftarrow-icon messagebox-critical-icon"
130 " messagebox-information-icon messagebox-question-icon"
131 " messagebox-warning-icon network-icon rightarrow-icon"
132 " titlebar-contexthelp-icon titlebar-maximize-icon"
133 " titlebar-menu-icon titlebar-minimize-icon"
134 " titlebar-normal-icon titlebar-shade-icon"
135 " titlebar-unshade-icon trash-icon uparrow-icon"
136 )
137 elif kwSet == 2:
138 return (
139 "active adjoins-item alternate bottom checked closable"
140 " closed default disabled editable edit-focus enabled"
141 " exclusive first flat floatable focus has-children"
142 " has-siblings horizontal hover indeterminate last left"
143 " maximized middle minimized movable no-frame"
144 " non-exclusive off on only-one open next-selected"
145 " pressed previous-selected read-only right selected top"
146 " unchecked vertical window"
147 ""
148 " add-line add-page branch chunk close-button corner"
149 " down-arrow down-button drop-down float-button groove"
150 " indicator handle icon item left-arrow left-corner"
151 " menu-arrow menu-button menu-indicator right-arrow"
152 " pane right-corner scroller section separator sub-line"
153 " sub-page tab tab-bar tear tearoff text title up-arrow"
154 " up-button"
155 )
156
157 return None
158
159 def language(self):
160 """
161 Public method to return the lexer language.
162
163 @return lexer language (string)
164 """
165 return "QSS"
166
167 def lexerName(self):
168 """
169 Public method to return the lexer name.
170
171 @return lexer name (string)
172 """
173 return "QSS"

eric ide

mercurial