QScintilla/Lexers/LexerContainer.py

changeset 0
de9c2efb9d02
child 12
1d8dd9706f46
equal deleted inserted replaced
-1:000000000000 0:de9c2efb9d02
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2008 - 2009 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a base class for custom lexers.
8 """
9
10 from PyQt4.Qsci import QsciLexer
11
12 from Lexer import Lexer
13
14 class LexerContainer(QsciLexer, Lexer):
15 """
16 Subclass as a base for the implementation of custom lexers.
17 """
18 def __init__(self, parent = None):
19 """
20 Constructor
21
22 @param parent parent widget of this lexer
23 """
24 QsciLexer.__init__(self, parent)
25 Lexer.__init__(self)
26
27 self.editor = parent
28
29 def language(self):
30 """
31 Public method returning the language of the lexer.
32
33 @return language of the lexer (string)
34 """
35 return "Container"
36
37 def lexer(self):
38 """
39 Public method returning the type of the lexer.
40
41 @return type of the lexer (string)
42 """
43 if hasattr(self, 'lexerId'):
44 return None
45 else:
46 return "container"
47
48 def description(self, style):
49 """
50 Public method returning the descriptions of the styles supported
51 by the lexer.
52
53 <b>Note</b>: This methods needs to be overridden by the lexer class.
54
55 @param style style number (integer)
56 @return description for the given style (string)
57 """
58 return ""
59
60 def styleBitsNeeded(self):
61 """
62 Public method to get the number of style bits needed by the lexer.
63
64 @return number of style bits needed (integer)
65 """
66 return 5
67
68 def styleText(self, start, end):
69 """
70 Public method to perform the styling.
71
72 @param start position of first character to be styled (integer)
73 @param end position of last character to be styled (integer)
74 """
75 self.editor.startStyling(start, 0x1f)
76 self.editor.setStyling(end - start + 1, 0)

eric ide

mercurial