src/eric7/QScintilla/QsciScintillaCompat.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9473
3f23dbf37dbe
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
11 11
12 from PyQt6.QtCore import pyqtSignal, Qt, QPoint 12 from PyQt6.QtCore import pyqtSignal, Qt, QPoint
13 from PyQt6.QtGui import QPalette, QColor 13 from PyQt6.QtGui import QPalette, QColor
14 from PyQt6.QtWidgets import QApplication, QListWidget 14 from PyQt6.QtWidgets import QApplication, QListWidget
15 from PyQt6.Qsci import ( 15 from PyQt6.Qsci import (
16 QsciScintillaBase, QsciScintilla, 16 QsciScintillaBase,
17 QSCINTILLA_VERSION as QSCIQSCINTILLA_VERSION 17 QsciScintilla,
18 QSCINTILLA_VERSION as QSCIQSCINTILLA_VERSION,
18 ) 19 )
19 20
20 ############################################################################### 21 ###############################################################################
21 22
22 23
23 def QSCINTILLA_VERSION(): 24 def QSCINTILLA_VERSION():
24 """ 25 """
25 Module function to return the QScintilla version. 26 Module function to return the QScintilla version.
26 27
27 @return QScintilla version (integer) 28 @return QScintilla version (integer)
28 """ 29 """
29 return QSCIQSCINTILLA_VERSION 30 return QSCIQSCINTILLA_VERSION
30 31
32
31 ############################################################################### 33 ###############################################################################
32 34
33 35
34 class QsciScintillaCompat(QsciScintilla): 36 class QsciScintillaCompat(QsciScintilla):
35 """ 37 """
36 Class implementing a compatability interface to QsciScintilla. 38 Class implementing a compatability interface to QsciScintilla.
37 39
38 This class implements all the functions, that were added to 40 This class implements all the functions, that were added to
39 QsciScintilla incrementally. This class ensures compatibility 41 QsciScintilla incrementally. This class ensures compatibility
40 to older versions of QsciScintilla. 42 to older versions of QsciScintilla.
41 43
42 @signal zoomValueChanged(int) emitted to signal a change of the zoom value 44 @signal zoomValueChanged(int) emitted to signal a change of the zoom value
43 """ 45 """
46
44 zoomValueChanged = pyqtSignal(int) 47 zoomValueChanged = pyqtSignal(int)
45 48
46 ArrowFoldStyle = QsciScintilla.FoldStyle.BoxedTreeFoldStyle.value + 1 49 ArrowFoldStyle = QsciScintilla.FoldStyle.BoxedTreeFoldStyle.value + 1
47 ArrowTreeFoldStyle = ArrowFoldStyle + 1 50 ArrowTreeFoldStyle = ArrowFoldStyle + 1
48 51
49 UserSeparator = '\x04' 52 UserSeparator = "\x04"
50 53
51 IndicatorStyleMax = QsciScintilla.INDIC_GRADIENTCENTRE 54 IndicatorStyleMax = QsciScintilla.INDIC_GRADIENTCENTRE
52 55
53 # Maps PyQt6.QFont.Weight to the weights used by QScintilla 56 # Maps PyQt6.QFont.Weight to the weights used by QScintilla
54 QFontWeightMapping = { 57 QFontWeightMapping = {
55 100: 0, 58 100: 0,
56 200: 12, 59 200: 12,
57 300: 25, 60 300: 25,
60 600: 63, 63 600: 63,
61 700: 75, 64 700: 75,
62 800: 81, 65 800: 81,
63 900: 87, 66 900: 87,
64 } 67 }
65 68
66 def __init__(self, parent=None): 69 def __init__(self, parent=None):
67 """ 70 """
68 Constructor 71 Constructor
69 72
70 @param parent parent widget (QWidget) 73 @param parent parent widget (QWidget)
71 """ 74 """
72 super().__init__(parent) 75 super().__init__(parent)
73 76
74 self.zoom = 0 77 self.zoom = 0
75 78
76 self.__targetSearchFlags = 0 79 self.__targetSearchFlags = 0
77 self.__targetSearchExpr = "" 80 self.__targetSearchExpr = ""
78 self.__targetSearchStart = 0 81 self.__targetSearchStart = 0
79 self.__targetSearchEnd = -1 82 self.__targetSearchEnd = -1
80 self.__targetSearchActive = False 83 self.__targetSearchActive = False
81 84
82 self.__modified = False 85 self.__modified = False
83 86
84 self.userListActivated.connect(self.__completionListSelected) 87 self.userListActivated.connect(self.__completionListSelected)
85 self.modificationChanged.connect(self.__modificationChanged) 88 self.modificationChanged.connect(self.__modificationChanged)
86 89
87 self.setAutoCompletionWidgetSize(40, 5) 90 self.setAutoCompletionWidgetSize(40, 5)
88 91
89 def __modificationChanged(self, m): 92 def __modificationChanged(self, m):
90 """ 93 """
91 Private slot to handle the modificationChanged signal. 94 Private slot to handle the modificationChanged signal.
92 95
93 @param m modification status (boolean) 96 @param m modification status (boolean)
94 """ 97 """
95 self.__modified = m 98 self.__modified = m
96 99
97 def isModified(self): 100 def isModified(self):
98 """ 101 """
99 Public method to return the modification status. 102 Public method to return the modification status.
100 103
101 @return flag indicating the modification status (boolean) 104 @return flag indicating the modification status (boolean)
102 """ 105 """
103 return self.__modified 106 return self.__modified
104 107
105 def setModified(self, m): 108 def setModified(self, m):
106 """ 109 """
107 Public slot to set the modification status. 110 Public slot to set the modification status.
108 111
109 @param m new modification status (boolean) 112 @param m new modification status (boolean)
110 """ 113 """
111 self.__modified = m 114 self.__modified = m
112 super().setModified(m) 115 super().setModified(m)
113 self.modificationChanged.emit(m) 116 self.modificationChanged.emit(m)
114 117
115 def setLexer(self, lex=None): 118 def setLexer(self, lex=None):
116 """ 119 """
117 Public method to set the lexer. 120 Public method to set the lexer.
118 121
119 @param lex the lexer to be set or None to reset it. 122 @param lex the lexer to be set or None to reset it.
120 """ 123 """
121 super().setLexer(lex) 124 super().setLexer(lex)
122 if lex is None: 125 if lex is None:
123 self.clearStyles() 126 self.clearStyles()
124 127
125 def clearStyles(self): 128 def clearStyles(self):
126 """ 129 """
127 Public method to set the styles according the selected Qt style. 130 Public method to set the styles according the selected Qt style.
128 """ 131 """
129 palette = QApplication.palette() 132 palette = QApplication.palette()
130 self.SendScintilla(QsciScintilla.SCI_STYLESETFORE, 133 self.SendScintilla(
131 QsciScintilla.STYLE_DEFAULT, 134 QsciScintilla.SCI_STYLESETFORE,
132 palette.color(QPalette.ColorRole.Text)) 135 QsciScintilla.STYLE_DEFAULT,
133 self.SendScintilla(QsciScintilla.SCI_STYLESETBACK, 136 palette.color(QPalette.ColorRole.Text),
134 QsciScintilla.STYLE_DEFAULT, 137 )
135 palette.color(QPalette.ColorRole.Base)) 138 self.SendScintilla(
139 QsciScintilla.SCI_STYLESETBACK,
140 QsciScintilla.STYLE_DEFAULT,
141 palette.color(QPalette.ColorRole.Base),
142 )
136 self.SendScintilla(QsciScintilla.SCI_STYLECLEARALL) 143 self.SendScintilla(QsciScintilla.SCI_STYLECLEARALL)
137 self.SendScintilla(QsciScintilla.SCI_CLEARDOCUMENTSTYLE) 144 self.SendScintilla(QsciScintilla.SCI_CLEARDOCUMENTSTYLE)
138 145
139 def monospacedStyles(self, font): 146 def monospacedStyles(self, font):
140 """ 147 """
141 Public method to set the current style to be monospaced. 148 Public method to set the current style to be monospaced.
142 149
143 @param font font to be used (QFont) 150 @param font font to be used (QFont)
144 """ 151 """
145 try: 152 try:
146 rangeLow = list(range(self.STYLE_DEFAULT)) 153 rangeLow = list(range(self.STYLE_DEFAULT))
147 except AttributeError: 154 except AttributeError:
148 rangeLow = list(range(32)) 155 rangeLow = list(range(32))
149 try: 156 try:
150 rangeHigh = list(range(self.STYLE_LASTPREDEFINED + 1, 157 rangeHigh = list(range(self.STYLE_LASTPREDEFINED + 1, self.STYLE_MAX + 1))
151 self.STYLE_MAX + 1))
152 except AttributeError: 158 except AttributeError:
153 rangeHigh = list(range(40, 128)) 159 rangeHigh = list(range(40, 128))
154 160
155 f = font.family().encode("utf-8") 161 f = font.family().encode("utf-8")
156 ps = font.pointSize() 162 ps = font.pointSize()
157 weight = -QsciScintillaCompat.QFontWeightMapping[font.weight()] 163 weight = -QsciScintillaCompat.QFontWeightMapping[font.weight()]
158 italic = font.italic() 164 italic = font.italic()
159 underline = font.underline() 165 underline = font.underline()
160 bold = font.bold() 166 bold = font.bold()
161 for style in rangeLow + rangeHigh: 167 for style in rangeLow + rangeHigh:
162 self.SendScintilla(QsciScintilla.SCI_STYLESETFONT, style, f) 168 self.SendScintilla(QsciScintilla.SCI_STYLESETFONT, style, f)
163 self.SendScintilla(QsciScintilla.SCI_STYLESETSIZE, style, ps) 169 self.SendScintilla(QsciScintilla.SCI_STYLESETSIZE, style, ps)
164 try: 170 try:
165 self.SendScintilla( 171 self.SendScintilla(QsciScintilla.SCI_STYLESETWEIGHT, style, weight)
166 QsciScintilla.SCI_STYLESETWEIGHT, style, weight)
167 except AttributeError: 172 except AttributeError:
168 self.SendScintilla(QsciScintilla.SCI_STYLESETBOLD, style, bold) 173 self.SendScintilla(QsciScintilla.SCI_STYLESETBOLD, style, bold)
169 self.SendScintilla(QsciScintilla.SCI_STYLESETITALIC, style, italic) 174 self.SendScintilla(QsciScintilla.SCI_STYLESETITALIC, style, italic)
170 self.SendScintilla( 175 self.SendScintilla(QsciScintilla.SCI_STYLESETUNDERLINE, style, underline)
171 QsciScintilla.SCI_STYLESETUNDERLINE, style, underline) 176
172
173 def linesOnScreen(self): 177 def linesOnScreen(self):
174 """ 178 """
175 Public method to get the amount of visible lines. 179 Public method to get the amount of visible lines.
176 180
177 @return amount of visible lines (integer) 181 @return amount of visible lines (integer)
178 """ 182 """
179 return self.SendScintilla(QsciScintilla.SCI_LINESONSCREEN) 183 return self.SendScintilla(QsciScintilla.SCI_LINESONSCREEN)
180 184
181 def lineAt(self, pos): 185 def lineAt(self, pos):
182 """ 186 """
183 Public method to calculate the line at a position. 187 Public method to calculate the line at a position.
184 188
185 This variant is able to calculate the line for positions in the 189 This variant is able to calculate the line for positions in the
186 margins and for empty lines. 190 margins and for empty lines.
187 191
188 @param pos position to calculate the line for (integer or QPoint) 192 @param pos position to calculate the line for (integer or QPoint)
189 @return linenumber at position or -1, if there is no line at pos 193 @return linenumber at position or -1, if there is no line at pos
190 (integer, zero based) 194 (integer, zero based)
191 """ 195 """
192 scipos = ( 196 scipos = (
193 pos 197 pos
194 if isinstance(pos, int) else 198 if isinstance(pos, int)
195 self.SendScintilla(QsciScintilla.SCI_POSITIONFROMPOINT, 199 else self.SendScintilla(
196 pos.x(), pos.y()) 200 QsciScintilla.SCI_POSITIONFROMPOINT, pos.x(), pos.y()
201 )
197 ) 202 )
198 line = self.SendScintilla(QsciScintilla.SCI_LINEFROMPOSITION, scipos) 203 line = self.SendScintilla(QsciScintilla.SCI_LINEFROMPOSITION, scipos)
199 if line >= self.lines(): 204 if line >= self.lines():
200 line = -1 205 line = -1
201 return line 206 return line
202 207
203 def currentPosition(self): 208 def currentPosition(self):
204 """ 209 """
205 Public method to get the current position. 210 Public method to get the current position.
206 211
207 @return absolute position of the cursor (integer) 212 @return absolute position of the cursor (integer)
208 """ 213 """
209 return self.SendScintilla(QsciScintilla.SCI_GETCURRENTPOS) 214 return self.SendScintilla(QsciScintilla.SCI_GETCURRENTPOS)
210 215
211 def styleAt(self, pos): 216 def styleAt(self, pos):
212 """ 217 """
213 Public method to get the style at a position in the text. 218 Public method to get the style at a position in the text.
214 219
215 @param pos position in the text (integer) 220 @param pos position in the text (integer)
216 @return style at the requested position or 0, if the position 221 @return style at the requested position or 0, if the position
217 is negative or past the end of the document (integer) 222 is negative or past the end of the document (integer)
218 """ 223 """
219 return self.SendScintilla(QsciScintilla.SCI_GETSTYLEAT, pos) 224 return self.SendScintilla(QsciScintilla.SCI_GETSTYLEAT, pos)
220 225
221 def currentStyle(self): 226 def currentStyle(self):
222 """ 227 """
223 Public method to get the style at the current position. 228 Public method to get the style at the current position.
224 229
225 @return style at the current position (integer) 230 @return style at the current position (integer)
226 """ 231 """
227 return self.styleAt(self.currentPosition()) 232 return self.styleAt(self.currentPosition())
228 233
229 def getSubStyleRange(self, styleNr): 234 def getSubStyleRange(self, styleNr):
230 """ 235 """
231 Public method to get the sub style range for given style number. 236 Public method to get the sub style range for given style number.
232 237
233 @param styleNr Number of the base style 238 @param styleNr Number of the base style
234 @type int 239 @type int
235 @return start index of the sub style and their count 240 @return start index of the sub style and their count
236 @rtype int, int 241 @rtype int, int
237 """ 242 """
238 start = self.SendScintilla(QsciScintilla.SCI_GETSUBSTYLESSTART, 243 start = self.SendScintilla(QsciScintilla.SCI_GETSUBSTYLESSTART, styleNr)
239 styleNr) 244 count = self.SendScintilla(QsciScintilla.SCI_GETSUBSTYLESLENGTH, styleNr)
240 count = self.SendScintilla(QsciScintilla.SCI_GETSUBSTYLESLENGTH,
241 styleNr)
242 return start, count 245 return start, count
243 246
244 def getEndStyled(self): 247 def getEndStyled(self):
245 """ 248 """
246 Public method to get the last styled position. 249 Public method to get the last styled position.
247 250
248 @return end position of the last styling run (integer) 251 @return end position of the last styling run (integer)
249 """ 252 """
250 return self.SendScintilla(QsciScintilla.SCI_GETENDSTYLED) 253 return self.SendScintilla(QsciScintilla.SCI_GETENDSTYLED)
251 254
252 def startStyling(self, pos, mask): 255 def startStyling(self, pos, mask):
253 """ 256 """
254 Public method to prepare styling. 257 Public method to prepare styling.
255 258
256 @param pos styling positition to start at (integer) 259 @param pos styling positition to start at (integer)
257 @param mask mask of bits to use for styling (integer) 260 @param mask mask of bits to use for styling (integer)
258 """ 261 """
259 self.SendScintilla(QsciScintilla.SCI_STARTSTYLING, pos, mask) 262 self.SendScintilla(QsciScintilla.SCI_STARTSTYLING, pos, mask)
260 263
261 def setStyling(self, length, style): 264 def setStyling(self, length, style):
262 """ 265 """
263 Public method to style some text. 266 Public method to style some text.
264 267
265 @param length length of text to style (integer) 268 @param length length of text to style (integer)
266 @param style style to set for text (integer) 269 @param style style to set for text (integer)
267 """ 270 """
268 self.SendScintilla(QsciScintilla.SCI_SETSTYLING, length, style) 271 self.SendScintilla(QsciScintilla.SCI_SETSTYLING, length, style)
269 272
270 def charAt(self, pos): 273 def charAt(self, pos):
271 """ 274 """
272 Public method to get the character at a position in the text observing 275 Public method to get the character at a position in the text observing
273 multibyte characters. 276 multibyte characters.
274 277
275 @param pos position in the text (integer) 278 @param pos position in the text (integer)
276 @return character at the requested position or empty string, if the 279 @return character at the requested position or empty string, if the
277 position is negative or past the end of the document (string) 280 position is negative or past the end of the document (string)
278 """ 281 """
279 ch = self.byteAt(pos) 282 ch = self.byteAt(pos)
288 utf8Len = 1 291 utf8Len = 1
289 while len(ch) < utf8Len: 292 while len(ch) < utf8Len:
290 pos += 1 293 pos += 1
291 ch += self.byteAt(pos) 294 ch += self.byteAt(pos)
292 try: 295 try:
293 return ch.decode('utf8') 296 return ch.decode("utf8")
294 except UnicodeDecodeError: 297 except UnicodeDecodeError:
295 if pos > 0: 298 if pos > 0:
296 # try it one position before; maybe we are in the 299 # try it one position before; maybe we are in the
297 # middle of a unicode character 300 # middle of a unicode character
298 return self.charAt(pos - 1) 301 return self.charAt(pos - 1)
299 else: 302 else:
300 return "" 303 return ""
301 else: 304 else:
302 return ch.decode() 305 return ch.decode()
303 306
304 def byteAt(self, pos): 307 def byteAt(self, pos):
305 """ 308 """
306 Public method to get the raw character (bytes) at a position in the 309 Public method to get the raw character (bytes) at a position in the
307 text. 310 text.
308 311
309 @param pos position in the text (integer) 312 @param pos position in the text (integer)
310 @return raw character at the requested position or empty bytes, if the 313 @return raw character at the requested position or empty bytes, if the
311 position is negative or past the end of the document (bytes) 314 position is negative or past the end of the document (bytes)
312 """ 315 """
313 char = self.SendScintilla(QsciScintilla.SCI_GETCHARAT, pos) 316 char = self.SendScintilla(QsciScintilla.SCI_GETCHARAT, pos)
314 if char == 0: 317 if char == 0:
315 return bytearray() 318 return bytearray()
316 if char < 0: 319 if char < 0:
317 char += 256 320 char += 256
318 return bytearray((char,)) 321 return bytearray((char,))
319 322
320 def foldLevelAt(self, line): 323 def foldLevelAt(self, line):
321 """ 324 """
322 Public method to get the fold level of a line of the document. 325 Public method to get the fold level of a line of the document.
323 326
324 @param line line number (integer) 327 @param line line number (integer)
325 @return fold level of the given line (integer) 328 @return fold level of the given line (integer)
326 """ 329 """
327 lvl = self.SendScintilla(QsciScintilla.SCI_GETFOLDLEVEL, line) 330 lvl = self.SendScintilla(QsciScintilla.SCI_GETFOLDLEVEL, line)
328 return ( 331 return (
329 (lvl & QsciScintilla.SC_FOLDLEVELNUMBERMASK) - 332 lvl & QsciScintilla.SC_FOLDLEVELNUMBERMASK
330 QsciScintilla.SC_FOLDLEVELBASE 333 ) - QsciScintilla.SC_FOLDLEVELBASE
331 ) 334
332
333 def foldFlagsAt(self, line): 335 def foldFlagsAt(self, line):
334 """ 336 """
335 Public method to get the fold flags of a line of the document. 337 Public method to get the fold flags of a line of the document.
336 338
337 @param line line number (integer) 339 @param line line number (integer)
338 @return fold flags of the given line (integer) 340 @return fold flags of the given line (integer)
339 """ 341 """
340 lvl = self.SendScintilla(QsciScintilla.SCI_GETFOLDLEVEL, line) 342 lvl = self.SendScintilla(QsciScintilla.SCI_GETFOLDLEVEL, line)
341 return lvl & ~QsciScintilla.SC_FOLDLEVELNUMBERMASK 343 return lvl & ~QsciScintilla.SC_FOLDLEVELNUMBERMASK
342 344
343 def foldHeaderAt(self, line): 345 def foldHeaderAt(self, line):
344 """ 346 """
345 Public method to determine, if a line of the document is a fold header 347 Public method to determine, if a line of the document is a fold header
346 line. 348 line.
347 349
348 @param line line number (integer) 350 @param line line number (integer)
349 @return flag indicating a fold header line (boolean) 351 @return flag indicating a fold header line (boolean)
350 """ 352 """
351 lvl = self.SendScintilla(QsciScintilla.SCI_GETFOLDLEVEL, line) 353 lvl = self.SendScintilla(QsciScintilla.SCI_GETFOLDLEVEL, line)
352 return lvl & QsciScintilla.SC_FOLDLEVELHEADERFLAG 354 return lvl & QsciScintilla.SC_FOLDLEVELHEADERFLAG
353 355
354 def foldExpandedAt(self, line): 356 def foldExpandedAt(self, line):
355 """ 357 """
356 Public method to determine, if a fold is expanded. 358 Public method to determine, if a fold is expanded.
357 359
358 @param line line number (integer) 360 @param line line number (integer)
359 @return flag indicating the fold expansion state of the line (boolean) 361 @return flag indicating the fold expansion state of the line (boolean)
360 """ 362 """
361 return self.SendScintilla(QsciScintilla.SCI_GETFOLDEXPANDED, line) 363 return self.SendScintilla(QsciScintilla.SCI_GETFOLDEXPANDED, line)
362 364
363 def setIndentationGuideView(self, view): 365 def setIndentationGuideView(self, view):
364 """ 366 """
365 Public method to set the view of the indentation guides. 367 Public method to set the view of the indentation guides.
366 368
367 @param view view of the indentation guides (SC_IV_NONE, SC_IV_REAL, 369 @param view view of the indentation guides (SC_IV_NONE, SC_IV_REAL,
368 SC_IV_LOOKFORWARD or SC_IV_LOOKBOTH) 370 SC_IV_LOOKFORWARD or SC_IV_LOOKBOTH)
369 """ 371 """
370 self.SendScintilla(QsciScintilla.SCI_SETINDENTATIONGUIDES, view) 372 self.SendScintilla(QsciScintilla.SCI_SETINDENTATIONGUIDES, view)
371 373
372 def indentationGuideView(self): 374 def indentationGuideView(self):
373 """ 375 """
374 Public method to get the indentation guide view. 376 Public method to get the indentation guide view.
375 377
376 @return indentation guide view (SC_IV_NONE, SC_IV_REAL, 378 @return indentation guide view (SC_IV_NONE, SC_IV_REAL,
377 SC_IV_LOOKFORWARD or SC_IV_LOOKBOTH) 379 SC_IV_LOOKFORWARD or SC_IV_LOOKBOTH)
378 """ 380 """
379 return self.SendScintilla(QsciScintilla.SCI_GETINDENTATIONGUIDES) 381 return self.SendScintilla(QsciScintilla.SCI_GETINDENTATIONGUIDES)
380 382
381 ########################################################################### 383 ###########################################################################
382 ## methods below are missing from QScintilla 384 ## methods below are missing from QScintilla
383 ########################################################################### 385 ###########################################################################
384 386
385 def setAutoCompletionWidgetSize(self, chars, lines): 387 def setAutoCompletionWidgetSize(self, chars, lines):
386 """ 388 """
387 Public method to set the size of completion and user lists. 389 Public method to set the size of completion and user lists.
388 390
389 @param chars max. number of chars to show 391 @param chars max. number of chars to show
390 @type int 392 @type int
391 @param lines max. number of lines to show 393 @param lines max. number of lines to show
392 @type int 394 @type int
393 """ 395 """
394 self.SendScintilla(QsciScintilla.SCI_AUTOCSETMAXWIDTH, chars) 396 self.SendScintilla(QsciScintilla.SCI_AUTOCSETMAXWIDTH, chars)
395 self.SendScintilla(QsciScintilla.SCI_AUTOCSETMAXHEIGHT, lines) 397 self.SendScintilla(QsciScintilla.SCI_AUTOCSETMAXHEIGHT, lines)
396 398
397 def zoomIn(self, zoom=1): 399 def zoomIn(self, zoom=1):
398 """ 400 """
399 Public method used to increase the zoom factor. 401 Public method used to increase the zoom factor.
400 402
401 @param zoom zoom factor increment (integer) 403 @param zoom zoom factor increment (integer)
402 """ 404 """
403 super().zoomIn(zoom) 405 super().zoomIn(zoom)
404 406
405 def zoomOut(self, zoom=1): 407 def zoomOut(self, zoom=1):
406 """ 408 """
407 Public method used to decrease the zoom factor. 409 Public method used to decrease the zoom factor.
408 410
409 @param zoom zoom factor decrement (integer) 411 @param zoom zoom factor decrement (integer)
410 """ 412 """
411 super().zoomOut(zoom) 413 super().zoomOut(zoom)
412 414
413 def zoomTo(self, zoom): 415 def zoomTo(self, zoom):
414 """ 416 """
415 Public method used to zoom to a specific zoom factor. 417 Public method used to zoom to a specific zoom factor.
416 418
417 @param zoom zoom factor (integer) 419 @param zoom zoom factor (integer)
418 """ 420 """
419 self.zoom = zoom 421 self.zoom = zoom
420 super().zoomTo(zoom) 422 super().zoomTo(zoom)
421 self.zoomValueChanged.emit(self.zoom) 423 self.zoomValueChanged.emit(self.zoom)
422 424
423 def getZoom(self): 425 def getZoom(self):
424 """ 426 """
425 Public method used to retrieve the current zoom factor. 427 Public method used to retrieve the current zoom factor.
426 428
427 @return zoom factor (integer) 429 @return zoom factor (integer)
428 """ 430 """
429 return self.zoom 431 return self.zoom
430 432
431 def editorCommand(self, cmd): 433 def editorCommand(self, cmd):
432 """ 434 """
433 Public method to perform a simple editor command. 435 Public method to perform a simple editor command.
434 436
435 @param cmd the scintilla command to be performed (integer) 437 @param cmd the scintilla command to be performed (integer)
436 """ 438 """
437 self.SendScintilla(cmd) 439 self.SendScintilla(cmd)
438 440
439 def scrollVertical(self, lines): 441 def scrollVertical(self, lines):
440 """ 442 """
441 Public method to scroll the text area. 443 Public method to scroll the text area.
442 444
443 @param lines number of lines to scroll (negative scrolls up, 445 @param lines number of lines to scroll (negative scrolls up,
444 positive scrolls down) (integer) 446 positive scrolls down) (integer)
445 """ 447 """
446 self.SendScintilla(QsciScintilla.SCI_LINESCROLL, 0, lines) 448 self.SendScintilla(QsciScintilla.SCI_LINESCROLL, 0, lines)
447 449
448 def moveCursorToEOL(self): 450 def moveCursorToEOL(self):
449 """ 451 """
450 Public method to move the cursor to the end of line. 452 Public method to move the cursor to the end of line.
451 """ 453 """
452 self.SendScintilla(QsciScintilla.SCI_LINEEND) 454 self.SendScintilla(QsciScintilla.SCI_LINEEND)
453 455
454 def moveCursorLeft(self): 456 def moveCursorLeft(self):
455 """ 457 """
456 Public method to move the cursor left. 458 Public method to move the cursor left.
457 """ 459 """
458 self.SendScintilla(QsciScintilla.SCI_CHARLEFT) 460 self.SendScintilla(QsciScintilla.SCI_CHARLEFT)
459 461
460 def moveCursorRight(self): 462 def moveCursorRight(self):
461 """ 463 """
462 Public method to move the cursor right. 464 Public method to move the cursor right.
463 """ 465 """
464 self.SendScintilla(QsciScintilla.SCI_CHARRIGHT) 466 self.SendScintilla(QsciScintilla.SCI_CHARRIGHT)
465 467
466 def moveCursorWordLeft(self): 468 def moveCursorWordLeft(self):
467 """ 469 """
468 Public method to move the cursor left one word. 470 Public method to move the cursor left one word.
469 """ 471 """
470 self.SendScintilla(QsciScintilla.SCI_WORDLEFT) 472 self.SendScintilla(QsciScintilla.SCI_WORDLEFT)
471 473
472 def moveCursorWordRight(self): 474 def moveCursorWordRight(self):
473 """ 475 """
474 Public method to move the cursor right one word. 476 Public method to move the cursor right one word.
475 """ 477 """
476 self.SendScintilla(QsciScintilla.SCI_WORDRIGHT) 478 self.SendScintilla(QsciScintilla.SCI_WORDRIGHT)
477 479
478 def newLineBelow(self): 480 def newLineBelow(self):
479 """ 481 """
480 Public method to insert a new line below the current one. 482 Public method to insert a new line below the current one.
481 """ 483 """
482 self.SendScintilla(QsciScintilla.SCI_LINEEND) 484 self.SendScintilla(QsciScintilla.SCI_LINEEND)
483 self.SendScintilla(QsciScintilla.SCI_NEWLINE) 485 self.SendScintilla(QsciScintilla.SCI_NEWLINE)
484 486
485 def deleteBack(self): 487 def deleteBack(self):
486 """ 488 """
487 Public method to delete the character to the left of the cursor. 489 Public method to delete the character to the left of the cursor.
488 """ 490 """
489 self.SendScintilla(QsciScintilla.SCI_DELETEBACK) 491 self.SendScintilla(QsciScintilla.SCI_DELETEBACK)
490 492
491 def delete(self): 493 def delete(self):
492 """ 494 """
493 Public method to delete the character to the right of the cursor. 495 Public method to delete the character to the right of the cursor.
494 """ 496 """
495 self.SendScintilla(QsciScintilla.SCI_CLEAR) 497 self.SendScintilla(QsciScintilla.SCI_CLEAR)
496 498
497 def deleteWordLeft(self): 499 def deleteWordLeft(self):
498 """ 500 """
499 Public method to delete the word to the left of the cursor. 501 Public method to delete the word to the left of the cursor.
500 """ 502 """
501 self.SendScintilla(QsciScintilla.SCI_DELWORDLEFT) 503 self.SendScintilla(QsciScintilla.SCI_DELWORDLEFT)
502 504
503 def deleteWordRight(self): 505 def deleteWordRight(self):
504 """ 506 """
505 Public method to delete the word to the right of the cursor. 507 Public method to delete the word to the right of the cursor.
506 """ 508 """
507 self.SendScintilla(QsciScintilla.SCI_DELWORDRIGHT) 509 self.SendScintilla(QsciScintilla.SCI_DELWORDRIGHT)
508 510
509 def deleteLineLeft(self): 511 def deleteLineLeft(self):
510 """ 512 """
511 Public method to delete the line to the left of the cursor. 513 Public method to delete the line to the left of the cursor.
512 """ 514 """
513 self.SendScintilla(QsciScintilla.SCI_DELLINELEFT) 515 self.SendScintilla(QsciScintilla.SCI_DELLINELEFT)
514 516
515 def deleteLineRight(self): 517 def deleteLineRight(self):
516 """ 518 """
517 Public method to delete the line to the right of the cursor. 519 Public method to delete the line to the right of the cursor.
518 """ 520 """
519 self.SendScintilla(QsciScintilla.SCI_DELLINERIGHT) 521 self.SendScintilla(QsciScintilla.SCI_DELLINERIGHT)
520 522
521 def extendSelectionLeft(self): 523 def extendSelectionLeft(self):
522 """ 524 """
523 Public method to extend the selection one character to the left. 525 Public method to extend the selection one character to the left.
524 """ 526 """
525 self.SendScintilla(QsciScintilla.SCI_CHARLEFTEXTEND) 527 self.SendScintilla(QsciScintilla.SCI_CHARLEFTEXTEND)
526 528
527 def extendSelectionRight(self): 529 def extendSelectionRight(self):
528 """ 530 """
529 Public method to extend the selection one character to the right. 531 Public method to extend the selection one character to the right.
530 """ 532 """
531 self.SendScintilla(QsciScintilla.SCI_CHARRIGHTEXTEND) 533 self.SendScintilla(QsciScintilla.SCI_CHARRIGHTEXTEND)
532 534
533 def extendSelectionWordLeft(self): 535 def extendSelectionWordLeft(self):
534 """ 536 """
535 Public method to extend the selection one word to the left. 537 Public method to extend the selection one word to the left.
536 """ 538 """
537 self.SendScintilla(QsciScintilla.SCI_WORDLEFTEXTEND) 539 self.SendScintilla(QsciScintilla.SCI_WORDLEFTEXTEND)
538 540
539 def extendSelectionWordRight(self): 541 def extendSelectionWordRight(self):
540 """ 542 """
541 Public method to extend the selection one word to the right. 543 Public method to extend the selection one word to the right.
542 """ 544 """
543 self.SendScintilla(QsciScintilla.SCI_WORDRIGHTEXTEND) 545 self.SendScintilla(QsciScintilla.SCI_WORDRIGHTEXTEND)
544 546
545 def extendSelectionToBOL(self): 547 def extendSelectionToBOL(self):
546 """ 548 """
547 Public method to extend the selection to the beginning of the line. 549 Public method to extend the selection to the beginning of the line.
548 """ 550 """
549 self.SendScintilla(QsciScintilla.SCI_VCHOMEEXTEND) 551 self.SendScintilla(QsciScintilla.SCI_VCHOMEEXTEND)
550 552
551 def extendSelectionToEOL(self): 553 def extendSelectionToEOL(self):
552 """ 554 """
553 Public method to extend the selection to the end of the line. 555 Public method to extend the selection to the end of the line.
554 """ 556 """
555 self.SendScintilla(QsciScintilla.SCI_LINEENDEXTEND) 557 self.SendScintilla(QsciScintilla.SCI_LINEENDEXTEND)
556 558
557 def hasSelection(self): 559 def hasSelection(self):
558 """ 560 """
559 Public method to check for a selection. 561 Public method to check for a selection.
560 562
561 @return flag indicating the presence of a selection (boolean) 563 @return flag indicating the presence of a selection (boolean)
562 """ 564 """
563 return self.getSelection()[0] != -1 565 return self.getSelection()[0] != -1
564 566
565 def hasSelectedText(self): 567 def hasSelectedText(self):
566 """ 568 """
567 Public method to indicate the presence of selected text. 569 Public method to indicate the presence of selected text.
568 570
569 This is an overriding method to cope with a bug in QsciScintilla. 571 This is an overriding method to cope with a bug in QsciScintilla.
570 572
571 @return flag indicating the presence of selected text (boolean) 573 @return flag indicating the presence of selected text (boolean)
572 """ 574 """
573 return bool(self.selectedText()) 575 return bool(self.selectedText())
574 576
575 def selectionIsRectangle(self): 577 def selectionIsRectangle(self):
576 """ 578 """
577 Public method to check, if the current selection is rectangular. 579 Public method to check, if the current selection is rectangular.
578 580
579 @return flag indicating a rectangular selection (boolean) 581 @return flag indicating a rectangular selection (boolean)
580 """ 582 """
581 startLine, startIndex, endLine, endIndex = self.getSelection() 583 startLine, startIndex, endLine, endIndex = self.getSelection()
582 return ( 584 return (
583 startLine != -1 and 585 startLine != -1
584 startLine != endLine and 586 and startLine != endLine
585 self.SendScintilla(QsciScintilla.SCI_SELECTIONISRECTANGLE) 587 and self.SendScintilla(QsciScintilla.SCI_SELECTIONISRECTANGLE)
586 ) 588 )
587 589
588 def getRectangularSelection(self): 590 def getRectangularSelection(self):
589 """ 591 """
590 Public method to retrieve the start and end of a rectangular selection. 592 Public method to retrieve the start and end of a rectangular selection.
591 593
592 @return tuple with start line and index and end line and index 594 @return tuple with start line and index and end line and index
593 (tuple of four int) 595 (tuple of four int)
594 """ 596 """
595 if not self.selectionIsRectangle(): 597 if not self.selectionIsRectangle():
596 return (-1, -1, -1, -1) 598 return (-1, -1, -1, -1)
597 599
598 startPos = self.SendScintilla( 600 startPos = self.SendScintilla(QsciScintilla.SCI_GETRECTANGULARSELECTIONANCHOR)
599 QsciScintilla.SCI_GETRECTANGULARSELECTIONANCHOR) 601 endPos = self.SendScintilla(QsciScintilla.SCI_GETRECTANGULARSELECTIONCARET)
600 endPos = self.SendScintilla(
601 QsciScintilla.SCI_GETRECTANGULARSELECTIONCARET)
602 startLine, startIndex = self.lineIndexFromPosition(startPos) 602 startLine, startIndex = self.lineIndexFromPosition(startPos)
603 endLine, endIndex = self.lineIndexFromPosition(endPos) 603 endLine, endIndex = self.lineIndexFromPosition(endPos)
604 604
605 return (startLine, startIndex, endLine, endIndex) 605 return (startLine, startIndex, endLine, endIndex)
606 606
607 def setRectangularSelection(self, startLine, startIndex, endLine, 607 def setRectangularSelection(self, startLine, startIndex, endLine, endIndex):
608 endIndex):
609 """ 608 """
610 Public method to set a rectangular selection. 609 Public method to set a rectangular selection.
611 610
612 @param startLine line number of the start of the selection (int) 611 @param startLine line number of the start of the selection (int)
613 @param startIndex index number of the start of the selection (int) 612 @param startIndex index number of the start of the selection (int)
614 @param endLine line number of the end of the selection (int) 613 @param endLine line number of the end of the selection (int)
615 @param endIndex index number of the end of the selection (int) 614 @param endIndex index number of the end of the selection (int)
616 """ 615 """
617 startPos = self.positionFromLineIndex(startLine, startIndex) 616 startPos = self.positionFromLineIndex(startLine, startIndex)
618 endPos = self.positionFromLineIndex(endLine, endIndex) 617 endPos = self.positionFromLineIndex(endLine, endIndex)
619 618
620 self.SendScintilla( 619 self.SendScintilla(QsciScintilla.SCI_SETRECTANGULARSELECTIONANCHOR, startPos)
621 QsciScintilla.SCI_SETRECTANGULARSELECTIONANCHOR, startPos) 620 self.SendScintilla(QsciScintilla.SCI_SETRECTANGULARSELECTIONCARET, endPos)
622 self.SendScintilla( 621
623 QsciScintilla.SCI_SETRECTANGULARSELECTIONCARET, endPos)
624
625 def getSelectionCount(self): 622 def getSelectionCount(self):
626 """ 623 """
627 Public method to get the number of active selections. 624 Public method to get the number of active selections.
628 625
629 @return number of active selection (integer) 626 @return number of active selection (integer)
630 """ 627 """
631 return self.SendScintilla(QsciScintilla.SCI_GETSELECTIONS) 628 return self.SendScintilla(QsciScintilla.SCI_GETSELECTIONS)
632 629
633 def getSelectionN(self, index): 630 def getSelectionN(self, index):
634 """ 631 """
635 Public method to get the start and end of a selection given by its 632 Public method to get the start and end of a selection given by its
636 index. 633 index.
637 634
638 @param index index of the selection (integer) 635 @param index index of the selection (integer)
639 @return tuple with start line and index and end line and index 636 @return tuple with start line and index and end line and index
640 (tuple of four int) for the given selection 637 (tuple of four int) for the given selection
641 """ 638 """
642 startPos = self.SendScintilla( 639 startPos = self.SendScintilla(QsciScintilla.SCI_GETSELECTIONNSTART, index)
643 QsciScintilla.SCI_GETSELECTIONNSTART, index)
644 endPos = self.SendScintilla(QsciScintilla.SCI_GETSELECTIONNEND, index) 640 endPos = self.SendScintilla(QsciScintilla.SCI_GETSELECTIONNEND, index)
645 startLine, startIndex = self.lineIndexFromPosition(startPos) 641 startLine, startIndex = self.lineIndexFromPosition(startPos)
646 endLine, endIndex = self.lineIndexFromPosition(endPos) 642 endLine, endIndex = self.lineIndexFromPosition(endPos)
647 643
648 return (startLine, startIndex, endLine, endIndex) 644 return (startLine, startIndex, endLine, endIndex)
649 645
650 def getSelections(self): 646 def getSelections(self):
651 """ 647 """
652 Public method to get the start and end coordinates of all active 648 Public method to get the start and end coordinates of all active
653 selections. 649 selections.
654 650
655 @return list of tuples with start line and index and end line and index 651 @return list of tuples with start line and index and end line and index
656 of each active selection (list of tuples of four int) 652 of each active selection (list of tuples of four int)
657 """ 653 """
658 selections = [] 654 selections = []
659 for index in range(self.getSelectionCount()): 655 for index in range(self.getSelectionCount()):
660 selections.append(self.getSelectionN(index)) 656 selections.append(self.getSelectionN(index))
661 return selections 657 return selections
662 658
663 def addCursor(self, line, index): 659 def addCursor(self, line, index):
664 """ 660 """
665 Public method to add an additional cursor. 661 Public method to add an additional cursor.
666 662
667 @param line line number for the cursor 663 @param line line number for the cursor
668 @type int 664 @type int
669 @param index index number for the cursor 665 @param index index number for the cursor
670 @type int 666 @type int
671 """ 667 """
672 pos = self.positionFromLineIndex(line, index) 668 pos = self.positionFromLineIndex(line, index)
673 669
674 if self.getSelectionCount() == 0: 670 if self.getSelectionCount() == 0:
675 self.SendScintilla(QsciScintilla.SCI_SETSELECTION, pos, pos) 671 self.SendScintilla(QsciScintilla.SCI_SETSELECTION, pos, pos)
676 else: 672 else:
677 self.SendScintilla(QsciScintilla.SCI_ADDSELECTION, pos, pos) 673 self.SendScintilla(QsciScintilla.SCI_ADDSELECTION, pos, pos)
678 674
679 def enableMultiCursorSupport(self): 675 def enableMultiCursorSupport(self):
680 """ 676 """
681 Public method to enable support for multi cursor editing. 677 Public method to enable support for multi cursor editing.
682 """ 678 """
683 # typing should insert in all selections at the same time 679 # typing should insert in all selections at the same time
684 self.SendScintilla(QsciScintilla.SCI_SETMULTIPLESELECTION, True) 680 self.SendScintilla(QsciScintilla.SCI_SETMULTIPLESELECTION, True)
685 self.SendScintilla(QsciScintilla.SCI_SETADDITIONALSELECTIONTYPING, 681 self.SendScintilla(QsciScintilla.SCI_SETADDITIONALSELECTIONTYPING, True)
686 True) 682
687
688 def setVirtualSpaceOptions(self, options): 683 def setVirtualSpaceOptions(self, options):
689 """ 684 """
690 Public method to set the virtual space usage options. 685 Public method to set the virtual space usage options.
691 686
692 @param options usage options to set (integer, 0 to 3) 687 @param options usage options to set (integer, 0 to 3)
693 """ 688 """
694 self.SendScintilla(QsciScintilla.SCI_SETVIRTUALSPACEOPTIONS, options) 689 self.SendScintilla(QsciScintilla.SCI_SETVIRTUALSPACEOPTIONS, options)
695 690
696 def getLineSeparator(self): 691 def getLineSeparator(self):
697 """ 692 """
698 Public method to get the line separator for the current eol mode. 693 Public method to get the line separator for the current eol mode.
699 694
700 @return eol string (string) 695 @return eol string (string)
701 """ 696 """
702 m = self.eolMode() 697 m = self.eolMode()
703 if m == QsciScintilla.EolMode.EolWindows: 698 if m == QsciScintilla.EolMode.EolWindows:
704 eol = '\r\n' 699 eol = "\r\n"
705 elif m == QsciScintilla.EolMode.EolUnix: 700 elif m == QsciScintilla.EolMode.EolUnix:
706 eol = '\n' 701 eol = "\n"
707 elif m == QsciScintilla.EolMode.EolMac: 702 elif m == QsciScintilla.EolMode.EolMac:
708 eol = '\r' 703 eol = "\r"
709 else: 704 else:
710 eol = '' 705 eol = ""
711 return eol 706 return eol
712 707
713 def getEolIndicator(self): 708 def getEolIndicator(self):
714 """ 709 """
715 Public method to get the eol indicator for the current eol mode. 710 Public method to get the eol indicator for the current eol mode.
716 711
717 @return eol indicator (string) 712 @return eol indicator (string)
718 """ 713 """
719 m = self.eolMode() 714 m = self.eolMode()
720 if m == QsciScintilla.EolMode.EolWindows: 715 if m == QsciScintilla.EolMode.EolWindows:
721 eol = 'CRLF' 716 eol = "CRLF"
722 elif m == QsciScintilla.EolMode.EolUnix: 717 elif m == QsciScintilla.EolMode.EolUnix:
723 eol = 'LF' 718 eol = "LF"
724 elif m == QsciScintilla.EolMode.EolMac: 719 elif m == QsciScintilla.EolMode.EolMac:
725 eol = 'CR' 720 eol = "CR"
726 else: 721 else:
727 eol = '' 722 eol = ""
728 return eol 723 return eol
729 724
730 def setEolModeByEolString(self, eolStr): 725 def setEolModeByEolString(self, eolStr):
731 """ 726 """
732 Public method to set the eol mode given the eol string. 727 Public method to set the eol mode given the eol string.
733 728
734 @param eolStr eol string (string) 729 @param eolStr eol string (string)
735 """ 730 """
736 if eolStr == '\r\n': 731 if eolStr == "\r\n":
737 self.setEolMode(QsciScintilla.EolMode.EolWindows) 732 self.setEolMode(QsciScintilla.EolMode.EolWindows)
738 elif eolStr == '\n': 733 elif eolStr == "\n":
739 self.setEolMode(QsciScintilla.EolMode.EolUnix) 734 self.setEolMode(QsciScintilla.EolMode.EolUnix)
740 elif eolStr == '\r': 735 elif eolStr == "\r":
741 self.setEolMode(QsciScintilla.EolMode.EolMac) 736 self.setEolMode(QsciScintilla.EolMode.EolMac)
742 737
743 def detectEolString(self, txt): 738 def detectEolString(self, txt):
744 """ 739 """
745 Public method to determine the eol string used. 740 Public method to determine the eol string used.
746 741
747 @param txt text from which to determine the eol string (string) 742 @param txt text from which to determine the eol string (string)
748 @return eol string (string) 743 @return eol string (string)
749 """ 744 """
750 if len(txt.split("\r\n", 1)) == 2: 745 if len(txt.split("\r\n", 1)) == 2:
751 return '\r\n' 746 return "\r\n"
752 elif len(txt.split("\n", 1)) == 2: 747 elif len(txt.split("\n", 1)) == 2:
753 return '\n' 748 return "\n"
754 elif len(txt.split("\r", 1)) == 2: 749 elif len(txt.split("\r", 1)) == 2:
755 return '\r' 750 return "\r"
756 else: 751 else:
757 return None 752 return None
758 753
759 def getCursorFlashTime(self): 754 def getCursorFlashTime(self):
760 """ 755 """
761 Public method to get the flash (blink) time of the cursor in 756 Public method to get the flash (blink) time of the cursor in
762 milliseconds. 757 milliseconds.
763 758
764 The flash time is the time required to display, invert and restore the 759 The flash time is the time required to display, invert and restore the
765 caret display. Usually the text cursor is displayed for half the cursor 760 caret display. Usually the text cursor is displayed for half the cursor
766 flash time, then hidden for the same amount of time. 761 flash time, then hidden for the same amount of time.
767 762
768 @return flash time of the cursor in milliseconds (integer) 763 @return flash time of the cursor in milliseconds (integer)
769 """ 764 """
770 return 2 * self.SendScintilla(QsciScintilla.SCI_GETCARETPERIOD) 765 return 2 * self.SendScintilla(QsciScintilla.SCI_GETCARETPERIOD)
771 766
772 def setCursorFlashTime(self, time): 767 def setCursorFlashTime(self, time):
773 """ 768 """
774 Public method to set the flash (blink) time of the cursor in 769 Public method to set the flash (blink) time of the cursor in
775 milliseconds. 770 milliseconds.
776 771
777 The flash time is the time required to display, invert and restore the 772 The flash time is the time required to display, invert and restore the
778 caret display. Usually the text cursor is displayed for half the cursor 773 caret display. Usually the text cursor is displayed for half the cursor
779 flash time, then hidden for the same amount of time. 774 flash time, then hidden for the same amount of time.
780 775
781 @param time flash time of the cursor in milliseconds (integer) 776 @param time flash time of the cursor in milliseconds (integer)
782 """ 777 """
783 self.SendScintilla(QsciScintilla.SCI_SETCARETPERIOD, time // 2) 778 self.SendScintilla(QsciScintilla.SCI_SETCARETPERIOD, time // 2)
784 779
785 def getCaretLineAlwaysVisible(self): 780 def getCaretLineAlwaysVisible(self):
786 """ 781 """
787 Public method to determine, if the caret line is visible even if 782 Public method to determine, if the caret line is visible even if
788 the editor doesn't have the focus. 783 the editor doesn't have the focus.
789 784
790 @return flag indicating an always visible caret line (boolean) 785 @return flag indicating an always visible caret line (boolean)
791 """ 786 """
792 try: 787 try:
793 return self.SendScintilla( 788 return self.SendScintilla(QsciScintilla.SCI_GETCARETLINEVISIBLEALWAYS)
794 QsciScintilla.SCI_GETCARETLINEVISIBLEALWAYS)
795 except AttributeError: 789 except AttributeError:
796 return False 790 return False
797 791
798 def setCaretLineAlwaysVisible(self, alwaysVisible): 792 def setCaretLineAlwaysVisible(self, alwaysVisible):
799 """ 793 """
800 Public method to set the caret line visible even if the editor doesn't 794 Public method to set the caret line visible even if the editor doesn't
801 have the focus. 795 have the focus.
802 796
803 @param alwaysVisible flag indicating that the caret line shall be 797 @param alwaysVisible flag indicating that the caret line shall be
804 visible even if the editor doesn't have the focus (boolean) 798 visible even if the editor doesn't have the focus (boolean)
805 """ 799 """
806 with contextlib.suppress(AttributeError): 800 with contextlib.suppress(AttributeError):
807 self.SendScintilla( 801 self.SendScintilla(
808 QsciScintilla.SCI_SETCARETLINEVISIBLEALWAYS, alwaysVisible) 802 QsciScintilla.SCI_SETCARETLINEVISIBLEALWAYS, alwaysVisible
809 803 )
804
810 def canPaste(self): 805 def canPaste(self):
811 """ 806 """
812 Public method to test, if the paste action is available (i.e. if the 807 Public method to test, if the paste action is available (i.e. if the
813 clipboard contains some text). 808 clipboard contains some text).
814 809
815 @return flag indicating the availability of 'paste' 810 @return flag indicating the availability of 'paste'
816 @rtype bool 811 @rtype bool
817 """ 812 """
818 return self.SendScintilla(QsciScintilla.SCI_CANPASTE) 813 return self.SendScintilla(QsciScintilla.SCI_CANPASTE)
819 814
820 ########################################################################### 815 ###########################################################################
821 ## methods to perform searches in target range 816 ## methods to perform searches in target range
822 ########################################################################### 817 ###########################################################################
823 818
824 def positionFromPoint(self, point): 819 def positionFromPoint(self, point):
825 """ 820 """
826 Public method to calculate the scintilla position from a point in the 821 Public method to calculate the scintilla position from a point in the
827 window. 822 window.
828 823
829 @param point point in the window (QPoint) 824 @param point point in the window (QPoint)
830 @return scintilla position (integer) or -1 to indicate, that the point 825 @return scintilla position (integer) or -1 to indicate, that the point
831 is not near any character 826 is not near any character
832 """ 827 """
833 return self.SendScintilla(QsciScintilla.SCI_POSITIONFROMPOINTCLOSE, 828 return self.SendScintilla(
834 point.x(), point.y()) 829 QsciScintilla.SCI_POSITIONFROMPOINTCLOSE, point.x(), point.y()
835 830 )
831
836 def positionBefore(self, pos): 832 def positionBefore(self, pos):
837 """ 833 """
838 Public method to get the position before the given position taking into 834 Public method to get the position before the given position taking into
839 account multibyte characters. 835 account multibyte characters.
840 836
841 @param pos position (integer) 837 @param pos position (integer)
842 @return position before the given one (integer) 838 @return position before the given one (integer)
843 """ 839 """
844 return self.SendScintilla(QsciScintilla.SCI_POSITIONBEFORE, pos) 840 return self.SendScintilla(QsciScintilla.SCI_POSITIONBEFORE, pos)
845 841
846 def positionAfter(self, pos): 842 def positionAfter(self, pos):
847 """ 843 """
848 Public method to get the position after the given position taking into 844 Public method to get the position after the given position taking into
849 account multibyte characters. 845 account multibyte characters.
850 846
851 @param pos position (integer) 847 @param pos position (integer)
852 @return position after the given one (integer) 848 @return position after the given one (integer)
853 """ 849 """
854 return self.SendScintilla(QsciScintilla.SCI_POSITIONAFTER, pos) 850 return self.SendScintilla(QsciScintilla.SCI_POSITIONAFTER, pos)
855 851
856 def lineEndPosition(self, line): 852 def lineEndPosition(self, line):
857 """ 853 """
858 Public method to determine the line end position of the given line. 854 Public method to determine the line end position of the given line.
859 855
860 @param line line number (integer) 856 @param line line number (integer)
861 @return position of the line end disregarding line end characters 857 @return position of the line end disregarding line end characters
862 (integer) 858 (integer)
863 """ 859 """
864 return self.SendScintilla(QsciScintilla.SCI_GETLINEENDPOSITION, line) 860 return self.SendScintilla(QsciScintilla.SCI_GETLINEENDPOSITION, line)
865 861
866 def __doSearchTarget(self): 862 def __doSearchTarget(self):
867 """ 863 """
868 Private method to perform the search in target. 864 Private method to perform the search in target.
869 865
870 @return flag indicating a successful search (boolean) 866 @return flag indicating a successful search (boolean)
871 """ 867 """
872 if self.__targetSearchStart == self.__targetSearchEnd: 868 if self.__targetSearchStart == self.__targetSearchEnd:
873 self.__targetSearchActive = False 869 self.__targetSearchActive = False
874 return False 870 return False
875 871
876 self.SendScintilla(QsciScintilla.SCI_SETTARGETSTART, 872 self.SendScintilla(QsciScintilla.SCI_SETTARGETSTART, self.__targetSearchStart)
877 self.__targetSearchStart) 873 self.SendScintilla(QsciScintilla.SCI_SETTARGETEND, self.__targetSearchEnd)
878 self.SendScintilla(QsciScintilla.SCI_SETTARGETEND, 874 self.SendScintilla(QsciScintilla.SCI_SETSEARCHFLAGS, self.__targetSearchFlags)
879 self.__targetSearchEnd)
880 self.SendScintilla(QsciScintilla.SCI_SETSEARCHFLAGS,
881 self.__targetSearchFlags)
882 targetSearchExpr = self._encodeString(self.__targetSearchExpr) 875 targetSearchExpr = self._encodeString(self.__targetSearchExpr)
883 pos = self.SendScintilla(QsciScintilla.SCI_SEARCHINTARGET, 876 pos = self.SendScintilla(
884 len(targetSearchExpr), 877 QsciScintilla.SCI_SEARCHINTARGET, len(targetSearchExpr), targetSearchExpr
885 targetSearchExpr) 878 )
886 879
887 if pos == -1: 880 if pos == -1:
888 self.__targetSearchActive = False 881 self.__targetSearchActive = False
889 return False 882 return False
890 883
891 targend = self.SendScintilla(QsciScintilla.SCI_GETTARGETEND) 884 targend = self.SendScintilla(QsciScintilla.SCI_GETTARGETEND)
892 self.__targetSearchStart = targend 885 self.__targetSearchStart = targend
893 886
894 return True 887 return True
895 888
896 def getFoundTarget(self): 889 def getFoundTarget(self):
897 """ 890 """
898 Public method to get the recently found target. 891 Public method to get the recently found target.
899 892
900 @return found target as a tuple of starting position and target length 893 @return found target as a tuple of starting position and target length
901 (integer, integer) 894 (integer, integer)
902 """ 895 """
903 if self.__targetSearchActive: 896 if self.__targetSearchActive:
904 spos = self.SendScintilla(QsciScintilla.SCI_GETTARGETSTART) 897 spos = self.SendScintilla(QsciScintilla.SCI_GETTARGETSTART)
905 epos = self.SendScintilla(QsciScintilla.SCI_GETTARGETEND) 898 epos = self.SendScintilla(QsciScintilla.SCI_GETTARGETEND)
906 return (spos, epos - spos) 899 return (spos, epos - spos)
907 else: 900 else:
908 return (0, 0) 901 return (0, 0)
909 902
910 def findFirstTarget(self, expr_, re_, cs_, wo_, 903 def findFirstTarget(
911 begline=-1, begindex=-1, endline=-1, endindex=-1, 904 self,
912 ws_=False, posix=False, cxx11=False): 905 expr_,
906 re_,
907 cs_,
908 wo_,
909 begline=-1,
910 begindex=-1,
911 endline=-1,
912 endindex=-1,
913 ws_=False,
914 posix=False,
915 cxx11=False,
916 ):
913 """ 917 """
914 Public method to search in a specified range of text without 918 Public method to search in a specified range of text without
915 setting the selection. 919 setting the selection.
916 920
917 @param expr_ search expression 921 @param expr_ search expression
918 @type str 922 @type str
919 @param re_ flag indicating a regular expression 923 @param re_ flag indicating a regular expression
920 @type bool 924 @type bool
921 @param cs_ flag indicating a case sensitive search 925 @param cs_ flag indicating a case sensitive search
954 self.__targetSearchFlags |= QsciScintilla.SCFIND_POSIX 958 self.__targetSearchFlags |= QsciScintilla.SCFIND_POSIX
955 with contextlib.suppress(AttributeError): 959 with contextlib.suppress(AttributeError):
956 if cxx11: 960 if cxx11:
957 self.__targetSearchFlags |= QsciScintilla.SCFIND_CXX11REGEX 961 self.__targetSearchFlags |= QsciScintilla.SCFIND_CXX11REGEX
958 # defined for QScintilla >= 2.11.0 962 # defined for QScintilla >= 2.11.0
959 963
960 if begline < 0 or begindex < 0: 964 if begline < 0 or begindex < 0:
961 self.__targetSearchStart = self.SendScintilla( 965 self.__targetSearchStart = self.SendScintilla(
962 QsciScintilla.SCI_GETCURRENTPOS) 966 QsciScintilla.SCI_GETCURRENTPOS
967 )
963 else: 968 else:
964 self.__targetSearchStart = self.positionFromLineIndex( 969 self.__targetSearchStart = self.positionFromLineIndex(begline, begindex)
965 begline, begindex) 970
966
967 if endline < 0 or endindex < 0: 971 if endline < 0 or endindex < 0:
968 self.__targetSearchEnd = self.SendScintilla( 972 self.__targetSearchEnd = self.SendScintilla(QsciScintilla.SCI_GETTEXTLENGTH)
969 QsciScintilla.SCI_GETTEXTLENGTH)
970 else: 973 else:
971 self.__targetSearchEnd = self.positionFromLineIndex( 974 self.__targetSearchEnd = self.positionFromLineIndex(endline, endindex)
972 endline, endindex) 975
973
974 self.__targetSearchExpr = expr_ 976 self.__targetSearchExpr = expr_
975 977
976 if self.__targetSearchExpr: 978 if self.__targetSearchExpr:
977 self.__targetSearchActive = True 979 self.__targetSearchActive = True
978 980
979 return self.__doSearchTarget() 981 return self.__doSearchTarget()
980 982
981 return False 983 return False
982 984
983 def findNextTarget(self): 985 def findNextTarget(self):
984 """ 986 """
985 Public method to find the next occurrence in the target range. 987 Public method to find the next occurrence in the target range.
986 988
987 @return flag indicating a successful search (boolean) 989 @return flag indicating a successful search (boolean)
988 """ 990 """
989 if not self.__targetSearchActive: 991 if not self.__targetSearchActive:
990 return False 992 return False
991 993
992 return self.__doSearchTarget() 994 return self.__doSearchTarget()
993 995
994 def replaceTarget(self, replaceStr): 996 def replaceTarget(self, replaceStr):
995 """ 997 """
996 Public method to replace the string found by the last search in target. 998 Public method to replace the string found by the last search in target.
997 999
998 @param replaceStr replacement string or regexp (string) 1000 @param replaceStr replacement string or regexp (string)
999 """ 1001 """
1000 if not self.__targetSearchActive: 1002 if not self.__targetSearchActive:
1001 return 1003 return
1002 1004
1003 cmd = ( 1005 cmd = (
1004 QsciScintilla.SCI_REPLACETARGETRE 1006 QsciScintilla.SCI_REPLACETARGETRE
1005 if self.__targetSearchFlags & QsciScintilla.SCFIND_REGEXP else 1007 if self.__targetSearchFlags & QsciScintilla.SCFIND_REGEXP
1006 QsciScintilla.SCI_REPLACETARGET 1008 else QsciScintilla.SCI_REPLACETARGET
1007 ) 1009 )
1008 r = self._encodeString(replaceStr) 1010 r = self._encodeString(replaceStr)
1009 1011
1010 start = self.SendScintilla(QsciScintilla.SCI_GETTARGETSTART) 1012 start = self.SendScintilla(QsciScintilla.SCI_GETTARGETSTART)
1011 self.SendScintilla(cmd, len(r), r) 1013 self.SendScintilla(cmd, len(r), r)
1012 1014
1013 self.__targetSearchStart = start + len(r) 1015 self.__targetSearchStart = start + len(r)
1014 1016
1015 ########################################################################### 1017 ###########################################################################
1016 ## indicator handling methods 1018 ## indicator handling methods
1017 ########################################################################### 1019 ###########################################################################
1018 1020
1019 def indicatorDefine(self, indicator, style, color): 1021 def indicatorDefine(self, indicator, style, color):
1020 """ 1022 """
1021 Public method to define the appearance of an indicator. 1023 Public method to define the appearance of an indicator.
1022 1024
1023 @param indicator number of the indicator (integer, 1025 @param indicator number of the indicator (integer,
1024 QsciScintilla.INDIC_CONTAINER .. QsciScintilla.INDIC_MAX) 1026 QsciScintilla.INDIC_CONTAINER .. QsciScintilla.INDIC_MAX)
1025 @param style style to be used for the indicator 1027 @param style style to be used for the indicator
1026 (QsciScintilla.INDIC_PLAIN, QsciScintilla.INDIC_SQUIGGLE, 1028 (QsciScintilla.INDIC_PLAIN, QsciScintilla.INDIC_SQUIGGLE,
1027 QsciScintilla.INDIC_TT, QsciScintilla.INDIC_DIAGONAL, 1029 QsciScintilla.INDIC_TT, QsciScintilla.INDIC_DIAGONAL,
1038 depending upon QScintilla version) 1040 depending upon QScintilla version)
1039 @param color color to be used by the indicator (QColor) 1041 @param color color to be used by the indicator (QColor)
1040 @exception ValueError the indicator or style are not valid 1042 @exception ValueError the indicator or style are not valid
1041 """ 1043 """
1042 if ( 1044 if (
1043 indicator < QsciScintilla.INDIC_CONTAINER or 1045 indicator < QsciScintilla.INDIC_CONTAINER
1044 indicator > QsciScintilla.INDIC_MAX 1046 or indicator > QsciScintilla.INDIC_MAX
1045 ): 1047 ):
1046 raise ValueError("indicator number out of range") 1048 raise ValueError("indicator number out of range")
1047 1049
1048 if ( 1050 if style < QsciScintilla.INDIC_PLAIN or style > self.IndicatorStyleMax:
1049 style < QsciScintilla.INDIC_PLAIN or
1050 style > self.IndicatorStyleMax
1051 ):
1052 raise ValueError("style out of range") 1051 raise ValueError("style out of range")
1053 1052
1054 self.SendScintilla(QsciScintilla.SCI_INDICSETSTYLE, indicator, style) 1053 self.SendScintilla(QsciScintilla.SCI_INDICSETSTYLE, indicator, style)
1055 self.SendScintilla(QsciScintilla.SCI_INDICSETFORE, indicator, color) 1054 self.SendScintilla(QsciScintilla.SCI_INDICSETFORE, indicator, color)
1056 with contextlib.suppress(AttributeError): 1055 with contextlib.suppress(AttributeError):
1057 self.SendScintilla(QsciScintilla.SCI_INDICSETALPHA, indicator, 1056 self.SendScintilla(
1058 color.alpha()) 1057 QsciScintilla.SCI_INDICSETALPHA, indicator, color.alpha()
1058 )
1059 if style in ( 1059 if style in (
1060 QsciScintilla.INDIC_ROUNDBOX, QsciScintilla.INDIC_STRAIGHTBOX, 1060 QsciScintilla.INDIC_ROUNDBOX,
1061 QsciScintilla.INDIC_DOTBOX, QsciScintilla.INDIC_FULLBOX, 1061 QsciScintilla.INDIC_STRAIGHTBOX,
1062 QsciScintilla.INDIC_DOTBOX,
1063 QsciScintilla.INDIC_FULLBOX,
1062 ): 1064 ):
1063 # set outline alpha less transparent 1065 # set outline alpha less transparent
1064 self.SendScintilla(QsciScintilla.SCI_INDICSETOUTLINEALPHA, 1066 self.SendScintilla(
1065 indicator, color.alpha() + 20) 1067 QsciScintilla.SCI_INDICSETOUTLINEALPHA,
1066 1068 indicator,
1069 color.alpha() + 20,
1070 )
1071
1067 def setCurrentIndicator(self, indicator): 1072 def setCurrentIndicator(self, indicator):
1068 """ 1073 """
1069 Public method to set the current indicator. 1074 Public method to set the current indicator.
1070 1075
1071 @param indicator number of the indicator (integer, 1076 @param indicator number of the indicator (integer,
1072 QsciScintilla.INDIC_CONTAINER .. QsciScintilla.INDIC_MAX) 1077 QsciScintilla.INDIC_CONTAINER .. QsciScintilla.INDIC_MAX)
1073 @exception ValueError the indicator or style are not valid 1078 @exception ValueError the indicator or style are not valid
1074 """ 1079 """
1075 if ( 1080 if (
1076 indicator < QsciScintilla.INDIC_CONTAINER or 1081 indicator < QsciScintilla.INDIC_CONTAINER
1077 indicator > QsciScintilla.INDIC_MAX 1082 or indicator > QsciScintilla.INDIC_MAX
1078 ): 1083 ):
1079 raise ValueError("indicator number out of range") 1084 raise ValueError("indicator number out of range")
1080 1085
1081 self.SendScintilla(QsciScintilla.SCI_SETINDICATORCURRENT, indicator) 1086 self.SendScintilla(QsciScintilla.SCI_SETINDICATORCURRENT, indicator)
1082 1087
1083 def setIndicatorRange(self, indicator, spos, length): 1088 def setIndicatorRange(self, indicator, spos, length):
1084 """ 1089 """
1085 Public method to set an indicator for the given range. 1090 Public method to set an indicator for the given range.
1086 1091
1087 @param indicator number of the indicator (integer, 1092 @param indicator number of the indicator (integer,
1088 QsciScintilla.INDIC_CONTAINER .. QsciScintilla.INDIC_MAX) 1093 QsciScintilla.INDIC_CONTAINER .. QsciScintilla.INDIC_MAX)
1089 @param spos position of the indicator start (integer) 1094 @param spos position of the indicator start (integer)
1090 @param length length of the indicator (integer) 1095 @param length length of the indicator (integer)
1091 """ 1096 """
1092 self.setCurrentIndicator(indicator) 1097 self.setCurrentIndicator(indicator)
1093 self.SendScintilla(QsciScintilla.SCI_INDICATORFILLRANGE, spos, length) 1098 self.SendScintilla(QsciScintilla.SCI_INDICATORFILLRANGE, spos, length)
1094 1099
1095 def setIndicator(self, indicator, sline, sindex, eline, eindex): 1100 def setIndicator(self, indicator, sline, sindex, eline, eindex):
1096 """ 1101 """
1097 Public method to set an indicator for the given range. 1102 Public method to set an indicator for the given range.
1098 1103
1099 @param indicator number of the indicator (integer, 1104 @param indicator number of the indicator (integer,
1100 QsciScintilla.INDIC_CONTAINER .. QsciScintilla.INDIC_MAX) 1105 QsciScintilla.INDIC_CONTAINER .. QsciScintilla.INDIC_MAX)
1101 @param sline line number of the indicator start (integer) 1106 @param sline line number of the indicator start (integer)
1102 @param sindex index of the indicator start (integer) 1107 @param sindex index of the indicator start (integer)
1103 @param eline line number of the indicator end (integer) 1108 @param eline line number of the indicator end (integer)
1104 @param eindex index of the indicator end (integer) 1109 @param eindex index of the indicator end (integer)
1105 """ 1110 """
1106 spos = self.positionFromLineIndex(sline, sindex) 1111 spos = self.positionFromLineIndex(sline, sindex)
1107 epos = self.positionFromLineIndex(eline, eindex) 1112 epos = self.positionFromLineIndex(eline, eindex)
1108 self.setIndicatorRange(indicator, spos, epos - spos) 1113 self.setIndicatorRange(indicator, spos, epos - spos)
1109 1114
1110 def clearIndicatorRange(self, indicator, spos, length): 1115 def clearIndicatorRange(self, indicator, spos, length):
1111 """ 1116 """
1112 Public method to clear an indicator for the given range. 1117 Public method to clear an indicator for the given range.
1113 1118
1114 @param indicator number of the indicator (integer, 1119 @param indicator number of the indicator (integer,
1115 QsciScintilla.INDIC_CONTAINER .. QsciScintilla.INDIC_MAX) 1120 QsciScintilla.INDIC_CONTAINER .. QsciScintilla.INDIC_MAX)
1116 @param spos position of the indicator start (integer) 1121 @param spos position of the indicator start (integer)
1117 @param length length of the indicator (integer) 1122 @param length length of the indicator (integer)
1118 """ 1123 """
1119 self.setCurrentIndicator(indicator) 1124 self.setCurrentIndicator(indicator)
1120 self.SendScintilla(QsciScintilla.SCI_INDICATORCLEARRANGE, spos, length) 1125 self.SendScintilla(QsciScintilla.SCI_INDICATORCLEARRANGE, spos, length)
1121 1126
1122 def clearIndicator(self, indicator, sline, sindex, eline, eindex): 1127 def clearIndicator(self, indicator, sline, sindex, eline, eindex):
1123 """ 1128 """
1124 Public method to clear an indicator for the given range. 1129 Public method to clear an indicator for the given range.
1125 1130
1126 @param indicator number of the indicator (integer, 1131 @param indicator number of the indicator (integer,
1127 QsciScintilla.INDIC_CONTAINER .. QsciScintilla.INDIC_MAX) 1132 QsciScintilla.INDIC_CONTAINER .. QsciScintilla.INDIC_MAX)
1128 @param sline line number of the indicator start (integer) 1133 @param sline line number of the indicator start (integer)
1129 @param sindex index of the indicator start (integer) 1134 @param sindex index of the indicator start (integer)
1130 @param eline line number of the indicator end (integer) 1135 @param eline line number of the indicator end (integer)
1131 @param eindex index of the indicator end (integer) 1136 @param eindex index of the indicator end (integer)
1132 """ 1137 """
1133 spos = self.positionFromLineIndex(sline, sindex) 1138 spos = self.positionFromLineIndex(sline, sindex)
1134 epos = self.positionFromLineIndex(eline, eindex) 1139 epos = self.positionFromLineIndex(eline, eindex)
1135 self.clearIndicatorRange(indicator, spos, epos - spos) 1140 self.clearIndicatorRange(indicator, spos, epos - spos)
1136 1141
1137 def clearAllIndicators(self, indicator): 1142 def clearAllIndicators(self, indicator):
1138 """ 1143 """
1139 Public method to clear all occurrences of an indicator. 1144 Public method to clear all occurrences of an indicator.
1140 1145
1141 @param indicator number of the indicator (integer, 1146 @param indicator number of the indicator (integer,
1142 QsciScintilla.INDIC_CONTAINER .. QsciScintilla.INDIC_MAX) 1147 QsciScintilla.INDIC_CONTAINER .. QsciScintilla.INDIC_MAX)
1143 """ 1148 """
1144 self.clearIndicatorRange(indicator, 0, self.length()) 1149 self.clearIndicatorRange(indicator, 0, self.length())
1145 1150
1146 def hasIndicator(self, indicator, pos): 1151 def hasIndicator(self, indicator, pos):
1147 """ 1152 """
1148 Public method to test for the existence of an indicator. 1153 Public method to test for the existence of an indicator.
1149 1154
1150 @param indicator number of the indicator (integer, 1155 @param indicator number of the indicator (integer,
1151 QsciScintilla.INDIC_CONTAINER .. QsciScintilla.INDIC_MAX) 1156 QsciScintilla.INDIC_CONTAINER .. QsciScintilla.INDIC_MAX)
1152 @param pos position to test (integer) 1157 @param pos position to test (integer)
1153 @return flag indicating the existence of the indicator (boolean) 1158 @return flag indicating the existence of the indicator (boolean)
1154 """ 1159 """
1155 res = self.SendScintilla(QsciScintilla.SCI_INDICATORVALUEAT, 1160 res = self.SendScintilla(QsciScintilla.SCI_INDICATORVALUEAT, indicator, pos)
1156 indicator, pos)
1157 return res 1161 return res
1158 1162
1159 def showFindIndicator(self, sline, sindex, eline, eindex): 1163 def showFindIndicator(self, sline, sindex, eline, eindex):
1160 """ 1164 """
1161 Public method to show the find indicator for the given range. 1165 Public method to show the find indicator for the given range.
1162 1166
1163 @param sline line number of the indicator start (integer) 1167 @param sline line number of the indicator start (integer)
1164 @param sindex index of the indicator start (integer) 1168 @param sindex index of the indicator start (integer)
1165 @param eline line number of the indicator end (integer) 1169 @param eline line number of the indicator end (integer)
1166 @param eindex index of the indicator end (integer) 1170 @param eindex index of the indicator end (integer)
1167 """ 1171 """
1168 if hasattr(QsciScintilla, "SCI_FINDINDICATORSHOW"): 1172 if hasattr(QsciScintilla, "SCI_FINDINDICATORSHOW"):
1169 spos = self.positionFromLineIndex(sline, sindex) 1173 spos = self.positionFromLineIndex(sline, sindex)
1170 epos = self.positionFromLineIndex(eline, eindex) 1174 epos = self.positionFromLineIndex(eline, eindex)
1171 self.SendScintilla(QsciScintilla.SCI_FINDINDICATORSHOW, spos, epos) 1175 self.SendScintilla(QsciScintilla.SCI_FINDINDICATORSHOW, spos, epos)
1172 1176
1173 def flashFindIndicator(self, sline, sindex, eline, eindex): 1177 def flashFindIndicator(self, sline, sindex, eline, eindex):
1174 """ 1178 """
1175 Public method to flash the find indicator for the given range. 1179 Public method to flash the find indicator for the given range.
1176 1180
1177 @param sline line number of the indicator start (integer) 1181 @param sline line number of the indicator start (integer)
1178 @param sindex index of the indicator start (integer) 1182 @param sindex index of the indicator start (integer)
1179 @param eline line number of the indicator end (integer) 1183 @param eline line number of the indicator end (integer)
1180 @param eindex index of the indicator end (integer) 1184 @param eindex index of the indicator end (integer)
1181 """ 1185 """
1182 if hasattr(QsciScintilla, "SCI_FINDINDICATORFLASH"): 1186 if hasattr(QsciScintilla, "SCI_FINDINDICATORFLASH"):
1183 spos = self.positionFromLineIndex(sline, sindex) 1187 spos = self.positionFromLineIndex(sline, sindex)
1184 epos = self.positionFromLineIndex(eline, eindex) 1188 epos = self.positionFromLineIndex(eline, eindex)
1185 self.SendScintilla(QsciScintilla.SCI_FINDINDICATORFLASH, 1189 self.SendScintilla(QsciScintilla.SCI_FINDINDICATORFLASH, spos, epos)
1186 spos, epos) 1190
1187
1188 def hideFindIndicator(self): 1191 def hideFindIndicator(self):
1189 """ 1192 """
1190 Public method to hide the find indicator. 1193 Public method to hide the find indicator.
1191 """ 1194 """
1192 if hasattr(QsciScintilla, "SCI_FINDINDICATORHIDE"): 1195 if hasattr(QsciScintilla, "SCI_FINDINDICATORHIDE"):
1193 self.SendScintilla(QsciScintilla.SCI_FINDINDICATORHIDE) 1196 self.SendScintilla(QsciScintilla.SCI_FINDINDICATORHIDE)
1194 1197
1195 def getIndicatorStartPos(self, indicator, pos): 1198 def getIndicatorStartPos(self, indicator, pos):
1196 """ 1199 """
1197 Public method to get the start position of an indicator at a position. 1200 Public method to get the start position of an indicator at a position.
1198 1201
1199 @param indicator ID of the indicator (integer) 1202 @param indicator ID of the indicator (integer)
1200 @param pos position within the indicator (integer) 1203 @param pos position within the indicator (integer)
1201 @return start position of the indicator (integer) 1204 @return start position of the indicator (integer)
1202 """ 1205 """
1203 return self.SendScintilla(QsciScintilla.SCI_INDICATORSTART, 1206 return self.SendScintilla(QsciScintilla.SCI_INDICATORSTART, indicator, pos)
1204 indicator, pos) 1207
1205
1206 def getIndicatorEndPos(self, indicator, pos): 1208 def getIndicatorEndPos(self, indicator, pos):
1207 """ 1209 """
1208 Public method to get the end position of an indicator at a position. 1210 Public method to get the end position of an indicator at a position.
1209 1211
1210 @param indicator ID of the indicator (integer) 1212 @param indicator ID of the indicator (integer)
1211 @param pos position within the indicator (integer) 1213 @param pos position within the indicator (integer)
1212 @return end position of the indicator (integer) 1214 @return end position of the indicator (integer)
1213 """ 1215 """
1214 return self.SendScintilla(QsciScintilla.SCI_INDICATOREND, 1216 return self.SendScintilla(QsciScintilla.SCI_INDICATOREND, indicator, pos)
1215 indicator, pos) 1217
1216
1217 def gotoPreviousIndicator(self, indicator, wrap): 1218 def gotoPreviousIndicator(self, indicator, wrap):
1218 """ 1219 """
1219 Public method to move the cursor to the previous position of an 1220 Public method to move the cursor to the previous position of an
1220 indicator. 1221 indicator.
1221 1222
1222 This method ensures, that the position found is visible (i.e. unfolded 1223 This method ensures, that the position found is visible (i.e. unfolded
1223 and inside the visible range). The text containing the indicator is 1224 and inside the visible range). The text containing the indicator is
1224 selected. 1225 selected.
1225 1226
1226 @param indicator ID of the indicator to search (integer) 1227 @param indicator ID of the indicator to search (integer)
1227 @param wrap flag indicating to wrap around at the beginning of the 1228 @param wrap flag indicating to wrap around at the beginning of the
1228 text (boolean) 1229 text (boolean)
1229 @return flag indicating if the indicator was found (boolean) 1230 @return flag indicating if the indicator was found (boolean)
1230 """ 1231 """
1231 pos = self.SendScintilla(QsciScintilla.SCI_GETCURRENTPOS) 1232 pos = self.SendScintilla(QsciScintilla.SCI_GETCURRENTPOS)
1232 docLen = self.SendScintilla(QsciScintilla.SCI_GETTEXTLENGTH) 1233 docLen = self.SendScintilla(QsciScintilla.SCI_GETTEXTLENGTH)
1233 isInIndicator = self.hasIndicator(indicator, pos) 1234 isInIndicator = self.hasIndicator(indicator, pos)
1234 posStart = self.getIndicatorStartPos(indicator, pos) 1235 posStart = self.getIndicatorStartPos(indicator, pos)
1235 posEnd = self.getIndicatorEndPos(indicator, pos) 1236 posEnd = self.getIndicatorEndPos(indicator, pos)
1236 1237
1237 if posStart == 0 and posEnd == docLen - 1: 1238 if posStart == 0 and posEnd == docLen - 1:
1238 # indicator does not exist 1239 # indicator does not exist
1239 return False 1240 return False
1240 1241
1241 if posStart <= 0: 1242 if posStart <= 0:
1242 if not wrap: 1243 if not wrap:
1243 return False 1244 return False
1244 1245
1245 isInIndicator = self.hasIndicator(indicator, docLen - 1) 1246 isInIndicator = self.hasIndicator(indicator, docLen - 1)
1246 posStart = self.getIndicatorStartPos(indicator, docLen - 1) 1247 posStart = self.getIndicatorStartPos(indicator, docLen - 1)
1247 1248
1248 if isInIndicator: 1249 if isInIndicator:
1249 # get out of it 1250 # get out of it
1250 posStart = self.getIndicatorStartPos(indicator, posStart - 1) 1251 posStart = self.getIndicatorStartPos(indicator, posStart - 1)
1251 if posStart <= 0: 1252 if posStart <= 0:
1252 if not wrap: 1253 if not wrap:
1253 return False 1254 return False
1254 1255
1255 posStart = self.getIndicatorStartPos(indicator, docLen - 1) 1256 posStart = self.getIndicatorStartPos(indicator, docLen - 1)
1256 1257
1257 newPos = posStart - 1 1258 newPos = posStart - 1
1258 posStart = self.getIndicatorStartPos(indicator, newPos) 1259 posStart = self.getIndicatorStartPos(indicator, newPos)
1259 posEnd = self.getIndicatorEndPos(indicator, newPos) 1260 posEnd = self.getIndicatorEndPos(indicator, newPos)
1260 1261
1261 if self.hasIndicator(indicator, posStart): 1262 if self.hasIndicator(indicator, posStart):
1262 # found it 1263 # found it
1263 line, index = self.lineIndexFromPosition(posEnd) 1264 line, index = self.lineIndexFromPosition(posEnd)
1264 self.ensureLineVisible(line) 1265 self.ensureLineVisible(line)
1265 self.SendScintilla(QsciScintilla.SCI_SETSEL, posEnd, posStart) 1266 self.SendScintilla(QsciScintilla.SCI_SETSEL, posEnd, posStart)
1266 self.SendScintilla(QsciScintilla.SCI_SCROLLCARET) 1267 self.SendScintilla(QsciScintilla.SCI_SCROLLCARET)
1267 return True 1268 return True
1268 1269
1269 return False 1270 return False
1270 1271
1271 def gotoNextIndicator(self, indicator, wrap): 1272 def gotoNextIndicator(self, indicator, wrap):
1272 """ 1273 """
1273 Public method to move the cursor to the next position of an indicator. 1274 Public method to move the cursor to the next position of an indicator.
1274 1275
1275 This method ensures, that the position found is visible (i.e. unfolded 1276 This method ensures, that the position found is visible (i.e. unfolded
1276 and inside the visible range). The text containing the indicator is 1277 and inside the visible range). The text containing the indicator is
1277 selected. 1278 selected.
1278 1279
1279 @param indicator ID of the indicator to search (integer) 1280 @param indicator ID of the indicator to search (integer)
1280 @param wrap flag indicating to wrap around at the beginning of the 1281 @param wrap flag indicating to wrap around at the beginning of the
1281 text (boolean) 1282 text (boolean)
1282 @return flag indicating if the indicator was found (boolean) 1283 @return flag indicating if the indicator was found (boolean)
1283 """ 1284 """
1284 pos = self.SendScintilla(QsciScintilla.SCI_GETCURRENTPOS) 1285 pos = self.SendScintilla(QsciScintilla.SCI_GETCURRENTPOS)
1285 docLen = self.SendScintilla(QsciScintilla.SCI_GETTEXTLENGTH) 1286 docLen = self.SendScintilla(QsciScintilla.SCI_GETTEXTLENGTH)
1286 isInIndicator = self.hasIndicator(indicator, pos) 1287 isInIndicator = self.hasIndicator(indicator, pos)
1287 posStart = self.getIndicatorStartPos(indicator, pos) 1288 posStart = self.getIndicatorStartPos(indicator, pos)
1288 posEnd = self.getIndicatorEndPos(indicator, pos) 1289 posEnd = self.getIndicatorEndPos(indicator, pos)
1289 1290
1290 if posStart == 0 and posEnd == docLen - 1: 1291 if posStart == 0 and posEnd == docLen - 1:
1291 # indicator does not exist 1292 # indicator does not exist
1292 return False 1293 return False
1293 1294
1294 if posEnd >= docLen: 1295 if posEnd >= docLen:
1295 if not wrap: 1296 if not wrap:
1296 return False 1297 return False
1297 1298
1298 isInIndicator = self.hasIndicator(indicator, 0) 1299 isInIndicator = self.hasIndicator(indicator, 0)
1299 posEnd = self.getIndicatorEndPos(indicator, 0) 1300 posEnd = self.getIndicatorEndPos(indicator, 0)
1300 1301
1301 if isInIndicator: 1302 if isInIndicator:
1302 # get out of it 1303 # get out of it
1303 posEnd = self.getIndicatorEndPos(indicator, posEnd) 1304 posEnd = self.getIndicatorEndPos(indicator, posEnd)
1304 if posEnd >= docLen: 1305 if posEnd >= docLen:
1305 if not wrap: 1306 if not wrap:
1306 return False 1307 return False
1307 1308
1308 posEnd = self.getIndicatorEndPos(indicator, 0) 1309 posEnd = self.getIndicatorEndPos(indicator, 0)
1309 1310
1310 newPos = posEnd + 1 1311 newPos = posEnd + 1
1311 posStart = self.getIndicatorStartPos(indicator, newPos) 1312 posStart = self.getIndicatorStartPos(indicator, newPos)
1312 posEnd = self.getIndicatorEndPos(indicator, newPos) 1313 posEnd = self.getIndicatorEndPos(indicator, newPos)
1313 1314
1314 if self.hasIndicator(indicator, posStart): 1315 if self.hasIndicator(indicator, posStart):
1315 # found it 1316 # found it
1316 line, index = self.lineIndexFromPosition(posEnd) 1317 line, index = self.lineIndexFromPosition(posEnd)
1317 self.ensureLineVisible(line) 1318 self.ensureLineVisible(line)
1318 self.SendScintilla(QsciScintilla.SCI_SETSEL, posStart, posEnd) 1319 self.SendScintilla(QsciScintilla.SCI_SETSEL, posStart, posEnd)
1319 self.SendScintilla(QsciScintilla.SCI_SCROLLCARET) 1320 self.SendScintilla(QsciScintilla.SCI_SCROLLCARET)
1320 return True 1321 return True
1321 1322
1322 return False 1323 return False
1323 1324
1324 ########################################################################### 1325 ###########################################################################
1325 ## methods to perform folding related stuff 1326 ## methods to perform folding related stuff
1326 ########################################################################### 1327 ###########################################################################
1327 1328
1328 def __setFoldMarker(self, marknr, mark=QsciScintilla.SC_MARK_EMPTY): 1329 def __setFoldMarker(self, marknr, mark=QsciScintilla.SC_MARK_EMPTY):
1329 """ 1330 """
1330 Private method to define a fold marker. 1331 Private method to define a fold marker.
1331 1332
1332 @param marknr marker number to define (integer) 1333 @param marknr marker number to define (integer)
1333 @param mark fold mark symbol to be used (integer) 1334 @param mark fold mark symbol to be used (integer)
1334 """ 1335 """
1335 self.SendScintilla(QsciScintilla.SCI_MARKERDEFINE, marknr, mark) 1336 self.SendScintilla(QsciScintilla.SCI_MARKERDEFINE, marknr, mark)
1336 1337
1337 if mark != QsciScintilla.SC_MARK_EMPTY: 1338 if mark != QsciScintilla.SC_MARK_EMPTY:
1338 self.SendScintilla(QsciScintilla.SCI_MARKERSETFORE, 1339 self.SendScintilla(
1339 marknr, QColor(Qt.GlobalColor.white)) 1340 QsciScintilla.SCI_MARKERSETFORE, marknr, QColor(Qt.GlobalColor.white)
1340 self.SendScintilla(QsciScintilla.SCI_MARKERSETBACK, 1341 )
1341 marknr, QColor(Qt.GlobalColor.black)) 1342 self.SendScintilla(
1342 1343 QsciScintilla.SCI_MARKERSETBACK, marknr, QColor(Qt.GlobalColor.black)
1344 )
1345
1343 def setFolding(self, style, margin=2): 1346 def setFolding(self, style, margin=2):
1344 """ 1347 """
1345 Public method to set the folding style and margin. 1348 Public method to set the folding style and margin.
1346 1349
1347 @param style folding style to set (integer) 1350 @param style folding style to set (integer)
1348 @param margin margin number (integer) 1351 @param margin margin number (integer)
1349 """ 1352 """
1350 if isinstance(style, QsciScintilla.FoldStyle): 1353 if isinstance(style, QsciScintilla.FoldStyle):
1351 super().setFolding(QsciScintilla.FoldStyle(style), margin) 1354 super().setFolding(QsciScintilla.FoldStyle(style), margin)
1352 else: 1355 else:
1353 super().setFolding( 1356 super().setFolding(QsciScintilla.FoldStyle.PlainFoldStyle, margin)
1354 QsciScintilla.FoldStyle.PlainFoldStyle, margin) 1357
1355
1356 if style == self.ArrowFoldStyle: 1358 if style == self.ArrowFoldStyle:
1357 self.__setFoldMarker(QsciScintilla.SC_MARKNUM_FOLDER, 1359 self.__setFoldMarker(
1358 QsciScintilla.SC_MARK_ARROW) 1360 QsciScintilla.SC_MARKNUM_FOLDER, QsciScintilla.SC_MARK_ARROW
1359 self.__setFoldMarker(QsciScintilla.SC_MARKNUM_FOLDEROPEN, 1361 )
1360 QsciScintilla.SC_MARK_ARROWDOWN) 1362 self.__setFoldMarker(
1363 QsciScintilla.SC_MARKNUM_FOLDEROPEN, QsciScintilla.SC_MARK_ARROWDOWN
1364 )
1361 self.__setFoldMarker(QsciScintilla.SC_MARKNUM_FOLDERSUB) 1365 self.__setFoldMarker(QsciScintilla.SC_MARKNUM_FOLDERSUB)
1362 self.__setFoldMarker(QsciScintilla.SC_MARKNUM_FOLDERTAIL) 1366 self.__setFoldMarker(QsciScintilla.SC_MARKNUM_FOLDERTAIL)
1363 self.__setFoldMarker(QsciScintilla.SC_MARKNUM_FOLDEREND) 1367 self.__setFoldMarker(QsciScintilla.SC_MARKNUM_FOLDEREND)
1364 self.__setFoldMarker(QsciScintilla.SC_MARKNUM_FOLDEROPENMID) 1368 self.__setFoldMarker(QsciScintilla.SC_MARKNUM_FOLDEROPENMID)
1365 self.__setFoldMarker(QsciScintilla.SC_MARKNUM_FOLDERMIDTAIL) 1369 self.__setFoldMarker(QsciScintilla.SC_MARKNUM_FOLDERMIDTAIL)
1366 elif style == self.ArrowTreeFoldStyle: 1370 elif style == self.ArrowTreeFoldStyle:
1367 self.__setFoldMarker(QsciScintilla.SC_MARKNUM_FOLDER, 1371 self.__setFoldMarker(
1368 QsciScintilla.SC_MARK_ARROW) 1372 QsciScintilla.SC_MARKNUM_FOLDER, QsciScintilla.SC_MARK_ARROW
1369 self.__setFoldMarker(QsciScintilla.SC_MARKNUM_FOLDEROPEN, 1373 )
1370 QsciScintilla.SC_MARK_ARROWDOWN) 1374 self.__setFoldMarker(
1371 self.__setFoldMarker(QsciScintilla.SC_MARKNUM_FOLDERSUB, 1375 QsciScintilla.SC_MARKNUM_FOLDEROPEN, QsciScintilla.SC_MARK_ARROWDOWN
1372 QsciScintilla.SC_MARK_VLINE) 1376 )
1373 self.__setFoldMarker(QsciScintilla.SC_MARKNUM_FOLDERTAIL, 1377 self.__setFoldMarker(
1374 QsciScintilla.SC_MARK_LCORNER) 1378 QsciScintilla.SC_MARKNUM_FOLDERSUB, QsciScintilla.SC_MARK_VLINE
1375 self.__setFoldMarker(QsciScintilla.SC_MARKNUM_FOLDEREND, 1379 )
1376 QsciScintilla.SC_MARK_ARROW) 1380 self.__setFoldMarker(
1377 self.__setFoldMarker(QsciScintilla.SC_MARKNUM_FOLDEROPENMID, 1381 QsciScintilla.SC_MARKNUM_FOLDERTAIL, QsciScintilla.SC_MARK_LCORNER
1378 QsciScintilla.SC_MARK_ARROWDOWN) 1382 )
1379 self.__setFoldMarker(QsciScintilla.SC_MARKNUM_FOLDERMIDTAIL, 1383 self.__setFoldMarker(
1380 QsciScintilla.SC_MARK_TCORNER) 1384 QsciScintilla.SC_MARKNUM_FOLDEREND, QsciScintilla.SC_MARK_ARROW
1381 1385 )
1386 self.__setFoldMarker(
1387 QsciScintilla.SC_MARKNUM_FOLDEROPENMID,
1388 QsciScintilla.SC_MARK_ARROWDOWN,
1389 )
1390 self.__setFoldMarker(
1391 QsciScintilla.SC_MARKNUM_FOLDERMIDTAIL,
1392 QsciScintilla.SC_MARK_TCORNER,
1393 )
1394
1382 def setFoldMarkersColors(self, foreColor, backColor): 1395 def setFoldMarkersColors(self, foreColor, backColor):
1383 """ 1396 """
1384 Public method to set the foreground and background colors of the 1397 Public method to set the foreground and background colors of the
1385 fold markers. 1398 fold markers.
1386 1399
1387 @param foreColor foreground color (QColor) 1400 @param foreColor foreground color (QColor)
1388 @param backColor background color (QColor) 1401 @param backColor background color (QColor)
1389 """ 1402 """
1390 self.SendScintilla(QsciScintilla.SCI_MARKERSETFORE, 1403 self.SendScintilla(
1391 QsciScintilla.SC_MARKNUM_FOLDER, foreColor) 1404 QsciScintilla.SCI_MARKERSETFORE, QsciScintilla.SC_MARKNUM_FOLDER, foreColor
1392 self.SendScintilla(QsciScintilla.SCI_MARKERSETBACK, 1405 )
1393 QsciScintilla.SC_MARKNUM_FOLDER, backColor) 1406 self.SendScintilla(
1394 1407 QsciScintilla.SCI_MARKERSETBACK, QsciScintilla.SC_MARKNUM_FOLDER, backColor
1395 self.SendScintilla(QsciScintilla.SCI_MARKERSETFORE, 1408 )
1396 QsciScintilla.SC_MARKNUM_FOLDEROPEN, foreColor) 1409
1397 self.SendScintilla(QsciScintilla.SCI_MARKERSETBACK, 1410 self.SendScintilla(
1398 QsciScintilla.SC_MARKNUM_FOLDEROPEN, backColor) 1411 QsciScintilla.SCI_MARKERSETFORE,
1399 1412 QsciScintilla.SC_MARKNUM_FOLDEROPEN,
1400 self.SendScintilla(QsciScintilla.SCI_MARKERSETFORE, 1413 foreColor,
1401 QsciScintilla.SC_MARKNUM_FOLDEROPENMID, foreColor) 1414 )
1402 self.SendScintilla(QsciScintilla.SCI_MARKERSETBACK, 1415 self.SendScintilla(
1403 QsciScintilla.SC_MARKNUM_FOLDEROPENMID, backColor) 1416 QsciScintilla.SCI_MARKERSETBACK,
1404 1417 QsciScintilla.SC_MARKNUM_FOLDEROPEN,
1405 self.SendScintilla(QsciScintilla.SCI_MARKERSETFORE, 1418 backColor,
1406 QsciScintilla.SC_MARKNUM_FOLDERSUB, foreColor) 1419 )
1407 self.SendScintilla(QsciScintilla.SCI_MARKERSETBACK, 1420
1408 QsciScintilla.SC_MARKNUM_FOLDERSUB, backColor) 1421 self.SendScintilla(
1409 1422 QsciScintilla.SCI_MARKERSETFORE,
1410 self.SendScintilla(QsciScintilla.SCI_MARKERSETFORE, 1423 QsciScintilla.SC_MARKNUM_FOLDEROPENMID,
1411 QsciScintilla.SC_MARKNUM_FOLDERTAIL, foreColor) 1424 foreColor,
1412 self.SendScintilla(QsciScintilla.SCI_MARKERSETBACK, 1425 )
1413 QsciScintilla.SC_MARKNUM_FOLDERTAIL, backColor) 1426 self.SendScintilla(
1414 1427 QsciScintilla.SCI_MARKERSETBACK,
1415 self.SendScintilla(QsciScintilla.SCI_MARKERSETFORE, 1428 QsciScintilla.SC_MARKNUM_FOLDEROPENMID,
1416 QsciScintilla.SC_MARKNUM_FOLDERMIDTAIL, foreColor) 1429 backColor,
1417 self.SendScintilla(QsciScintilla.SCI_MARKERSETBACK, 1430 )
1418 QsciScintilla.SC_MARKNUM_FOLDERMIDTAIL, backColor) 1431
1419 1432 self.SendScintilla(
1420 self.SendScintilla(QsciScintilla.SCI_MARKERSETFORE, 1433 QsciScintilla.SCI_MARKERSETFORE,
1421 QsciScintilla.SC_MARKNUM_FOLDEREND, foreColor) 1434 QsciScintilla.SC_MARKNUM_FOLDERSUB,
1422 self.SendScintilla(QsciScintilla.SCI_MARKERSETBACK, 1435 foreColor,
1423 QsciScintilla.SC_MARKNUM_FOLDEREND, backColor) 1436 )
1424 1437 self.SendScintilla(
1438 QsciScintilla.SCI_MARKERSETBACK,
1439 QsciScintilla.SC_MARKNUM_FOLDERSUB,
1440 backColor,
1441 )
1442
1443 self.SendScintilla(
1444 QsciScintilla.SCI_MARKERSETFORE,
1445 QsciScintilla.SC_MARKNUM_FOLDERTAIL,
1446 foreColor,
1447 )
1448 self.SendScintilla(
1449 QsciScintilla.SCI_MARKERSETBACK,
1450 QsciScintilla.SC_MARKNUM_FOLDERTAIL,
1451 backColor,
1452 )
1453
1454 self.SendScintilla(
1455 QsciScintilla.SCI_MARKERSETFORE,
1456 QsciScintilla.SC_MARKNUM_FOLDERMIDTAIL,
1457 foreColor,
1458 )
1459 self.SendScintilla(
1460 QsciScintilla.SCI_MARKERSETBACK,
1461 QsciScintilla.SC_MARKNUM_FOLDERMIDTAIL,
1462 backColor,
1463 )
1464
1465 self.SendScintilla(
1466 QsciScintilla.SCI_MARKERSETFORE,
1467 QsciScintilla.SC_MARKNUM_FOLDEREND,
1468 foreColor,
1469 )
1470 self.SendScintilla(
1471 QsciScintilla.SCI_MARKERSETBACK,
1472 QsciScintilla.SC_MARKNUM_FOLDEREND,
1473 backColor,
1474 )
1475
1425 def getVisibleLineFromDocLine(self, docLine): 1476 def getVisibleLineFromDocLine(self, docLine):
1426 """ 1477 """
1427 Public method to convert a document line number to a visible line 1478 Public method to convert a document line number to a visible line
1428 number (i.e. respect folded lines and annotations). 1479 number (i.e. respect folded lines and annotations).
1429 1480
1430 @param docLine document line number to be converted 1481 @param docLine document line number to be converted
1431 @type int 1482 @type int
1432 @return visible line number 1483 @return visible line number
1433 @rtype int 1484 @rtype int
1434 """ 1485 """
1435 return self.SendScintilla(QsciScintilla.SCI_VISIBLEFROMDOCLINE, 1486 return self.SendScintilla(QsciScintilla.SCI_VISIBLEFROMDOCLINE, docLine)
1436 docLine) 1487
1437
1438 def getDocLineFromVisibleLine(self, displayLine): 1488 def getDocLineFromVisibleLine(self, displayLine):
1439 """ 1489 """
1440 Public method to convert a visible line number to a document line 1490 Public method to convert a visible line number to a document line
1441 number (i.e. respect folded lines and annotations). 1491 number (i.e. respect folded lines and annotations).
1442 1492
1443 @param displayLine display line number to be converted 1493 @param displayLine display line number to be converted
1444 @type int 1494 @type int
1445 @return document line number 1495 @return document line number
1446 @rtype int 1496 @rtype int
1447 """ 1497 """
1448 return self.SendScintilla(QsciScintilla.SCI_DOCLINEFROMVISIBLE, 1498 return self.SendScintilla(QsciScintilla.SCI_DOCLINEFROMVISIBLE, displayLine)
1449 displayLine) 1499
1450
1451 ########################################################################### 1500 ###########################################################################
1452 ## interface methods to the standard keyboard command set 1501 ## interface methods to the standard keyboard command set
1453 ########################################################################### 1502 ###########################################################################
1454 1503
1455 def clearKeys(self): 1504 def clearKeys(self):
1456 """ 1505 """
1457 Public method to clear the key commands. 1506 Public method to clear the key commands.
1458 """ 1507 """
1459 # call into the QsciCommandSet 1508 # call into the QsciCommandSet
1460 self.standardCommands().clearKeys() 1509 self.standardCommands().clearKeys()
1461 1510
1462 def clearAlternateKeys(self): 1511 def clearAlternateKeys(self):
1463 """ 1512 """
1464 Public method to clear the alternate key commands. 1513 Public method to clear the alternate key commands.
1465 """ 1514 """
1466 # call into the QsciCommandSet 1515 # call into the QsciCommandSet
1467 self.standardCommands().clearAlternateKeys() 1516 self.standardCommands().clearAlternateKeys()
1468 1517
1469 ########################################################################### 1518 ###########################################################################
1470 ## specialized event handlers 1519 ## specialized event handlers
1471 ########################################################################### 1520 ###########################################################################
1472 1521
1473 def focusOutEvent(self, event): 1522 def focusOutEvent(self, event):
1474 """ 1523 """
1475 Protected method called when the editor loses focus. 1524 Protected method called when the editor loses focus.
1476 1525
1477 @param event event object (QFocusEvent) 1526 @param event event object (QFocusEvent)
1478 """ 1527 """
1479 if self.isListActive(): 1528 if self.isListActive():
1480 if event.reason() in [ 1529 if event.reason() in [
1481 Qt.FocusReason.ActiveWindowFocusReason, 1530 Qt.FocusReason.ActiveWindowFocusReason,
1482 Qt.FocusReason.OtherFocusReason 1531 Qt.FocusReason.OtherFocusReason,
1483 ]: 1532 ]:
1484 aw = QApplication.activeWindow() 1533 aw = QApplication.activeWindow()
1485 if aw is None or aw.parent() is not self: 1534 if aw is None or aw.parent() is not self:
1486 self.cancelList() 1535 self.cancelList()
1487 else: 1536 else:
1488 self.cancelList() 1537 self.cancelList()
1489 1538
1490 if self.isCallTipActive(): 1539 if self.isCallTipActive():
1491 if event.reason() in [ 1540 if event.reason() in [
1492 Qt.FocusReason.ActiveWindowFocusReason, 1541 Qt.FocusReason.ActiveWindowFocusReason,
1493 Qt.FocusReason.OtherFocusReason 1542 Qt.FocusReason.OtherFocusReason,
1494 ]: 1543 ]:
1495 aw = QApplication.activeWindow() 1544 aw = QApplication.activeWindow()
1496 if aw is None or aw.parent() is not self: 1545 if aw is None or aw.parent() is not self:
1497 self.cancelCallTips() 1546 self.cancelCallTips()
1498 else: 1547 else:
1499 self.cancelCallTips() 1548 self.cancelCallTips()
1500 1549
1501 super().focusOutEvent(event) 1550 super().focusOutEvent(event)
1502 1551
1503 def event(self, evt): 1552 def event(self, evt):
1504 """ 1553 """
1505 Public method to handle events. 1554 Public method to handle events.
1506 1555
1507 Note: We are not interested in the standard QsciScintilla event 1556 Note: We are not interested in the standard QsciScintilla event
1508 handling because we do it ourselves. 1557 handling because we do it ourselves.
1509 1558
1510 @param evt event object to handle (QEvent) 1559 @param evt event object to handle (QEvent)
1511 @return result of the event handling (boolean) 1560 @return result of the event handling (boolean)
1512 """ 1561 """
1513 return QsciScintillaBase.event(self, evt) 1562 return QsciScintillaBase.event(self, evt)
1514 1563
1517 ########################################################################### 1566 ###########################################################################
1518 1567
1519 def getFileName(self): 1568 def getFileName(self):
1520 """ 1569 """
1521 Public method to return the name of the file being displayed. 1570 Public method to return the name of the file being displayed.
1522 1571
1523 @return filename of the displayed file (string) 1572 @return filename of the displayed file (string)
1524 """ 1573 """
1525 p = self.parent() 1574 p = self.parent()
1526 if p is None: 1575 if p is None:
1527 return "" 1576 return ""
1528 else: 1577 else:
1529 try: 1578 try:
1530 return p.getFileName() 1579 return p.getFileName()
1531 except AttributeError: 1580 except AttributeError:
1532 return "" 1581 return ""
1533 1582
1534 ########################################################################### 1583 ###########################################################################
1535 ## replacements for buggy methods 1584 ## replacements for buggy methods
1536 ########################################################################### 1585 ###########################################################################
1537 1586
1538 def showUserList(self, listId, lst): 1587 def showUserList(self, listId, lst):
1539 """ 1588 """
1540 Public method to show a user supplied list. 1589 Public method to show a user supplied list.
1541 1590
1542 @param listId id of the list (integer) 1591 @param listId id of the list (integer)
1543 @param lst list to be show (list of strings) 1592 @param lst list to be show (list of strings)
1544 """ 1593 """
1545 if listId <= 0: 1594 if listId <= 0:
1546 return 1595 return
1547 1596
1548 # Setup seperator for user lists 1597 # Setup seperator for user lists
1598 self.SendScintilla(QsciScintilla.SCI_AUTOCSETSEPARATOR, ord(self.UserSeparator))
1549 self.SendScintilla( 1599 self.SendScintilla(
1550 QsciScintilla.SCI_AUTOCSETSEPARATOR, ord(self.UserSeparator)) 1600 QsciScintilla.SCI_USERLISTSHOW,
1551 self.SendScintilla( 1601 listId,
1552 QsciScintilla.SCI_USERLISTSHOW, listId, 1602 self._encodeString(self.UserSeparator.join(lst)),
1553 self._encodeString(self.UserSeparator.join(lst))) 1603 )
1554 1604
1555 self.updateUserListSize() 1605 self.updateUserListSize()
1556 1606
1557 def autoCompleteFromDocument(self): 1607 def autoCompleteFromDocument(self):
1558 """ 1608 """
1559 Public method to resize list box after creation. 1609 Public method to resize list box after creation.
1560 """ 1610 """
1561 super().autoCompleteFromDocument() 1611 super().autoCompleteFromDocument()
1562 self.updateUserListSize() 1612 self.updateUserListSize()
1563 1613
1564 def autoCompleteFromAPIs(self): 1614 def autoCompleteFromAPIs(self):
1565 """ 1615 """
1566 Public method to resize list box after creation. 1616 Public method to resize list box after creation.
1567 """ 1617 """
1568 super().autoCompleteFromAPIs() 1618 super().autoCompleteFromAPIs()
1569 self.updateUserListSize() 1619 self.updateUserListSize()
1570 1620
1571 def autoCompleteFromAll(self): 1621 def autoCompleteFromAll(self):
1572 """ 1622 """
1573 Public method to resize list box after creation. 1623 Public method to resize list box after creation.
1574 """ 1624 """
1575 super().autoCompleteFromAll() 1625 super().autoCompleteFromAll()
1576 self.updateUserListSize() 1626 self.updateUserListSize()
1577 1627
1578 ########################################################################### 1628 ###########################################################################
1579 ## work-around for buggy behavior 1629 ## work-around for buggy behavior
1580 ########################################################################### 1630 ###########################################################################
1581 1631
1582 def updateUserListSize(self): 1632 def updateUserListSize(self):
1583 """ 1633 """
1584 Public method to resize the completion list to fit with contents. 1634 Public method to resize the completion list to fit with contents.
1585 """ 1635 """
1586 children = self.findChildren(QListWidget) 1636 children = self.findChildren(QListWidget)
1587 if children: 1637 if children:
1588 userListWidget = children[-1] 1638 userListWidget = children[-1]
1589 hScrollbar = userListWidget.horizontalScrollBar() 1639 hScrollbar = userListWidget.horizontalScrollBar()
1590 if hScrollbar.isVisible(): 1640 if hScrollbar.isVisible():
1591 hScrollbarHeight = hScrollbar.sizeHint().height() 1641 hScrollbarHeight = hScrollbar.sizeHint().height()
1592 1642
1593 geom = userListWidget.geometry() 1643 geom = userListWidget.geometry()
1594 geom.setHeight(geom.height() + hScrollbarHeight) 1644 geom.setHeight(geom.height() + hScrollbarHeight)
1595 1645
1596 charPos = self.SendScintilla(QsciScintilla.SCI_GETCURRENTPOS) 1646 charPos = self.SendScintilla(QsciScintilla.SCI_GETCURRENTPOS)
1597 currentYPos = self.SendScintilla( 1647 currentYPos = self.SendScintilla(
1598 QsciScintilla.SCI_POINTYFROMPOSITION, 0, charPos) 1648 QsciScintilla.SCI_POINTYFROMPOSITION, 0, charPos
1649 )
1599 if geom.y() < currentYPos: 1650 if geom.y() < currentYPos:
1600 geom.setY(geom.y() - hScrollbarHeight) 1651 geom.setY(geom.y() - hScrollbarHeight)
1601 moveY = True 1652 moveY = True
1602 else: 1653 else:
1603 moveY = False 1654 moveY = False
1604 1655
1605 userListWidget.setGeometry(geom) 1656 userListWidget.setGeometry(geom)
1606 if moveY: 1657 if moveY:
1607 userListWidget.move(geom.x(), geom.y() - hScrollbarHeight) 1658 userListWidget.move(geom.x(), geom.y() - hScrollbarHeight)
1608 1659
1609 def __completionListSelected(self, listId, txt): 1660 def __completionListSelected(self, listId, txt):
1610 """ 1661 """
1611 Private slot to handle the selection from the completion list. 1662 Private slot to handle the selection from the completion list.
1612 1663
1613 Note: This works around an issue of some window managers taking 1664 Note: This works around an issue of some window managers taking
1614 focus away from the application when clicked inside a completion 1665 focus away from the application when clicked inside a completion
1615 list but not giving it back when an item is selected via a 1666 list but not giving it back when an item is selected via a
1616 double-click. 1667 double-click.
1617 1668
1618 @param listId the ID of the user list (integer) 1669 @param listId the ID of the user list (integer)
1619 @param txt the selected text (string) 1670 @param txt the selected text (string)
1620 """ 1671 """
1621 self.activateWindow() 1672 self.activateWindow()
1622 1673
1623 def updateVerticalScrollBar(self): 1674 def updateVerticalScrollBar(self):
1624 """ 1675 """
1625 Public method to update the vertical scroll bar to reflect the 1676 Public method to update the vertical scroll bar to reflect the
1626 additional lines added by annotations. 1677 additional lines added by annotations.
1627 """ 1678 """
1628 # Workaround because Scintilla.Redraw isn't implemented 1679 # Workaround because Scintilla.Redraw isn't implemented
1629 self.SendScintilla(QsciScintilla.SCI_SETVSCROLLBAR, 0) 1680 self.SendScintilla(QsciScintilla.SCI_SETVSCROLLBAR, 0)
1630 self.SendScintilla(QsciScintilla.SCI_SETVSCROLLBAR, 1) 1681 self.SendScintilla(QsciScintilla.SCI_SETVSCROLLBAR, 1)
1631 1682
1632 ########################################################################### 1683 ###########################################################################
1633 ## utility methods 1684 ## utility methods
1634 ########################################################################### 1685 ###########################################################################
1635 1686
1636 def _encodeString(self, string): 1687 def _encodeString(self, string):
1637 """ 1688 """
1638 Protected method to encode a string depending on the current mode. 1689 Protected method to encode a string depending on the current mode.
1639 1690
1640 @param string string to be encoded (str) 1691 @param string string to be encoded (str)
1641 @return encoded string (bytes) 1692 @return encoded string (bytes)
1642 """ 1693 """
1643 if isinstance(string, bytes): 1694 if isinstance(string, bytes):
1644 return string 1695 return string
1645 else: 1696 else:
1646 if self.isUtf8(): 1697 if self.isUtf8():
1647 return string.encode("utf-8") 1698 return string.encode("utf-8")
1648 else: 1699 else:
1649 return string.encode("latin-1") 1700 return string.encode("latin-1")
1650 1701
1651 ######################################################################### 1702 #########################################################################
1652 ## Methods below are missing from QScintilla. 1703 ## Methods below are missing from QScintilla.
1653 ######################################################################### 1704 #########################################################################
1654 1705
1655 if "setWrapStartIndent" not in QsciScintilla.__dict__: 1706 if "setWrapStartIndent" not in QsciScintilla.__dict__:
1707
1656 def setWrapStartIndent(self, indent): 1708 def setWrapStartIndent(self, indent):
1657 """ 1709 """
1658 Public method to set a the amount of characters wrapped sublines 1710 Public method to set a the amount of characters wrapped sublines
1659 shall be indented. 1711 shall be indented.
1660 1712
1661 @param indent amount of characters to indent 1713 @param indent amount of characters to indent
1662 @type int 1714 @type int
1663 """ 1715 """
1664 self.SendScintilla(QsciScintilla.SCI_SETWRAPSTARTINDENT, indent) 1716 self.SendScintilla(QsciScintilla.SCI_SETWRAPSTARTINDENT, indent)
1665 1717
1666 if "getGlobalCursorPosition" not in QsciScintilla.__dict__: 1718 if "getGlobalCursorPosition" not in QsciScintilla.__dict__:
1719
1667 def getGlobalCursorPosition(self): 1720 def getGlobalCursorPosition(self):
1668 """ 1721 """
1669 Public method to determine the point of the cursor. 1722 Public method to determine the point of the cursor.
1670 1723
1671 @return point of the cursor 1724 @return point of the cursor
1672 @rtype QPoint 1725 @rtype QPoint
1673 """ 1726 """
1674 pos = self.currentPosition() 1727 pos = self.currentPosition()
1675 x = self.SendScintilla(QsciScintilla.SCI_POINTXFROMPOSITION, 1728 x = self.SendScintilla(QsciScintilla.SCI_POINTXFROMPOSITION, 0, pos)
1676 0, pos) 1729 y = self.SendScintilla(QsciScintilla.SCI_POINTYFROMPOSITION, 0, pos)
1677 y = self.SendScintilla(QsciScintilla.SCI_POINTYFROMPOSITION,
1678 0, pos)
1679 return QPoint(x, y) 1730 return QPoint(x, y)
1680 1731
1681 if "cancelCallTips" not in QsciScintilla.__dict__: 1732 if "cancelCallTips" not in QsciScintilla.__dict__:
1733
1682 def cancelCallTips(self): 1734 def cancelCallTips(self):
1683 """ 1735 """
1684 Public method to cancel displayed call tips. 1736 Public method to cancel displayed call tips.
1685 """ 1737 """
1686 self.SendScintilla(QsciScintilla.SCI_CALLTIPCANCEL) 1738 self.SendScintilla(QsciScintilla.SCI_CALLTIPCANCEL)
1687 1739
1688 if "lineIndexFromPoint" not in QsciScintilla.__dict__: 1740 if "lineIndexFromPoint" not in QsciScintilla.__dict__:
1741
1689 def lineIndexFromPoint(self, point): 1742 def lineIndexFromPoint(self, point):
1690 """ 1743 """
1691 Public method to convert a point to line and index. 1744 Public method to convert a point to line and index.
1692 1745
1693 @param point point to be converted 1746 @param point point to be converted
1694 @type QPoin 1747 @type QPoin
1695 @return tuple containing the line number and index number 1748 @return tuple containing the line number and index number
1696 @rtype tuple of (int, int) 1749 @rtype tuple of (int, int)
1697 """ 1750 """
1698 pos = self.positionFromPoint(point) 1751 pos = self.positionFromPoint(point)
1699 return self.lineIndexFromPosition(pos) 1752 return self.lineIndexFromPosition(pos)
1700 1753
1754
1701 ## ######################################################################### 1755 ## #########################################################################
1702 ## ## Methods below have been added to QScintilla starting with version 2.x. 1756 ## ## Methods below have been added to QScintilla starting with version 2.x.
1703 ## ######################################################################### 1757 ## #########################################################################
1704 ## 1758 ##
1705 ## if "newMethod" not in QsciScintilla.__dict__: 1759 ## if "newMethod" not in QsciScintilla.__dict__:

eric ide

mercurial