QScintilla/QsciScintillaCompat.py

branch
Py2 comp.
changeset 3080
6c0a430b19df
parent 3060
5883ce99ee12
parent 3078
b9422535d0fe
child 3145
a9de05d4a22f
equal deleted inserted replaced
3079:0233bbe9a9c4 3080:6c0a430b19df
9 9
10 from __future__ import unicode_literals # __IGNORE_WARNING__ 10 from __future__ import unicode_literals # __IGNORE_WARNING__
11 11
12 from PyQt4.QtCore import pyqtSignal, Qt 12 from PyQt4.QtCore import pyqtSignal, Qt
13 from PyQt4.QtGui import QPalette, QColor, QApplication 13 from PyQt4.QtGui import QPalette, QColor, QApplication
14 from PyQt4.Qsci import QsciScintilla, \ 14 from PyQt4.Qsci import QsciScintillaBase, QsciScintilla, \
15 QSCINTILLA_VERSION as QSCIQSCINTILLA_VERSION, QSCINTILLA_VERSION_STR, \ 15 QSCINTILLA_VERSION as QSCIQSCINTILLA_VERSION
16 QsciScintillaBase
17 16
18 ############################################################################### 17 ###############################################################################
19 18
20 19
21 def QSCINTILLA_VERSION(): 20 def QSCINTILLA_VERSION():
22 """ 21 """
23 Module function to return the QScintilla version. 22 Module function to return the QScintilla version.
24 23
25 If the installed QScintilla is a snapshot version, then assume it is
26 of the latest release and return a version number of 0x99999.
27
28 @return QScintilla version (integer) 24 @return QScintilla version (integer)
29 """ 25 """
30 if '-snapshot-' in QSCINTILLA_VERSION_STR: 26 return QSCIQSCINTILLA_VERSION
31 return 0x99999
32 else:
33 return QSCIQSCINTILLA_VERSION
34 27
35 ############################################################################### 28 ###############################################################################
36 29
37 30
38 class QsciScintillaCompat(QsciScintilla): 31 class QsciScintillaCompat(QsciScintilla):
49 42
50 ArrowFoldStyle = QsciScintilla.BoxedTreeFoldStyle + 1 43 ArrowFoldStyle = QsciScintilla.BoxedTreeFoldStyle + 1
51 ArrowTreeFoldStyle = ArrowFoldStyle + 1 44 ArrowTreeFoldStyle = ArrowFoldStyle + 1
52 45
53 UserSeparator = '\x04' 46 UserSeparator = '\x04'
47
48 if QSCINTILLA_VERSION() < 0x020600:
49 IndicatorStyleMax = QsciScintilla.INDIC_ROUNDBOX
50 elif QSCINTILLA_VERSION() < 0x020700:
51 IndicatorStyleMax = QsciScintilla.INDIC_DOTBOX
52 elif QSCINTILLA_VERSION() < 0x020800:
53 IndicatorStyleMax = QsciScintilla.INDIC_SQUIGGLEPIXMAP
54 else:
55 IndicatorStyleMax = QsciScintilla.INDIC_COMPOSITIONTHICK
54 56
55 def __init__(self, parent=None): 57 def __init__(self, parent=None):
56 """ 58 """
57 Constructor 59 Constructor
58 60
669 671
670 @param time flash time of the cursor in milliseconds (integer) 672 @param time flash time of the cursor in milliseconds (integer)
671 """ 673 """
672 self.SendScintilla(QsciScintilla.SCI_SETCARETPERIOD, time // 2) 674 self.SendScintilla(QsciScintilla.SCI_SETCARETPERIOD, time // 2)
673 675
676 def getCaretLineAlwaysVisible(self):
677 """
678 Public method to determine, if the caret line is visible even if
679 the editor doesn't have the focus.
680
681 @return flag indicating an always visible caret line (boolean)
682 """
683 try:
684 return self.SendScintilla(
685 QsciScintilla.SCI_GETCARETLINEVISIBLEALWAYS)
686 except AttributeError:
687 return False
688
689 def setCaretLineAlwaysVisible(self, alwaysVisible):
690 """
691 Public method to set the caret line visible even if the editor doesn't
692 have the focus.
693
694 @param alwaysVisible flag indicating that the caret line shall be
695 visible even if the editor doesn't have the focus (boolean)
696 """
697 try:
698 self.SendScintilla(
699 QsciScintilla.SCI_SETCARETLINEVISIBLEALWAYS, alwaysVisible)
700 except AttributeError:
701 pass
702
674 ########################################################################### 703 ###########################################################################
675 # methods to perform searches in target range 704 # methods to perform searches in target range
676 ########################################################################### 705 ###########################################################################
677 706
678 def positionFromPoint(self, point): 707 def positionFromPoint(self, point):
859 QsciScintilla.INDIC_CONTAINER .. QsciScintilla.INDIC_MAX) 888 QsciScintilla.INDIC_CONTAINER .. QsciScintilla.INDIC_MAX)
860 @param style style to be used for the indicator 889 @param style style to be used for the indicator
861 (QsciScintilla.INDIC_PLAIN, QsciScintilla.INDIC_SQUIGGLE, 890 (QsciScintilla.INDIC_PLAIN, QsciScintilla.INDIC_SQUIGGLE,
862 QsciScintilla.INDIC_TT, QsciScintilla.INDIC_DIAGONAL, 891 QsciScintilla.INDIC_TT, QsciScintilla.INDIC_DIAGONAL,
863 QsciScintilla.INDIC_STRIKE, QsciScintilla.INDIC_HIDDEN, 892 QsciScintilla.INDIC_STRIKE, QsciScintilla.INDIC_HIDDEN,
864 QsciScintilla.INDIC_BOX, QsciScintilla.INDIC_ROUNDBOX) 893 QsciScintilla.INDIC_BOX, QsciScintilla.INDIC_ROUNDBOX,
894 QsciScintilla.INDIC_STRAIGHTBOX, QsciScintilla.INDIC_DASH,
895 QsciScintilla.INDIC_DOTS, QsciScintilla.INDIC_SQUIGGLELOW,
896 QsciScintilla.INDIC_DOTBOX, QsciScintilla.INDIC_SQUIGGLEPIXMAP,
897 QsciScintilla.INDIC_COMPOSITIONTHICK depending upon QScintilla
898 version)
865 @param color color to be used by the indicator (QColor) 899 @param color color to be used by the indicator (QColor)
866 @exception ValueError the indicator or style are not valid 900 @exception ValueError the indicator or style are not valid
867 """ 901 """
868 if indicator < QsciScintilla.INDIC_CONTAINER or \ 902 if indicator < QsciScintilla.INDIC_CONTAINER or \
869 indicator > QsciScintilla.INDIC_MAX: 903 indicator > QsciScintilla.INDIC_MAX:
870 raise ValueError("indicator number out of range") 904 raise ValueError("indicator number out of range")
871 905
872 if style < QsciScintilla.INDIC_PLAIN or \ 906 if style < QsciScintilla.INDIC_PLAIN or \
873 style > QsciScintilla.INDIC_ROUNDBOX: 907 style > self.IndicatorStyleMax:
874 raise ValueError("style out of range") 908 raise ValueError("style out of range")
875 909
876 self.SendScintilla(QsciScintilla.SCI_INDICSETSTYLE, indicator, style) 910 self.SendScintilla(QsciScintilla.SCI_INDICSETSTYLE, indicator, style)
877 self.SendScintilla(QsciScintilla.SCI_INDICSETFORE, indicator, color) 911 self.SendScintilla(QsciScintilla.SCI_INDICSETFORE, indicator, color)
878 try: 912 try:
968 @return flag indicating the existence of the indicator (boolean) 1002 @return flag indicating the existence of the indicator (boolean)
969 """ 1003 """
970 res = self.SendScintilla(QsciScintilla.SCI_INDICATORVALUEAT, 1004 res = self.SendScintilla(QsciScintilla.SCI_INDICATORVALUEAT,
971 indicator, pos) 1005 indicator, pos)
972 return res 1006 return res
1007
1008 def showFindIndicator(self, sline, sindex, eline, eindex):
1009 """
1010 Public method to show the find indicator for the given range.
1011
1012 @param sline line number of the indicator start (integer)
1013 @param sindex index of the indicator start (integer)
1014 @param eline line number of the indicator end (integer)
1015 @param eindex index of the indicator end (integer)
1016 """
1017 if hasattr(QsciScintilla, "SCI_FINDINDICATORSHOW"):
1018 spos = self.positionFromLineIndex(sline, sindex)
1019 epos = self.positionFromLineIndex(eline, eindex)
1020 self.SendScintilla(QsciScintilla.SCI_FINDINDICATORSHOW, spos, epos)
1021
1022 def flashFindIndicator(self, sline, sindex, eline, eindex):
1023 """
1024 Public method to flash the find indicator for the given range.
1025
1026 @param sline line number of the indicator start (integer)
1027 @param sindex index of the indicator start (integer)
1028 @param eline line number of the indicator end (integer)
1029 @param eindex index of the indicator end (integer)
1030 """
1031 if hasattr(QsciScintilla, "SCI_FINDINDICATORFLASH"):
1032 spos = self.positionFromLineIndex(sline, sindex)
1033 epos = self.positionFromLineIndex(eline, eindex)
1034 self.SendScintilla(QsciScintilla.SCI_FINDINDICATORFLASH,
1035 spos, epos)
1036
1037 def hideFindIndicator(self):
1038 """
1039 Public method to hide the find indicator.
1040 """
1041 if hasattr(QsciScintilla, "SCI_FINDINDICATORHIDE"):
1042 self.SendScintilla(QsciScintilla.SCI_FINDINDICATORHIDE)
973 1043
974 ########################################################################### 1044 ###########################################################################
975 # methods to perform folding related stuff 1045 # methods to perform folding related stuff
976 ########################################################################### 1046 ###########################################################################
977 1047

eric ide

mercurial