518 else: |
522 else: |
519 return None |
523 return None |
520 |
524 |
521 def getCursorFlashTime(self): |
525 def getCursorFlashTime(self): |
522 """ |
526 """ |
523 Public method to get the flash (blink) time of the cursor in milliseconds. |
527 Public method to get the flash (blink) time of the cursor in |
|
528 milliseconds. |
524 |
529 |
525 The flash time is the time required to display, invert and restore the |
530 The flash time is the time required to display, invert and restore the |
526 caret display. Usually the text cursor is displayed for half the cursor |
531 caret display. Usually the text cursor is displayed for half the cursor |
527 flash time, then hidden for the same amount of time. |
532 flash time, then hidden for the same amount of time. |
528 |
533 |
529 @return flash time of the cursor in milliseconds (integer) |
534 @return flash time of the cursor in milliseconds (integer) |
530 """ |
535 """ |
531 return 2 * self.SendScintilla(QsciScintilla.SCI_GETCARETPERIOD) |
536 return 2 * self.SendScintilla(QsciScintilla.SCI_GETCARETPERIOD) |
532 |
537 |
533 def setCursorFlashTime(self, time): |
538 def setCursorFlashTime(self, time): |
534 """ |
539 """ |
535 Public method to get the flash (blink) time of the cursor in milliseconds. |
540 Public method to get the flash (blink) time of the cursor in |
|
541 milliseconds. |
536 |
542 |
537 The flash time is the time required to display, invert and restore the |
543 The flash time is the time required to display, invert and restore the |
538 caret display. Usually the text cursor is displayed for half the cursor |
544 caret display. Usually the text cursor is displayed for half the cursor |
539 flash time, then hidden for the same amount of time. |
545 flash time, then hidden for the same amount of time. |
540 |
546 |
541 @param time flash time of the cursor in milliseconds (integer) |
547 @param time flash time of the cursor in milliseconds (integer) |
542 """ |
548 """ |
543 self.SendScintilla(QsciScintilla.SCI_SETCARETPERIOD, time // 2) |
549 self.SendScintilla(QsciScintilla.SCI_SETCARETPERIOD, time // 2) |
544 |
550 |
545 ##################################################################################### |
551 ########################################################################### |
546 # methods to perform searches in target range |
552 # methods to perform searches in target range |
547 ##################################################################################### |
553 ########################################################################### |
548 |
554 |
549 def positionFromPoint(self, point): |
555 def positionFromPoint(self, point): |
550 """ |
556 """ |
551 Public method to calculate the scintilla position from a point in the window. |
557 Public method to calculate the scintilla position from a point in the |
|
558 window. |
552 |
559 |
553 @param point point in the window (QPoint) |
560 @param point point in the window (QPoint) |
554 @return scintilla position (integer) or -1 to indicate, that the point is not |
561 @return scintilla position (integer) or -1 to indicate, that the point |
555 near any character |
562 is not near any character |
556 """ |
563 """ |
557 return self.SendScintilla(QsciScintilla.SCI_POSITIONFROMPOINTCLOSE, |
564 return self.SendScintilla(QsciScintilla.SCI_POSITIONFROMPOINTCLOSE, |
558 point.x(), point.y()) |
565 point.x(), point.y()) |
559 |
566 |
560 def positionBefore(self, pos): |
567 def positionBefore(self, pos): |
561 """ |
568 """ |
562 Public method to get the position before the given position taking into account |
569 Public method to get the position before the given position taking into |
563 multibyte characters. |
570 account multibyte characters. |
564 |
571 |
565 @param pos position (integer) |
572 @param pos position (integer) |
566 @return position before the given one (integer) |
573 @return position before the given one (integer) |
567 """ |
574 """ |
568 return self.SendScintilla(QsciScintilla.SCI_POSITIONBEFORE, pos) |
575 return self.SendScintilla(QsciScintilla.SCI_POSITIONBEFORE, pos) |
569 |
576 |
570 def positionAfter(self, pos): |
577 def positionAfter(self, pos): |
571 """ |
578 """ |
572 Public method to get the position after the given position taking into account |
579 Public method to get the position after the given position taking into |
573 multibyte characters. |
580 account multibyte characters. |
574 |
581 |
575 @param pos position (integer) |
582 @param pos position (integer) |
576 @return position after the given one (integer) |
583 @return position after the given one (integer) |
577 """ |
584 """ |
578 return self.SendScintilla(QsciScintilla.SCI_POSITIONAFTER, pos) |
585 return self.SendScintilla(QsciScintilla.SCI_POSITIONAFTER, pos) |
579 |
586 |
580 def positionFromLineIndex(self, line, index): |
587 def lineEndPosition(self, line): |
581 """ |
588 """ |
582 Public method to convert line and index to an absolute position. |
589 Public method to determine the line end position of the given line. |
583 |
590 |
584 @param line line number (integer) |
591 @param line line number (integer) |
585 @param index index number (integer) |
592 @return position of the line end disregarding line end characters |
586 @return absolute position in the editor (integer) |
593 (integer) |
587 """ |
|
588 pos = self.SendScintilla(QsciScintilla.SCI_POSITIONFROMLINE, line) |
|
589 |
|
590 # Allow for multi-byte characters |
|
591 for i in range(index): |
|
592 pos = self.positionAfter(pos) |
|
593 |
|
594 return pos |
|
595 |
|
596 def lineIndexFromPosition(self, pos): |
|
597 """ |
|
598 Public method to convert an absolute position to line and index. |
|
599 |
|
600 @param pos absolute position in the editor (integer) |
|
601 @return tuple of line number (integer) and index number (integer) |
|
602 """ |
|
603 lin = self.SendScintilla(QsciScintilla.SCI_LINEFROMPOSITION, pos) |
|
604 linpos = self.SendScintilla(QsciScintilla.SCI_POSITIONFROMLINE, lin) |
|
605 indx = 0 |
|
606 |
|
607 # Allow for multi-byte characters. |
|
608 while linpos < pos: |
|
609 new_linpos = self.positionAfter(linpos) |
|
610 |
|
611 # If the position hasn't moved then we must be at the end of the text |
|
612 # (which implies that the position passed was beyond the end of the |
|
613 # text). |
|
614 if new_linpos == linpos: |
|
615 break |
|
616 |
|
617 linpos = new_linpos |
|
618 indx += 1 |
|
619 |
|
620 return lin, indx |
|
621 |
|
622 def lineEndPosition(self, line): |
|
623 """ |
|
624 Public method to determine the line end position of the given line. |
|
625 |
|
626 @param line line number (integer) |
|
627 @return position of the line end disregarding line end characters (integer) |
|
628 """ |
594 """ |
629 return self.SendScintilla(QsciScintilla.SCI_GETLINEENDPOSITION, line) |
595 return self.SendScintilla(QsciScintilla.SCI_GETLINEENDPOSITION, line) |
630 |
596 |
631 def __doSearchTarget(self): |
597 def __doSearchTarget(self): |
632 """ |
598 """ |
700 self.__targetSearchFlags |= QsciScintilla.SCFIND_WHOLEWORD |
669 self.__targetSearchFlags |= QsciScintilla.SCFIND_WHOLEWORD |
701 if ws_: |
670 if ws_: |
702 self.__targetSearchFlags |= QsciScintilla.SCFIND_WORDSTART |
671 self.__targetSearchFlags |= QsciScintilla.SCFIND_WORDSTART |
703 |
672 |
704 if begline < 0 or begindex < 0: |
673 if begline < 0 or begindex < 0: |
705 self.__targetSearchStart = self.SendScintilla(QsciScintilla.SCI_GETCURRENTPOS) |
674 self.__targetSearchStart = self.SendScintilla( |
|
675 QsciScintilla.SCI_GETCURRENTPOS) |
706 else: |
676 else: |
707 self.__targetSearchStart = self.positionFromLineIndex(begline, begindex) |
677 self.__targetSearchStart = self.positionFromLineIndex( |
|
678 begline, begindex) |
708 |
679 |
709 if endline < 0 or endindex < 0: |
680 if endline < 0 or endindex < 0: |
710 self.__targetSearchEnd = self.SendScintilla(QsciScintilla.SCI_GETTEXTLENGTH) |
681 self.__targetSearchEnd = self.SendScintilla( |
|
682 QsciScintilla.SCI_GETTEXTLENGTH) |
711 else: |
683 else: |
712 self.__targetSearchEnd = self.positionFromLineIndex(endline, endindex) |
684 self.__targetSearchEnd = self.positionFromLineIndex( |
|
685 endline, endindex) |
713 |
686 |
714 self.__targetSearchExpr = expr_ |
687 self.__targetSearchExpr = expr_ |
715 |
688 |
716 if self.__targetSearchExpr: |
689 if self.__targetSearchExpr: |
717 self.__targetSearchActive = True |
690 self.__targetSearchActive = True |
749 start = self.SendScintilla(QsciScintilla.SCI_GETTARGETSTART) |
722 start = self.SendScintilla(QsciScintilla.SCI_GETTARGETSTART) |
750 self.SendScintilla(cmd, len(r), r) |
723 self.SendScintilla(cmd, len(r), r) |
751 |
724 |
752 self.__targetSearchStart = start + len(r) |
725 self.__targetSearchStart = start + len(r) |
753 |
726 |
754 ##################################################################################### |
727 ########################################################################### |
755 # indicator handling methods |
728 # indicator handling methods |
756 ##################################################################################### |
729 ########################################################################### |
757 |
730 |
758 def indicatorDefine(self, indicator, style, color): |
731 def indicatorDefine(self, indicator, style, color): |
759 """ |
732 """ |
760 Public method to define the appearance of an indicator. |
733 Public method to define the appearance of an indicator. |
761 |
734 |
762 @param indicator number of the indicator (integer, |
735 @param indicator number of the indicator (integer, |
763 QsciScintilla.INDIC_CONTAINER .. QsciScintilla.INDIC_MAX) |
736 QsciScintilla.INDIC_CONTAINER .. QsciScintilla.INDIC_MAX) |
764 @param style style to be used for the indicator (QsciScintilla.INDIC_PLAIN, |
737 @param style style to be used for the indicator |
765 QsciScintilla.INDIC_SQUIGGLE, QsciScintilla.INDIC_TT, |
738 (QsciScintilla.INDIC_PLAIN, QsciScintilla.INDIC_SQUIGGLE, |
766 QsciScintilla.INDIC_DIAGONAL, QsciScintilla.INDIC_STRIKE, |
739 QsciScintilla.INDIC_TT, QsciScintilla.INDIC_DIAGONAL, |
767 QsciScintilla.INDIC_HIDDEN, QsciScintilla.INDIC_BOX, |
740 QsciScintilla.INDIC_STRIKE, QsciScintilla.INDIC_HIDDEN, |
768 QsciScintilla.INDIC_ROUNDBOX) |
741 QsciScintilla.INDIC_BOX, QsciScintilla.INDIC_ROUNDBOX) |
769 @param color color to be used by the indicator (QColor) |
742 @param color color to be used by the indicator (QColor) |
770 @exception ValueError the indicator or style are not valid |
743 @exception ValueError the indicator or style are not valid |
771 """ |
744 """ |
772 if indicator < QsciScintilla.INDIC_CONTAINER or \ |
745 if indicator < QsciScintilla.INDIC_CONTAINER or \ |
773 indicator > QsciScintilla.INDIC_MAX: |
746 indicator > QsciScintilla.INDIC_MAX: |
774 raise ValueError("indicator number out of range") |
747 raise ValueError("indicator number out of range") |
775 |
748 |
776 if style < QsciScintilla.INDIC_PLAIN or style > QsciScintilla.INDIC_ROUNDBOX: |
749 if style < QsciScintilla.INDIC_PLAIN or \ |
|
750 style > QsciScintilla.INDIC_ROUNDBOX: |
777 raise ValueError("style out of range") |
751 raise ValueError("style out of range") |
778 |
752 |
779 self.SendScintilla(QsciScintilla.SCI_INDICSETSTYLE, indicator, style) |
753 self.SendScintilla(QsciScintilla.SCI_INDICSETSTYLE, indicator, style) |
780 self.SendScintilla(QsciScintilla.SCI_INDICSETFORE, indicator, color) |
754 self.SendScintilla(QsciScintilla.SCI_INDICSETFORE, indicator, color) |
781 |
755 |
865 @param indicator number of the indicator (integer, |
839 @param indicator number of the indicator (integer, |
866 QsciScintilla.INDIC_CONTAINER .. QsciScintilla.INDIC_MAX) |
840 QsciScintilla.INDIC_CONTAINER .. QsciScintilla.INDIC_MAX) |
867 @param pos position to test (integer) |
841 @param pos position to test (integer) |
868 @return flag indicating the existence of the indicator (boolean) |
842 @return flag indicating the existence of the indicator (boolean) |
869 """ |
843 """ |
870 res = self.SendScintilla(QsciScintilla.SCI_INDICATORVALUEAT, indicator, pos) |
844 res = self.SendScintilla(QsciScintilla.SCI_INDICATORVALUEAT, |
|
845 indicator, pos) |
871 return res |
846 return res |
872 |
847 |
873 ##################################################################################### |
848 ########################################################################### |
874 # methods to perform folding related stuff |
849 # methods to perform folding related stuff |
875 ##################################################################################### |
850 ########################################################################### |
876 |
851 |
877 def __setFoldMarker(self, marknr, mark = QsciScintilla.SC_MARK_EMPTY): |
852 def __setFoldMarker(self, marknr, mark = QsciScintilla.SC_MARK_EMPTY): |
878 """ |
853 """ |
879 Private method to define a fold marker. |
854 Private method to define a fold marker. |
880 |
855 |
1059 if self.isUtf8(): |
1035 if self.isUtf8(): |
1060 return string.encode("utf-8") |
1036 return string.encode("utf-8") |
1061 else: |
1037 else: |
1062 return string.encode("latin-1") |
1038 return string.encode("latin-1") |
1063 |
1039 |
1064 ## ##################################################################################### |
1040 ########################################################################### |
1065 ## # methods below have been added to QScintilla starting with version after 2.x |
1041 # methods below have been added to QScintilla starting with version 2.5 |
1066 ## ##################################################################################### |
1042 ########################################################################### |
|
1043 |
|
1044 if "positionFromLineIndex" not in QsciScintilla.__dict__: |
|
1045 def positionFromLineIndex(self, line, index): |
|
1046 """ |
|
1047 Public method to convert line and index to an absolute position. |
|
1048 |
|
1049 @param line line number (integer) |
|
1050 @param index index number (integer) |
|
1051 @return absolute position in the editor (integer) |
|
1052 """ |
|
1053 pos = self.SendScintilla(QsciScintilla.SCI_POSITIONFROMLINE, line) |
|
1054 |
|
1055 # Allow for multi-byte characters |
|
1056 for i in range(index): |
|
1057 pos = self.positionAfter(pos) |
|
1058 |
|
1059 return pos |
|
1060 |
|
1061 if "lineIndexFromPosition" not in QsciScintilla.__dict__: |
|
1062 def lineIndexFromPosition(self, pos): |
|
1063 """ |
|
1064 Public method to convert an absolute position to line and index. |
|
1065 |
|
1066 @param pos absolute position in the editor (integer) |
|
1067 @return tuple of line number (integer) and index number (integer) |
|
1068 """ |
|
1069 lin = self.SendScintilla(QsciScintilla.SCI_LINEFROMPOSITION, pos) |
|
1070 linpos = self.SendScintilla( |
|
1071 QsciScintilla.SCI_POSITIONFROMLINE, lin) |
|
1072 indx = 0 |
|
1073 |
|
1074 # Allow for multi-byte characters. |
|
1075 while linpos < pos: |
|
1076 new_linpos = self.positionAfter(linpos) |
|
1077 |
|
1078 # If the position hasn't moved then we must be at the end of |
|
1079 # the text (which implies that the position passed was beyond |
|
1080 # the end of the text). |
|
1081 if new_linpos == linpos: |
|
1082 break |
|
1083 |
|
1084 linpos = new_linpos |
|
1085 indx += 1 |
|
1086 |
|
1087 return lin, indx |
|
1088 |
|
1089 ## ######################################################################### |
|
1090 ## # methods below have been added to QScintilla starting with version 2.x |
|
1091 ## ######################################################################### |
1067 ## |
1092 ## |
1068 ## if "newMethod" not in QsciScintilla.__dict__: |
1093 ## if "newMethod" not in QsciScintilla.__dict__: |
1069 ## def newMethod(self, param): |
1094 ## def newMethod(self, param): |
1070 ## """ |
1095 ## """ |
1071 ## Public method to do something. |
1096 ## Public method to do something. |