eric6/QScintilla/Lexers/LexerCSS.py

changeset 6942
2602857055c5
parent 6874
5a3a39442711
child 7229
53054eb5b15a
equal deleted inserted replaced
6941:f99d60d6b59b 6942:2602857055c5
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2005 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a CSS lexer with some additional methods.
8 """
9
10 from __future__ import unicode_literals
11
12 from PyQt5.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 try:
55 self.setHSSLanguage(
56 Preferences.getEditor("CssHssSupport"))
57 self.setLessLanguage(
58 Preferences.getEditor("CssLessSupport"))
59 self.setSCSSLanguage(
60 Preferences.getEditor("CssSassySupport"))
61 except AttributeError:
62 pass
63
64 def isCommentStyle(self, style):
65 """
66 Public method to check, if a style is a comment style.
67
68 @param style style to check (integer)
69 @return flag indicating a comment style (boolean)
70 """
71 return style in [QsciLexerCSS.Comment]
72
73 def isStringStyle(self, style):
74 """
75 Public method to check, if a style is a string style.
76
77 @param style style to check (integer)
78 @return flag indicating a string style (boolean)
79 """
80 return style in [QsciLexerCSS.DoubleQuotedString,
81 QsciLexerCSS.SingleQuotedString]
82
83 def defaultKeywords(self, kwSet):
84 """
85 Public method to get the default keywords.
86
87 @param kwSet number of the keyword set (integer)
88 @return string giving the keywords (string) or None
89 """
90 if kwSet == 1:
91 return (
92 "color background-color background-image background-repeat"
93 " background-attachment background-position background"
94 " font-family font-style font-variant font-weight font-size"
95 " font word-spacing letter-spacing text-decoration"
96 " vertical-align text-transform text-align text-indent"
97 " line-height margin-top margin-right margin-bottom"
98 " margin-left margin padding-top padding-right padding-bottom"
99 " padding-left padding border-top-width border-right-width"
100 " border-bottom-width border-left-width border-width"
101 " border-top border-right border-bottom border-left border"
102 " border-color border-style width height float clear display"
103 " white-space list-style-type list-style-image"
104 " list-style-position list-style"
105 )
106
107 if kwSet == 2:
108 return (
109 "link active visited first-child focus hover lang left"
110 " right first empty enabled disabled checked not root target"
111 " only-child last-child nth-child nth-last-child first-of-type"
112 " last-of-type nth-of-type nth-last-of-type only-of-type valid"
113 " invalid required optional first-letter first-line before"
114 " after"
115 )
116
117 if kwSet == 3:
118 return (
119 "border-top-color border-right-color border-bottom-color"
120 " border-left-color border-color border-top-style"
121 " border-right-style border-bottom-style border-left-style"
122 " border-style top right bottom left position z-index"
123 " direction unicode-bidi min-width max-width min-height"
124 " max-height overflow clip visibility content quotes"
125 " counter-reset counter-increment marker-offset size marks"
126 " page-break-before page-break-after page-break-inside page"
127 " orphans widows font-stretch font-size-adjust unicode-range"
128 " units-per-em src panose-1 stemv stemh slope cap-height"
129 " x-height ascent descent widths bbox definition-src baseline"
130 " centerline mathline topline text-shadow caption-side"
131 " table-layout border-collapse border-spacing empty-cells"
132 " speak-header cursor outline outline-width outline-style"
133 " outline-color volume speak pause-before pause-after pause"
134 " cue-before cue-after cue play-during azimuth elevation"
135 " speech-rate voice-family pitch pitch-range stress richness"
136 " speak-punctuation speak-numeral"
137 )
138
139 if kwSet == 4:
140 return (
141 "background-size border-radius border-top-right-radius"
142 " border-bottom-right-radius border-bottom-left-radius"
143 " border-top-left-radius box-shadow columns column-width"
144 " column-count column-rule column-gap column-rule-color"
145 " column-rule-style column-rule-width resize opacity word-wrap"
146 )
147
148 if kwSet == 5:
149 return (
150 "first-letter first-line before after selection"
151 )
152
153 if kwSet == 6:
154 return (
155 "^-moz- ^-webkit- ^-o- ^-ms- filter"
156 )
157
158 if kwSet == 7:
159 return (
160 "indeterminate default ^-moz- ^-webkit- ^-o- ^-ms-"
161 )
162
163 if kwSet == 8:
164 return (
165 "selection ^-moz- ^-webkit- ^-o- ^-ms-"
166 )
167
168 return QsciLexerCSS.keywords(self, kwSet)

eric ide

mercurial