6 """ |
6 """ |
7 Module implementing a custom lexer using pygments. |
7 Module implementing a custom lexer using pygments. |
8 """ |
8 """ |
9 |
9 |
10 from pygments.token import Token |
10 from pygments.token import Token |
11 from pygments.lexers import guess_lexer_for_filename, guess_lexer, find_lexer_class |
11 from pygments.lexers import guess_lexer_for_filename, guess_lexer, \ |
|
12 find_lexer_class |
12 from pygments.util import ClassNotFound |
13 from pygments.util import ClassNotFound |
13 |
14 |
14 from PyQt4.QtGui import QColor, QFont |
15 from PyQt4.QtGui import QColor, QFont |
15 |
16 |
16 from QScintilla.Lexers.LexerContainer import LexerContainer |
17 from QScintilla.Lexers.LexerContainer import LexerContainer |
303 Public method to get the default font for a style. |
304 Public method to get the default font for a style. |
304 |
305 |
305 @param style style number (integer) |
306 @param style style number (integer) |
306 @return font (QFont) |
307 @return font (QFont) |
307 """ |
308 """ |
308 if style in [PYGMENTS_COMMENT, PYGMENTS_PREPROCESSOR, PYGMENTS_MULTILINECOMMENT]: |
309 if style in [PYGMENTS_COMMENT, PYGMENTS_PREPROCESSOR, |
|
310 PYGMENTS_MULTILINECOMMENT]: |
309 if Utilities.isWindowsPlatform(): |
311 if Utilities.isWindowsPlatform(): |
310 f = QFont("Comic Sans MS", 9) |
312 f = QFont("Comic Sans MS", 9) |
311 else: |
313 else: |
312 f = QFont("Bitstream Vera Serif", 9) |
314 f = QFont("Bitstream Vera Serif", 9) |
313 if style == PYGMENTS_PREPROCESSOR: |
315 if style == PYGMENTS_PREPROCESSOR: |
318 if Utilities.isWindowsPlatform(): |
320 if Utilities.isWindowsPlatform(): |
319 return QFont("Comic Sans MS", 10) |
321 return QFont("Comic Sans MS", 10) |
320 else: |
322 else: |
321 return QFont("Bitstream Vera Serif", 10) |
323 return QFont("Bitstream Vera Serif", 10) |
322 |
324 |
323 if style in [PYGMENTS_KEYWORD, PYGMENTS_OPERATOR, PYGMENTS_WORD, PYGMENTS_BUILTIN, |
325 if style in [PYGMENTS_KEYWORD, PYGMENTS_OPERATOR, PYGMENTS_WORD, |
324 PYGMENTS_ATTRIBUTE, PYGMENTS_FUNCTION, PYGMENTS_CLASS, |
326 PYGMENTS_BUILTIN, PYGMENTS_ATTRIBUTE, PYGMENTS_FUNCTION, |
325 PYGMENTS_NAMESPACE, PYGMENTS_EXCEPTION, PYGMENTS_ENTITY, |
327 PYGMENTS_CLASS, PYGMENTS_NAMESPACE, PYGMENTS_EXCEPTION, |
326 PYGMENTS_TAG, PYGMENTS_SCALAR, PYGMENTS_ESCAPE, PYGMENTS_HEADING, |
328 PYGMENTS_ENTITY, PYGMENTS_TAG, PYGMENTS_SCALAR, |
327 PYGMENTS_SUBHEADING, PYGMENTS_STRONG, PYGMENTS_PROMPT]: |
329 PYGMENTS_ESCAPE, PYGMENTS_HEADING, PYGMENTS_SUBHEADING, |
|
330 PYGMENTS_STRONG, PYGMENTS_PROMPT]: |
328 f = LexerContainer.defaultFont(self, style) |
331 f = LexerContainer.defaultFont(self, style) |
329 f.setBold(True) |
332 f.setBold(True) |
330 return f |
333 return f |
331 |
334 |
332 if style in [PYGMENTS_DOCSTRING, PYGMENTS_EMPHASIZE]: |
335 if style in [PYGMENTS_DOCSTRING, PYGMENTS_EMPHASIZE]: |
466 |
470 |
467 @param style style to check (integer) |
471 @param style style to check (integer) |
468 @return flag indicating a string style (boolean) |
472 @return flag indicating a string style (boolean) |
469 """ |
473 """ |
470 return style in [PYGMENTS_STRING, PYGMENTS_DOCSTRING, PYGMENTS_OTHER, |
474 return style in [PYGMENTS_STRING, PYGMENTS_DOCSTRING, PYGMENTS_OTHER, |
471 PYGMENTS_HEADING, PYGMENTS_SUBHEADING, PYGMENTS_EMPHASIZE, |
475 PYGMENTS_HEADING, PYGMENTS_SUBHEADING, |
472 PYGMENTS_STRONG] |
476 PYGMENTS_EMPHASIZE, PYGMENTS_STRONG] |
473 |
477 |
474 def defaultKeywords(self, kwSet): |
478 def defaultKeywords(self, kwSet): |
475 """ |
479 """ |
476 Public method to get the default keywords. |
480 Public method to get the default keywords. |
477 |
481 |