13 from PyQt4.Qsci import QsciLexerPython |
13 from PyQt4.Qsci import QsciLexerPython |
14 |
14 |
15 from .CompleterBase import CompleterBase |
15 from .CompleterBase import CompleterBase |
16 |
16 |
17 import Preferences |
17 import Preferences |
|
18 |
18 |
19 |
19 class CompleterPython(CompleterBase): |
20 class CompleterPython(CompleterBase): |
20 """ |
21 """ |
21 Class implementing typing completer for Python. |
22 Class implementing typing completer for Python. |
22 """ |
23 """ |
23 def __init__(self, editor, parent = None): |
24 def __init__(self, editor, parent=None): |
24 """ |
25 """ |
25 Constructor |
26 Constructor |
26 |
27 |
27 @param editor reference to the editor object (QScintilla.Editor) |
28 @param editor reference to the editor object (QScintilla.Editor) |
28 @param parent reference to the parent object (QObject) |
29 @param parent reference to the parent object (QObject) |
75 Preferences.getEditorTyping("Python/InsertImport") |
76 Preferences.getEditorTyping("Python/InsertImport") |
76 self.__insertSelf = \ |
77 self.__insertSelf = \ |
77 Preferences.getEditorTyping("Python/InsertSelf") |
78 Preferences.getEditorTyping("Python/InsertSelf") |
78 self.__insertBlank = \ |
79 self.__insertBlank = \ |
79 Preferences.getEditorTyping("Python/InsertBlank") |
80 Preferences.getEditorTyping("Python/InsertBlank") |
80 self.__colonDetection= \ |
81 self.__colonDetection = \ |
81 Preferences.getEditorTyping("Python/ColonDetection") |
82 Preferences.getEditorTyping("Python/ColonDetection") |
82 self.__dedentDef= \ |
83 self.__dedentDef = \ |
83 Preferences.getEditorTyping("Python/DedentDef") |
84 Preferences.getEditorTyping("Python/DedentDef") |
84 |
85 |
85 def charAdded(self, charNumber): |
86 def charAdded(self, charNumber): |
86 """ |
87 """ |
87 Public slot called to handle the user entering a character. |
88 Public slot called to handle the user entering a character. |
263 break |
264 break |
264 ifLine -= 1 |
265 ifLine -= 1 |
265 |
266 |
266 def __dedentExceptToTry(self, hasColon): |
267 def __dedentExceptToTry(self, hasColon): |
267 """ |
268 """ |
268 Private method to dedent the line of the except statement to the last |
269 Private method to dedent the line of the except statement to the last |
269 try statement with less (or equal) indentation. |
270 try statement with less (or equal) indentation. |
270 |
271 |
271 @param hasColon flag indicating the except type (boolean) |
272 @param hasColon flag indicating the except type (boolean) |
272 """ |
273 """ |
273 line, col = self.editor.getCursorPosition() |
274 line, col = self.editor.getCursorPosition() |
286 break |
287 break |
287 tryLine -= 1 |
288 tryLine -= 1 |
288 |
289 |
289 def __dedentFinallyToTry(self): |
290 def __dedentFinallyToTry(self): |
290 """ |
291 """ |
291 Private method to dedent the line of the except statement to the last |
292 Private method to dedent the line of the except statement to the last |
292 try statement with less (or equal) indentation. |
293 try statement with less (or equal) indentation. |
293 """ |
294 """ |
294 line, col = self.editor.getCursorPosition() |
295 line, col = self.editor.getCursorPosition() |
295 indentation = self.editor.indentation(line) |
296 indentation = self.editor.indentation(line) |
296 tryLine = line - 1 |
297 tryLine = line - 1 |
364 curLine -= 1 |
365 curLine -= 1 |
365 return False |
366 return False |
366 |
367 |
367 def __isClassmethodDef(self): |
368 def __isClassmethodDef(self): |
368 """ |
369 """ |
369 Private method to check, if the user is defing a classmethod |
370 Private method to check, if the user is defing a classmethod |
370 (@classmethod) method. |
371 (@classmethod) method. |
371 |
372 |
372 @return flag indicating the definition of a classmethod method (boolean) |
373 @return flag indicating the definition of a classmethod method (boolean) |
373 """ |
374 """ |
374 line, col = self.editor.getCursorPosition() |
375 line, col = self.editor.getCursorPosition() |
398 |
399 |
399 def __inDoubleQuotedString(self): |
400 def __inDoubleQuotedString(self): |
400 """ |
401 """ |
401 Private method to check, if the cursor is within a double quoted string. |
402 Private method to check, if the cursor is within a double quoted string. |
402 |
403 |
403 @return flag indicating, if the cursor is inside a double |
404 @return flag indicating, if the cursor is inside a double |
404 quoted string (boolean) |
405 quoted string (boolean) |
405 """ |
406 """ |
406 return self.editor.currentStyle() == QsciLexerPython.DoubleQuotedString |
407 return self.editor.currentStyle() == QsciLexerPython.DoubleQuotedString |
407 |
408 |
408 def __inTripleDoubleQuotedString(self): |
409 def __inTripleDoubleQuotedString(self): |
409 """ |
410 """ |
410 Private method to check, if the cursor is within a triple double quoted string. |
411 Private method to check, if the cursor is within a triple double quoted string. |
411 |
412 |
412 @return flag indicating, if the cursor is inside a triple double |
413 @return flag indicating, if the cursor is inside a triple double |
413 quoted string (boolean) |
414 quoted string (boolean) |
414 """ |
415 """ |
415 return self.editor.currentStyle() == QsciLexerPython.TripleDoubleQuotedString |
416 return self.editor.currentStyle() == QsciLexerPython.TripleDoubleQuotedString |
416 |
417 |
417 def __inSingleQuotedString(self): |
418 def __inSingleQuotedString(self): |
418 """ |
419 """ |
419 Private method to check, if the cursor is within a single quoted string. |
420 Private method to check, if the cursor is within a single quoted string. |
420 |
421 |
421 @return flag indicating, if the cursor is inside a single |
422 @return flag indicating, if the cursor is inside a single |
422 quoted string (boolean) |
423 quoted string (boolean) |
423 """ |
424 """ |
424 return self.editor.currentStyle() == QsciLexerPython.SingleQuotedString |
425 return self.editor.currentStyle() == QsciLexerPython.SingleQuotedString |
425 |
426 |
426 def __inTripleSingleQuotedString(self): |
427 def __inTripleSingleQuotedString(self): |
427 """ |
428 """ |
428 Private method to check, if the cursor is within a triple single quoted string. |
429 Private method to check, if the cursor is within a triple single quoted string. |
429 |
430 |
430 @return flag indicating, if the cursor is inside a triple single |
431 @return flag indicating, if the cursor is inside a triple single |
431 quoted string (boolean) |
432 quoted string (boolean) |
432 """ |
433 """ |
433 return self.editor.currentStyle() == QsciLexerPython.TripleSingleQuotedString |
434 return self.editor.currentStyle() == QsciLexerPython.TripleSingleQuotedString |