QScintilla/QsciScintillaCompat.py

changeset 937
336c8f1ee7bb
parent 826
2e3e2055e715
child 938
f421f2138c0f
equal deleted inserted replaced
935:bf9ee1e00bc5 937:336c8f1ee7bb
11 from PyQt4.QtGui import QApplication, QPalette, QColor 11 from PyQt4.QtGui import QApplication, QPalette, QColor
12 from PyQt4.Qsci import QsciScintilla, \ 12 from PyQt4.Qsci import QsciScintilla, \
13 QSCINTILLA_VERSION as QsciQSCINTILLA_VERSION, QSCINTILLA_VERSION_STR 13 QSCINTILLA_VERSION as QsciQSCINTILLA_VERSION, QSCINTILLA_VERSION_STR
14 14
15 15
16 ##################################################################################### 16 ###############################################################################
17 17
18 def QSCINTILLA_VERSION(): 18 def QSCINTILLA_VERSION():
19 """ 19 """
20 Module function to return the QScintilla version. 20 Module function to return the QScintilla version.
21 21
27 if '-snapshot-' in QSCINTILLA_VERSION_STR: 27 if '-snapshot-' in QSCINTILLA_VERSION_STR:
28 return 0x99999 28 return 0x99999
29 else: 29 else:
30 return QsciQSCINTILLA_VERSION 30 return QsciQSCINTILLA_VERSION
31 31
32 ##################################################################################### 32 ###############################################################################
33 33
34 class QsciScintillaCompat(QsciScintilla): 34 class QsciScintillaCompat(QsciScintilla):
35 """ 35 """
36 Class implementing a compatability interface to QsciScintilla. 36 Class implementing a compatability interface to QsciScintilla.
37 37
127 """ 127 """
128 if isinstance(pos, int): 128 if isinstance(pos, int):
129 scipos = pos 129 scipos = pos
130 else: 130 else:
131 scipos = \ 131 scipos = \
132 self.SendScintilla(QsciScintilla.SCI_POSITIONFROMPOINT, pos.x(), pos.y()) 132 self.SendScintilla(QsciScintilla.SCI_POSITIONFROMPOINT,
133 pos.x(), pos.y())
133 line = self.SendScintilla(QsciScintilla.SCI_LINEFROMPOSITION, scipos) 134 line = self.SendScintilla(QsciScintilla.SCI_LINEFROMPOSITION, scipos)
134 if line >= self.lines(): 135 if line >= self.lines():
135 line = -1 136 line = -1
136 return line 137 return line
137 138
197 """ 198 """
198 Public method to get the character at a position in the text observing 199 Public method to get the character at a position in the text observing
199 multibyte characters. 200 multibyte characters.
200 201
201 @param pos position in the text (integer) 202 @param pos position in the text (integer)
202 @return character at the requested position or empty string, if the position 203 @return character at the requested position or empty string, if the
203 is negative or past the end of the document (string) 204 position is negative or past the end of the document (string)
204 """ 205 """
205 ch = self.byteAt(pos) 206 ch = self.byteAt(pos)
206 if ch and ord(ch) > 127 and self.isUtf8(): 207 if ch and ord(ch) > 127 and self.isUtf8():
207 if (ch[0] & 0xF0) == 0xF0: 208 if (ch[0] & 0xF0) == 0xF0:
208 utf8Len = 4 209 utf8Len = 4
217 else: 218 else:
218 return ch.decode() 219 return ch.decode()
219 220
220 def byteAt(self, pos): 221 def byteAt(self, pos):
221 """ 222 """
222 Public method to get the raw character (bytes) at a position in the text. 223 Public method to get the raw character (bytes) at a position in the
224 text.
223 225
224 @param pos position in the text (integer) 226 @param pos position in the text (integer)
225 @return raw character at the requested position or empty bytes, if the position 227 @return raw character at the requested position or empty bytes, if the
226 is negative or past the end of the document (bytes) 228 position is negative or past the end of the document (bytes)
227 """ 229 """
228 char = self.SendScintilla(QsciScintilla.SCI_GETCHARAT, pos) 230 char = self.SendScintilla(QsciScintilla.SCI_GETCHARAT, pos)
229 if char == 0: 231 if char == 0:
230 return b"" 232 return b""
231 if char < 0: 233 if char < 0:
239 @param line line number (integer) 241 @param line line number (integer)
240 @return fold level of the given line (integer) 242 @return fold level of the given line (integer)
241 """ 243 """
242 lvl = self.SendScintilla(QsciScintilla.SCI_GETFOLDLEVEL, line) 244 lvl = self.SendScintilla(QsciScintilla.SCI_GETFOLDLEVEL, line)
243 return \ 245 return \
244 (lvl & QsciScintilla.SC_FOLDLEVELNUMBERMASK) - QsciScintilla.SC_FOLDLEVELBASE 246 (lvl & QsciScintilla.SC_FOLDLEVELNUMBERMASK) - \
247 QsciScintilla.SC_FOLDLEVELBASE
245 248
246 def foldFlagsAt(self, line): 249 def foldFlagsAt(self, line):
247 """ 250 """
248 Public method to get the fold flags of a line of the document. 251 Public method to get the fold flags of a line of the document.
249 252
253 lvl = self.SendScintilla(QsciScintilla.SCI_GETFOLDLEVEL, line) 256 lvl = self.SendScintilla(QsciScintilla.SCI_GETFOLDLEVEL, line)
254 return lvl & ~QsciScintilla.SC_FOLDLEVELNUMBERMASK 257 return lvl & ~QsciScintilla.SC_FOLDLEVELNUMBERMASK
255 258
256 def foldHeaderAt(self, line): 259 def foldHeaderAt(self, line):
257 """ 260 """
258 Public method to determine, if a line of the document is a fold header line. 261 Public method to determine, if a line of the document is a fold header
262 line.
259 263
260 @param line line number (integer) 264 @param line line number (integer)
261 @return flag indicating a fold header line (boolean) 265 @return flag indicating a fold header line (boolean)
262 """ 266 """
263 lvl = self.SendScintilla(QsciScintilla.SCI_GETFOLDLEVEL, line) 267 lvl = self.SendScintilla(QsciScintilla.SCI_GETFOLDLEVEL, line)
288 @return indentation guide view (SC_IV_NONE, SC_IV_REAL, 292 @return indentation guide view (SC_IV_NONE, SC_IV_REAL,
289 SC_IV_LOOKFORWARD or SC_IV_LOOKBOTH) 293 SC_IV_LOOKFORWARD or SC_IV_LOOKBOTH)
290 """ 294 """
291 return self.SendScintilla(QsciScintilla.SCI_GETINDENTATIONGUIDES) 295 return self.SendScintilla(QsciScintilla.SCI_GETINDENTATIONGUIDES)
292 296
293 ##################################################################################### 297 ###########################################################################
294 # methods below are missing from QScintilla 298 # methods below are missing from QScintilla
295 ##################################################################################### 299 ###########################################################################
296 300
297 def zoomIn(self, zoom = 1): 301 def zoomIn(self, zoom = 1):
298 """ 302 """
299 Public method used to increase the zoom factor. 303 Public method used to increase the zoom factor.
300 304
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 """
636 """ 602 """
637 if self.__targetSearchStart == self.__targetSearchEnd: 603 if self.__targetSearchStart == self.__targetSearchEnd:
638 self.__targetSearchActive = False 604 self.__targetSearchActive = False
639 return False 605 return False
640 606
641 self.SendScintilla(QsciScintilla.SCI_SETTARGETSTART, self.__targetSearchStart) 607 self.SendScintilla(QsciScintilla.SCI_SETTARGETSTART,
642 self.SendScintilla(QsciScintilla.SCI_SETTARGETEND, self.__targetSearchEnd) 608 self.__targetSearchStart)
643 self.SendScintilla(QsciScintilla.SCI_SETSEARCHFLAGS, self.__targetSearchFlags) 609 self.SendScintilla(QsciScintilla.SCI_SETTARGETEND,
610 self.__targetSearchEnd)
611 self.SendScintilla(QsciScintilla.SCI_SETSEARCHFLAGS,
612 self.__targetSearchFlags)
644 targetSearchExpr = self._encodeString(self.__targetSearchExpr) 613 targetSearchExpr = self._encodeString(self.__targetSearchExpr)
645 pos = self.SendScintilla(QsciScintilla.SCI_SEARCHINTARGET, 614 pos = self.SendScintilla(QsciScintilla.SCI_SEARCHINTARGET,
646 len(targetSearchExpr), 615 len(targetSearchExpr),
647 targetSearchExpr) 616 targetSearchExpr)
648 617
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
897 @param margin margin number (integer) 872 @param margin margin number (integer)
898 """ 873 """
899 if style < self.ArrowFoldStyle: 874 if style < self.ArrowFoldStyle:
900 QsciScintilla.setFolding(self, style, margin) 875 QsciScintilla.setFolding(self, style, margin)
901 else: 876 else:
902 QsciScintilla.setFolding(self, QsciScintilla.PlainFoldStyle, margin) 877 QsciScintilla.setFolding(
878 self, QsciScintilla.PlainFoldStyle, margin)
903 879
904 if style == self.ArrowFoldStyle: 880 if style == self.ArrowFoldStyle:
905 self.__setFoldMarker(QsciScintilla.SC_MARKNUM_FOLDER, 881 self.__setFoldMarker(QsciScintilla.SC_MARKNUM_FOLDER,
906 QsciScintilla.SC_MARK_ARROW) 882 QsciScintilla.SC_MARK_ARROW)
907 self.__setFoldMarker(QsciScintilla.SC_MARKNUM_FOLDEROPEN, 883 self.__setFoldMarker(QsciScintilla.SC_MARKNUM_FOLDEROPEN,
969 QsciScintilla.SC_MARKNUM_FOLDEREND, foreColor) 945 QsciScintilla.SC_MARKNUM_FOLDEREND, foreColor)
970 self.SendScintilla(QsciScintilla.SCI_MARKERSETBACK, 946 self.SendScintilla(QsciScintilla.SCI_MARKERSETBACK,
971 QsciScintilla.SC_MARKNUM_FOLDEREND, backColor) 947 QsciScintilla.SC_MARKNUM_FOLDEREND, backColor)
972 948
973 949
974 ##################################################################################### 950 ###########################################################################
975 # interface methods to the standard keyboard command set 951 # interface methods to the standard keyboard command set
976 ##################################################################################### 952 ###########################################################################
977 953
978 def clearKeys(self): 954 def clearKeys(self):
979 """ 955 """
980 Protected method to clear the key commands. 956 Protected method to clear the key commands.
981 """ 957 """
987 Protected method to clear the alternate key commands. 963 Protected method to clear the alternate key commands.
988 """ 964 """
989 # call into the QsciCommandSet 965 # call into the QsciCommandSet
990 self.standardCommands().clearAlternateKeys() 966 self.standardCommands().clearAlternateKeys()
991 967
992 ##################################################################################### 968 ###########################################################################
993 # specialized event handlers 969 # specialized event handlers
994 ##################################################################################### 970 ###########################################################################
995 971
996 def focusOutEvent(self, event): 972 def focusOutEvent(self, event):
997 """ 973 """
998 Public method called when the editor loses focus. 974 Public method called when the editor loses focus.
999 975
1002 if self.isListActive(): 978 if self.isListActive():
1003 self.cancelList() 979 self.cancelList()
1004 980
1005 QsciScintilla.focusOutEvent(self, event) 981 QsciScintilla.focusOutEvent(self, event)
1006 982
1007 ##################################################################################### 983 ###########################################################################
1008 # interface methods to the mini editor 984 # interface methods to the mini editor
1009 ##################################################################################### 985 ###########################################################################
1010 986
1011 def getFileName(self): 987 def getFileName(self):
1012 """ 988 """
1013 Public method to return the name of the file being displayed. 989 Public method to return the name of the file being displayed.
1014 990
1021 try: 997 try:
1022 return p.getFileName() 998 return p.getFileName()
1023 except AttributeError: 999 except AttributeError:
1024 return "" 1000 return ""
1025 1001
1026 ##################################################################################### 1002 ###########################################################################
1027 # replacements for buggy methods 1003 # replacements for buggy methods
1028 ##################################################################################### 1004 ###########################################################################
1029 1005
1030 def showUserList(self, id, lst): 1006 def showUserList(self, id, lst):
1031 """ 1007 """
1032 Public method to show a user supplied list. 1008 Public method to show a user supplied list.
1033 1009
1040 self.SendScintilla(QsciScintilla.SCI_AUTOCSETSEPARATOR, 1016 self.SendScintilla(QsciScintilla.SCI_AUTOCSETSEPARATOR,
1041 ord(self.UserSeparator)) 1017 ord(self.UserSeparator))
1042 self.SendScintilla(QsciScintilla.SCI_USERLISTSHOW, id, 1018 self.SendScintilla(QsciScintilla.SCI_USERLISTSHOW, id,
1043 self._encodeString(self.UserSeparator.join(lst))) 1019 self._encodeString(self.UserSeparator.join(lst)))
1044 1020
1045 ##################################################################################### 1021 ###########################################################################
1046 # utility methods 1022 # utility methods
1047 ##################################################################################### 1023 ###########################################################################
1048 1024
1049 def _encodeString(self, string): 1025 def _encodeString(self, string):
1050 """ 1026 """
1051 Protected method to encode a string depending on the current mode. 1027 Protected method to encode a string depending on the current mode.
1052 1028
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.

eric ide

mercurial