17 |
17 |
18 class LexerCSS(Lexer, QsciLexerCSS): |
18 class LexerCSS(Lexer, QsciLexerCSS): |
19 """ |
19 """ |
20 Subclass to implement some additional lexer dependant methods. |
20 Subclass to implement some additional lexer dependant methods. |
21 """ |
21 """ |
|
22 |
22 def __init__(self, parent=None): |
23 def __init__(self, parent=None): |
23 """ |
24 """ |
24 Constructor |
25 Constructor |
25 |
26 |
26 @param parent parent widget of this lexer |
27 @param parent parent widget of this lexer |
27 """ |
28 """ |
28 QsciLexerCSS.__init__(self, parent) |
29 QsciLexerCSS.__init__(self, parent) |
29 Lexer.__init__(self) |
30 Lexer.__init__(self) |
30 |
31 |
31 self.commentString = "#" |
32 self.commentString = "#" |
32 self.streamCommentString = { |
33 self.streamCommentString = {"start": "/* ", "end": " */"} |
33 'start': '/* ', |
34 |
34 'end': ' */' |
|
35 } |
|
36 |
|
37 self.keywordSetDescriptions = [ |
35 self.keywordSetDescriptions = [ |
38 self.tr("CSS1 Properties"), |
36 self.tr("CSS1 Properties"), |
39 self.tr("Pseudo-Classes"), |
37 self.tr("Pseudo-Classes"), |
40 self.tr("CSS2 Properties"), |
38 self.tr("CSS2 Properties"), |
41 self.tr("CSS3 Properties"), |
39 self.tr("CSS3 Properties"), |
42 self.tr("Pseudo-Elements"), |
40 self.tr("Pseudo-Elements"), |
43 self.tr("Browser-Specific CSS Properties"), |
41 self.tr("Browser-Specific CSS Properties"), |
44 self.tr("Browser-Specific Pseudo-Classes"), |
42 self.tr("Browser-Specific Pseudo-Classes"), |
45 self.tr("Browser-Specific Pseudo-Elements"), |
43 self.tr("Browser-Specific Pseudo-Elements"), |
46 ] |
44 ] |
47 |
45 |
48 def initProperties(self): |
46 def initProperties(self): |
49 """ |
47 """ |
50 Public slot to initialize the properties. |
48 Public slot to initialize the properties. |
51 """ |
49 """ |
52 self.setFoldComments(Preferences.getEditor("CssFoldComment")) |
50 self.setFoldComments(Preferences.getEditor("CssFoldComment")) |
53 self.setFoldCompact(Preferences.getEditor("AllFoldCompact")) |
51 self.setFoldCompact(Preferences.getEditor("AllFoldCompact")) |
54 with contextlib.suppress(AttributeError): |
52 with contextlib.suppress(AttributeError): |
55 self.setHSSLanguage( |
53 self.setHSSLanguage(Preferences.getEditor("CssHssSupport")) |
56 Preferences.getEditor("CssHssSupport")) |
54 self.setLessLanguage(Preferences.getEditor("CssLessSupport")) |
57 self.setLessLanguage( |
55 self.setSCSSLanguage(Preferences.getEditor("CssSassySupport")) |
58 Preferences.getEditor("CssLessSupport")) |
56 |
59 self.setSCSSLanguage( |
|
60 Preferences.getEditor("CssSassySupport")) |
|
61 |
|
62 def isCommentStyle(self, style): |
57 def isCommentStyle(self, style): |
63 """ |
58 """ |
64 Public method to check, if a style is a comment style. |
59 Public method to check, if a style is a comment style. |
65 |
60 |
66 @param style style to check (integer) |
61 @param style style to check (integer) |
67 @return flag indicating a comment style (boolean) |
62 @return flag indicating a comment style (boolean) |
68 """ |
63 """ |
69 return style in [QsciLexerCSS.Comment] |
64 return style in [QsciLexerCSS.Comment] |
70 |
65 |
71 def isStringStyle(self, style): |
66 def isStringStyle(self, style): |
72 """ |
67 """ |
73 Public method to check, if a style is a string style. |
68 Public method to check, if a style is a string style. |
74 |
69 |
75 @param style style to check (integer) |
70 @param style style to check (integer) |
76 @return flag indicating a string style (boolean) |
71 @return flag indicating a string style (boolean) |
77 """ |
72 """ |
78 return style in [QsciLexerCSS.DoubleQuotedString, |
73 return style in [ |
79 QsciLexerCSS.SingleQuotedString] |
74 QsciLexerCSS.DoubleQuotedString, |
80 |
75 QsciLexerCSS.SingleQuotedString, |
|
76 ] |
|
77 |
81 def defaultKeywords(self, kwSet): |
78 def defaultKeywords(self, kwSet): |
82 """ |
79 """ |
83 Public method to get the default keywords. |
80 Public method to get the default keywords. |
84 |
81 |
85 @param kwSet number of the keyword set (integer) |
82 @param kwSet number of the keyword set (integer) |
86 @return string giving the keywords (string) or None |
83 @return string giving the keywords (string) or None |
87 """ |
84 """ |
88 if kwSet == 1: |
85 if kwSet == 1: |
89 return ( |
86 return ( |
99 " border-top border-right border-bottom border-left border" |
96 " border-top border-right border-bottom border-left border" |
100 " border-color border-style width height float clear display" |
97 " border-color border-style width height float clear display" |
101 " white-space list-style-type list-style-image" |
98 " white-space list-style-type list-style-image" |
102 " list-style-position list-style" |
99 " list-style-position list-style" |
103 ) |
100 ) |
104 |
101 |
105 if kwSet == 2: |
102 if kwSet == 2: |
106 return ( |
103 return ( |
107 "link active visited first-child focus hover lang left" |
104 "link active visited first-child focus hover lang left" |
108 " right first empty enabled disabled checked not root target" |
105 " right first empty enabled disabled checked not root target" |
109 " only-child last-child nth-child nth-last-child first-of-type" |
106 " 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" |
107 " last-of-type nth-of-type nth-last-of-type only-of-type valid" |
111 " invalid required optional first-letter first-line before" |
108 " invalid required optional first-letter first-line before" |
112 " after" |
109 " after" |
113 ) |
110 ) |
114 |
111 |
115 if kwSet == 3: |
112 if kwSet == 3: |
116 return ( |
113 return ( |
117 "border-top-color border-right-color border-bottom-color" |
114 "border-top-color border-right-color border-bottom-color" |
118 " border-left-color border-color border-top-style" |
115 " border-left-color border-color border-top-style" |
119 " border-right-style border-bottom-style border-left-style" |
116 " border-right-style border-bottom-style border-left-style" |
131 " outline-color volume speak pause-before pause-after pause" |
128 " outline-color volume speak pause-before pause-after pause" |
132 " cue-before cue-after cue play-during azimuth elevation" |
129 " cue-before cue-after cue play-during azimuth elevation" |
133 " speech-rate voice-family pitch pitch-range stress richness" |
130 " speech-rate voice-family pitch pitch-range stress richness" |
134 " speak-punctuation speak-numeral" |
131 " speak-punctuation speak-numeral" |
135 ) |
132 ) |
136 |
133 |
137 if kwSet == 4: |
134 if kwSet == 4: |
138 return ( |
135 return ( |
139 "background-size border-radius border-top-right-radius" |
136 "background-size border-radius border-top-right-radius" |
140 " border-bottom-right-radius border-bottom-left-radius" |
137 " border-bottom-right-radius border-bottom-left-radius" |
141 " border-top-left-radius box-shadow columns column-width" |
138 " border-top-left-radius box-shadow columns column-width" |
142 " column-count column-rule column-gap column-rule-color" |
139 " column-count column-rule column-gap column-rule-color" |
143 " column-rule-style column-rule-width resize opacity word-wrap" |
140 " column-rule-style column-rule-width resize opacity word-wrap" |
144 ) |
141 ) |
145 |
142 |
146 if kwSet == 5: |
143 if kwSet == 5: |
147 return ( |
144 return "first-letter first-line before after selection" |
148 "first-letter first-line before after selection" |
145 |
149 ) |
|
150 |
|
151 if kwSet == 6: |
146 if kwSet == 6: |
152 return ( |
147 return "^-moz- ^-webkit- ^-o- ^-ms- filter" |
153 "^-moz- ^-webkit- ^-o- ^-ms- filter" |
148 |
154 ) |
|
155 |
|
156 if kwSet == 7: |
149 if kwSet == 7: |
157 return ( |
150 return "indeterminate default ^-moz- ^-webkit- ^-o- ^-ms-" |
158 "indeterminate default ^-moz- ^-webkit- ^-o- ^-ms-" |
151 |
159 ) |
|
160 |
|
161 if kwSet == 8: |
152 if kwSet == 8: |
162 return ( |
153 return "selection ^-moz- ^-webkit- ^-o- ^-ms-" |
163 "selection ^-moz- ^-webkit- ^-o- ^-ms-" |
154 |
164 ) |
|
165 |
|
166 return QsciLexerCSS.keywords(self, kwSet) |
155 return QsciLexerCSS.keywords(self, kwSet) |