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