src/eric7/QScintilla/Lexers/LexerCSS.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 CSS 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 LexerCSS(Lexer, QsciLexerCSS):
19 """
20 Subclass to implement some additional lexer dependant 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 "color background-color background-image background-repeat"
91 " background-attachment background-position background"
92 " font-family font-style font-variant font-weight font-size"
93 " font word-spacing letter-spacing text-decoration"
94 " vertical-align text-transform text-align text-indent"
95 " line-height margin-top margin-right margin-bottom"
96 " margin-left margin padding-top padding-right padding-bottom"
97 " padding-left padding border-top-width border-right-width"
98 " border-bottom-width border-left-width border-width"
99 " border-top border-right border-bottom border-left border"
100 " border-color border-style width height float clear display"
101 " white-space list-style-type list-style-image"
102 " list-style-position list-style"
103 )
104
105 if kwSet == 2:
106 return (
107 "link active visited first-child focus hover lang left"
108 " right first empty enabled disabled checked not root target"
109 " only-child last-child nth-child nth-last-child first-of-type"
110 " last-of-type nth-of-type nth-last-of-type only-of-type valid"
111 " invalid required optional first-letter first-line before"
112 " after"
113 )
114
115 if kwSet == 3:
116 return (
117 "border-top-color border-right-color border-bottom-color"
118 " border-left-color border-color border-top-style"
119 " border-right-style border-bottom-style border-left-style"
120 " border-style top right bottom left position z-index"
121 " direction unicode-bidi min-width max-width min-height"
122 " max-height overflow clip visibility content quotes"
123 " counter-reset counter-increment marker-offset size marks"
124 " page-break-before page-break-after page-break-inside page"
125 " orphans widows font-stretch font-size-adjust unicode-range"
126 " units-per-em src panose-1 stemv stemh slope cap-height"
127 " x-height ascent descent widths bbox definition-src baseline"
128 " centerline mathline topline text-shadow caption-side"
129 " table-layout border-collapse border-spacing empty-cells"
130 " speak-header cursor outline outline-width outline-style"
131 " outline-color volume speak pause-before pause-after pause"
132 " cue-before cue-after cue play-during azimuth elevation"
133 " speech-rate voice-family pitch pitch-range stress richness"
134 " speak-punctuation speak-numeral"
135 )
136
137 if kwSet == 4:
138 return (
139 "background-size border-radius border-top-right-radius"
140 " border-bottom-right-radius border-bottom-left-radius"
141 " border-top-left-radius box-shadow columns column-width"
142 " column-count column-rule column-gap column-rule-color"
143 " column-rule-style column-rule-width resize opacity word-wrap"
144 )
145
146 if kwSet == 5:
147 return (
148 "first-letter first-line before after selection"
149 )
150
151 if kwSet == 6:
152 return (
153 "^-moz- ^-webkit- ^-o- ^-ms- filter"
154 )
155
156 if kwSet == 7:
157 return (
158 "indeterminate default ^-moz- ^-webkit- ^-o- ^-ms-"
159 )
160
161 if kwSet == 8:
162 return (
163 "selection ^-moz- ^-webkit- ^-o- ^-ms-"
164 )
165
166 return QsciLexerCSS.keywords(self, kwSet)

eric ide

mercurial