164 def __init__(self, parent=None, name=""): |
164 def __init__(self, parent=None, name=""): |
165 """ |
165 """ |
166 Constructor |
166 Constructor |
167 |
167 |
168 @param parent parent widget of this lexer |
168 @param parent parent widget of this lexer |
169 @param name name of the pygments lexer to use (string) |
169 @type QWidget |
|
170 @param name name of the pygments lexer to use |
|
171 @type str |
170 """ |
172 """ |
171 super().__init__(parent) |
173 super().__init__(parent) |
172 |
174 |
173 self.__inReadSettings = False |
175 self.__inReadSettings = False |
174 |
176 |
393 def description(self, style): |
396 def description(self, style): |
394 """ |
397 """ |
395 Public method returning the descriptions of the styles supported |
398 Public method returning the descriptions of the styles supported |
396 by the lexer. |
399 by the lexer. |
397 |
400 |
398 @param style style number (integer) |
401 @param style style number |
399 @return description for the style (string) |
402 @type int |
|
403 @return description for the style |
|
404 @rtype str |
400 """ |
405 """ |
401 try: |
406 try: |
402 return self.descriptions[style] |
407 return self.descriptions[style] |
403 except KeyError: |
408 except KeyError: |
404 return "" |
409 return "" |
405 |
410 |
406 def defaultColor(self, style): |
411 def defaultColor(self, style): |
407 """ |
412 """ |
408 Public method to get the default foreground color for a style. |
413 Public method to get the default foreground color for a style. |
409 |
414 |
410 @param style style number (integer) |
415 @param style style number |
411 @return foreground color (QColor) |
416 @type int |
|
417 @return foreground color |
|
418 @rtype QColor |
412 """ |
419 """ |
413 try: |
420 try: |
414 return self.defaultColors[style] |
421 return self.defaultColors[style] |
415 except KeyError: |
422 except KeyError: |
416 return LexerContainer.defaultColor(self, style) |
423 return LexerContainer.defaultColor(self, style) |
417 |
424 |
418 def defaultPaper(self, style): |
425 def defaultPaper(self, style): |
419 """ |
426 """ |
420 Public method to get the default background color for a style. |
427 Public method to get the default background color for a style. |
421 |
428 |
422 @param style style number (integer) |
429 @param style style number |
423 @return background color (QColor) |
430 @type int |
|
431 @return background color |
|
432 @rtype QColor |
424 """ |
433 """ |
425 try: |
434 try: |
426 return self.defaultPapers[style] |
435 return self.defaultPapers[style] |
427 except KeyError: |
436 except KeyError: |
428 return LexerContainer.defaultPaper(self, style) |
437 return LexerContainer.defaultPaper(self, style) |
429 |
438 |
430 def defaultFont(self, style): |
439 def defaultFont(self, style): |
431 """ |
440 """ |
432 Public method to get the default font for a style. |
441 Public method to get the default font for a style. |
433 |
442 |
434 @param style style number (integer) |
443 @param style style number |
435 @return font (QFont) |
444 @type int |
|
445 @return font |
|
446 @rtype QFont |
436 """ |
447 """ |
437 if style in [ |
448 if style in [ |
438 PYGMENTS_COMMENT, |
449 PYGMENTS_COMMENT, |
439 PYGMENTS_PREPROCESSOR, |
450 PYGMENTS_PREPROCESSOR, |
440 PYGMENTS_MULTILINECOMMENT, |
451 PYGMENTS_MULTILINECOMMENT, |
489 |
500 |
490 def defaultEolFill(self, style): |
501 def defaultEolFill(self, style): |
491 """ |
502 """ |
492 Public method to get the default fill to eol flag. |
503 Public method to get the default fill to eol flag. |
493 |
504 |
494 @param style style number (integer) |
505 @param style style number |
495 @return fill to eol flag (boolean) |
506 @type int |
|
507 @return fill to eol flag |
|
508 @rtype bool |
496 """ |
509 """ |
497 try: |
510 try: |
498 return self.defaultEolFills[style] |
511 return self.defaultEolFills[style] |
499 except KeyError: |
512 except KeyError: |
500 return LexerContainer.defaultEolFill(self, style) |
513 return LexerContainer.defaultEolFill(self, style) |
501 |
514 |
502 def __guessLexer(self, text): |
515 def __guessLexer(self, text): |
503 """ |
516 """ |
504 Private method to guess a pygments lexer. |
517 Private method to guess a pygments lexer. |
505 |
518 |
506 @param text text to base guessing on (string) |
519 @param text text to base guessing on |
507 @return reference to the guessed lexer (pygments.lexer) |
520 @type str |
|
521 @return reference to the guessed lexer |
|
522 @rtype pygments.lexer |
508 """ |
523 """ |
509 lexer = None |
524 lexer = None |
510 |
525 |
511 if self.__pygmentsName: |
526 if self.__pygmentsName: |
512 lexerClass = find_lexer_class(self.__pygmentsName) |
527 lexerClass = find_lexer_class(self.__pygmentsName) |
544 |
560 |
545 def name(self): |
561 def name(self): |
546 """ |
562 """ |
547 Public method to get the name of the pygments lexer. |
563 Public method to get the name of the pygments lexer. |
548 |
564 |
549 @return name of the pygments lexer (string) |
565 @return name of the pygments lexer |
|
566 @rtype str |
550 """ |
567 """ |
551 if self.__lexer is None: |
568 if self.__lexer is None: |
552 return "" |
569 return "" |
553 else: |
570 else: |
554 return self.__lexer.name |
571 return self.__lexer.name |
555 |
572 |
556 def styleText(self, start, end): # noqa: U100 |
573 def styleText(self, start, end): # noqa: U100 |
557 """ |
574 """ |
558 Public method to perform the styling. |
575 Public method to perform the styling. |
559 |
576 |
560 @param start position of first character to be styled (integer) |
577 @param start position of first character to be styled |
561 @param end position of last character to be styled (integer) |
578 @type int |
|
579 @param end position of last character to be styled |
|
580 @type int |
562 """ |
581 """ |
563 text = self.editor.text()[: end + 1] |
582 text = self.editor.text()[: end + 1] |
564 textLen = len(text.encode("utf-8")) |
583 textLen = len(text.encode("utf-8")) |
565 self.__lexer = self.__guessLexer(text) |
584 self.__lexer = self.__guessLexer(text) |
566 |
585 |
593 |
612 |
594 def isCommentStyle(self, style): |
613 def isCommentStyle(self, style): |
595 """ |
614 """ |
596 Public method to check, if a style is a comment style. |
615 Public method to check, if a style is a comment style. |
597 |
616 |
598 @param style style to check (integer) |
617 @param style style to check |
599 @return flag indicating a comment style (boolean) |
618 @type int |
|
619 @return flag indicating a comment style |
|
620 @rtype bool |
600 """ |
621 """ |
601 return style in [PYGMENTS_COMMENT] |
622 return style in [PYGMENTS_COMMENT] |
602 |
623 |
603 def isStringStyle(self, style): |
624 def isStringStyle(self, style): |
604 """ |
625 """ |
605 Public method to check, if a style is a string style. |
626 Public method to check, if a style is a string style. |
606 |
627 |
607 @param style style to check (integer) |
628 @param style style to check |
608 @return flag indicating a string style (boolean) |
629 @type int |
|
630 @return flag indicating a string style |
|
631 @rtype bool |
609 """ |
632 """ |
610 return style in [ |
633 return style in [ |
611 PYGMENTS_STRING, |
634 PYGMENTS_STRING, |
612 PYGMENTS_DOCSTRING, |
635 PYGMENTS_DOCSTRING, |
613 PYGMENTS_OTHER, |
636 PYGMENTS_OTHER, |
619 |
642 |
620 def defaultKeywords(self, kwSet): # noqa: U100 |
643 def defaultKeywords(self, kwSet): # noqa: U100 |
621 """ |
644 """ |
622 Public method to get the default keywords. |
645 Public method to get the default keywords. |
623 |
646 |
624 @param kwSet number of the keyword set (integer) |
647 @param kwSet number of the keyword set |
625 @return string giving the keywords (string) or None |
648 @type int |
|
649 @return string giving the keywords or None |
|
650 @rtype str |
626 """ |
651 """ |
627 return None # __IGNORE_WARNING_M831__ |
652 return None # __IGNORE_WARNING_M831__ |
628 |
653 |
629 def commentStr(self): |
654 def commentStr(self): |
630 """ |
655 """ |