src/eric7/QScintilla/TypingCompleters/CompleterPython.py

branch
eric7
changeset 10431
64157aeb0312
parent 10201
5beaa25bdfbe
child 10439
21c28b0f9e41
equal deleted inserted replaced
10430:e440aaf179ce 10431:64157aeb0312
24 24
25 def __init__(self, editor, parent=None): 25 def __init__(self, editor, parent=None):
26 """ 26 """
27 Constructor 27 Constructor
28 28
29 @param editor reference to the editor object (QScintilla.Editor) 29 @param editor reference to the editor object
30 @param parent reference to the parent object (QObject) 30 @type QScintilla.Editor
31 @param parent reference to the parent object
32 @type QObject
31 """ 33 """
32 super().__init__(editor, parent) 34 super().__init__(editor, parent)
33 35
34 self.__defRX = re.compile(r"^[ \t]*(async[ \t]+)?(def|cdef|cpdef) \w+\(") 36 self.__defRX = re.compile(r"^[ \t]*(async[ \t]+)?(def|cdef|cpdef) \w+\(")
35 self.__defSelfRX = re.compile( 37 self.__defSelfRX = re.compile(
83 85
84 def charAdded(self, charNumber): 86 def charAdded(self, charNumber):
85 """ 87 """
86 Public slot called to handle the user entering a character. 88 Public slot called to handle the user entering a character.
87 89
88 @param charNumber value of the character entered (integer) 90 @param charNumber value of the character entered
91 @type int
89 """ 92 """
90 char = chr(charNumber) 93 char = chr(charNumber)
91 if char not in ["(", ")", "{", "}", "[", "]", " ", ",", "'", '"', "\n", ":"]: 94 if char not in ["(", ")", "{", "}", "[", "]", " ", ",", "'", '"', "\n", ":"]:
92 return # take the short route 95 return # take the short route
93 96
375 378
376 def __isClassMethod(self): 379 def __isClassMethod(self):
377 """ 380 """
378 Private method to check, if the user is defining a class method. 381 Private method to check, if the user is defining a class method.
379 382
380 @return flag indicating the definition of a class method (boolean) 383 @return flag indicating the definition of a class method
384 @rtype bool
381 """ 385 """
382 line, col = self.editor.getCursorPosition() 386 line, col = self.editor.getCursorPosition()
383 indentation = self.editor.indentation(line) 387 indentation = self.editor.indentation(line)
384 curLine = line - 1 388 curLine = line - 1
385 inMultiLineString = False 389 inMultiLineString = False
410 def __isClassMethodDef(self): 414 def __isClassMethodDef(self):
411 """ 415 """
412 Private method to check, if the user is defing a class method 416 Private method to check, if the user is defing a class method
413 (@classmethod). 417 (@classmethod).
414 418
415 @return flag indicating the definition of a class method (boolean) 419 @return flag indicating the definition of a class method
420 @rtype bool
416 """ 421 """
417 line, col = self.editor.getCursorPosition() 422 line, col = self.editor.getCursorPosition()
418 indentation = self.editor.indentation(line) 423 indentation = self.editor.indentation(line)
419 curLine = line - 1 424 curLine = line - 1
420 if ( 425 if (
427 def __isStaticMethodDef(self): 432 def __isStaticMethodDef(self):
428 """ 433 """
429 Private method to check, if the user is defing a static method 434 Private method to check, if the user is defing a static method
430 (@staticmethod) method. 435 (@staticmethod) method.
431 436
432 @return flag indicating the definition of a static method (boolean) 437 @return flag indicating the definition of a static method
438 @rtype bool
433 """ 439 """
434 line, col = self.editor.getCursorPosition() 440 line, col = self.editor.getCursorPosition()
435 indentation = self.editor.indentation(line) 441 indentation = self.editor.indentation(line)
436 curLine = line - 1 442 curLine = line - 1
437 if ( 443 if (
443 449
444 def __inComment(self, line, col): 450 def __inComment(self, line, col):
445 """ 451 """
446 Private method to check, if the cursor is inside a comment. 452 Private method to check, if the cursor is inside a comment.
447 453
448 @param line current line (integer) 454 @param line current line
449 @param col current position within line (integer) 455 @type int
450 @return flag indicating, if the cursor is inside a comment (boolean) 456 @param col current position within line
457 @type int
458 @return flag indicating, if the cursor is inside a comment
459 @rtype bool
451 """ 460 """
452 txt = self.editor.text(line) 461 txt = self.editor.text(line)
453 if col == len(txt): 462 if col == len(txt):
454 col -= 1 463 col -= 1
455 while col >= 0: 464 while col >= 0:
462 """ 471 """
463 Private method to check, if the cursor is within a double quoted 472 Private method to check, if the cursor is within a double quoted
464 string. 473 string.
465 474
466 @return flag indicating, if the cursor is inside a double 475 @return flag indicating, if the cursor is inside a double
467 quoted string (boolean) 476 quoted string
477 @rtype bool
468 """ 478 """
469 return self.editor.currentStyle() == QsciLexerPython.DoubleQuotedString 479 return self.editor.currentStyle() == QsciLexerPython.DoubleQuotedString
470 480
471 def __inTripleDoubleQuotedString(self): 481 def __inTripleDoubleQuotedString(self):
472 """ 482 """
473 Private method to check, if the cursor is within a triple double 483 Private method to check, if the cursor is within a triple double
474 quoted string. 484 quoted string.
475 485
476 @return flag indicating, if the cursor is inside a triple double 486 @return flag indicating, if the cursor is inside a triple double
477 quoted string (boolean) 487 quoted string
488 @rtype bool
478 """ 489 """
479 return self.editor.currentStyle() == QsciLexerPython.TripleDoubleQuotedString 490 return self.editor.currentStyle() == QsciLexerPython.TripleDoubleQuotedString
480 491
481 def __inSingleQuotedString(self): 492 def __inSingleQuotedString(self):
482 """ 493 """
483 Private method to check, if the cursor is within a single quoted 494 Private method to check, if the cursor is within a single quoted
484 string. 495 string.
485 496
486 @return flag indicating, if the cursor is inside a single 497 @return flag indicating, if the cursor is inside a single
487 quoted string (boolean) 498 quoted string
499 @rtype bool
488 """ 500 """
489 return self.editor.currentStyle() == QsciLexerPython.SingleQuotedString 501 return self.editor.currentStyle() == QsciLexerPython.SingleQuotedString
490 502
491 def __inTripleSingleQuotedString(self): 503 def __inTripleSingleQuotedString(self):
492 """ 504 """
493 Private method to check, if the cursor is within a triple single 505 Private method to check, if the cursor is within a triple single
494 quoted string. 506 quoted string.
495 507
496 @return flag indicating, if the cursor is inside a triple single 508 @return flag indicating, if the cursor is inside a triple single
497 quoted string (boolean) 509 quoted string
510 @rtype bool
498 """ 511 """
499 return self.editor.currentStyle() == QsciLexerPython.TripleSingleQuotedString 512 return self.editor.currentStyle() == QsciLexerPython.TripleSingleQuotedString
500 513
501 514
502 def createCompleter(editor, parent=None): 515 def createCompleter(editor, parent=None):

eric ide

mercurial