58 |
58 |
59 def readSettings(self): |
59 def readSettings(self): |
60 """ |
60 """ |
61 Public slot called to reread the configuration parameters. |
61 Public slot called to reread the configuration parameters. |
62 """ |
62 """ |
63 self.setEnabled(Preferences.getEditorTyping("Python/EnabledTypingAids")) |
63 self.setEnabled( |
|
64 Preferences.getEditorTyping("Python/EnabledTypingAids")) |
64 self.__insertClosingBrace = \ |
65 self.__insertClosingBrace = \ |
65 Preferences.getEditorTyping("Python/InsertClosingBrace") |
66 Preferences.getEditorTyping("Python/InsertClosingBrace") |
66 self.__indentBrace = \ |
67 self.__indentBrace = \ |
67 Preferences.getEditorTyping("Python/IndentBrace") |
68 Preferences.getEditorTyping("Python/IndentBrace") |
68 self.__skipBrace = \ |
69 self.__skipBrace = \ |
91 Public slot called to handle the user entering a character. |
92 Public slot called to handle the user entering a character. |
92 |
93 |
93 @param charNumber value of the character entered (integer) |
94 @param charNumber value of the character entered (integer) |
94 """ |
95 """ |
95 char = chr(charNumber) |
96 char = chr(charNumber) |
96 if char not in ['(', ')', '{', '}', '[', ']', ' ', ',', "'", '"', '\n', ':']: |
97 if char not in ['(', ')', '{', '}', '[', ']', ' ', ',', "'", '"', |
|
98 '\n', ':']: |
97 return # take the short route |
99 return # take the short route |
98 |
100 |
99 line, col = self.editor.getCursorPosition() |
101 line, col = self.editor.getCursorPosition() |
100 |
102 |
101 if self.__inComment(line, col) or \ |
103 if self.__inComment(line, col) or \ |
135 if self.__skipBrace: |
137 if self.__skipBrace: |
136 self.editor.setSelection(line, col, line, col + 1) |
138 self.editor.setSelection(line, col, line, col + 1) |
137 self.editor.removeSelectedText() |
139 self.editor.removeSelectedText() |
138 |
140 |
139 # space |
141 # space |
140 # insert import, dedent to if for elif, dedent to try for except, dedent def |
142 # insert import, dedent to if for elif, dedent to try for except, |
|
143 # dedent def |
141 elif char == ' ': |
144 elif char == ' ': |
142 txt = self.editor.text(line)[:col] |
145 txt = self.editor.text(line)[:col] |
143 if self.__insertImport and self.__importRX.exactMatch(txt): |
146 if self.__insertImport and self.__importRX.exactMatch(txt): |
144 self.editor.insert('import ') |
147 self.editor.insert('import ') |
145 self.editor.setCursorPosition(line, col + 7) |
148 self.editor.setCursorPosition(line, col + 7) |
217 openCount = len(re.findall("[({[]", txt2)) |
220 openCount = len(re.findall("[({[]", txt2)) |
218 closeCount = len(re.findall("[)}\]]", txt2)) |
221 closeCount = len(re.findall("[)}\]]", txt2)) |
219 index -= 1 |
222 index -= 1 |
220 if openCount > closeCount and lastOpenIndex > col: |
223 if openCount > closeCount and lastOpenIndex > col: |
221 self.editor.insert(' ' * (lastOpenIndex - col + 1)) |
224 self.editor.insert(' ' * (lastOpenIndex - col + 1)) |
222 self.editor.setCursorPosition(line, lastOpenIndex + 1) |
225 self.editor.setCursorPosition( |
|
226 line, lastOpenIndex + 1) |
223 |
227 |
224 def __dedentToIf(self): |
228 def __dedentToIf(self): |
225 """ |
229 """ |
226 Private method to dedent the last line to the last if statement with |
230 Private method to dedent the last line to the last if statement with |
227 less (or equal) indentation. |
231 less (or equal) indentation. |
305 txt = self.editor.text(tryLine) |
309 txt = self.editor.text(tryLine) |
306 edInd = self.editor.indentation(tryLine) |
310 edInd = self.editor.indentation(tryLine) |
307 if self.__py24StyleTry: |
311 if self.__py24StyleTry: |
308 if (self.__exceptcRX.indexIn(txt) == 0 or \ |
312 if (self.__exceptcRX.indexIn(txt) == 0 or \ |
309 self.__exceptRX.indexIn(txt) == 0 or \ |
313 self.__exceptRX.indexIn(txt) == 0 or \ |
310 self.__finallyRX.indexIn(txt) == 0) and edInd <= indentation: |
314 self.__finallyRX.indexIn(txt) == 0) and \ |
|
315 edInd <= indentation: |
311 indentation = edInd - 1 |
316 indentation = edInd - 1 |
312 elif self.__tryRX.indexIn(txt) == 0 and edInd <= indentation: |
317 elif self.__tryRX.indexIn(txt) == 0 and edInd <= indentation: |
313 self.editor.cancelList() |
318 self.editor.cancelList() |
314 self.editor.setIndentation(line, edInd) |
319 self.editor.setIndentation(line, edInd) |
315 break |
320 break |
316 else: |
321 else: |
317 if self.__finallyRX.indexIn(txt) == 0 and edInd <= indentation: |
322 if self.__finallyRX.indexIn(txt) == 0 and edInd <= indentation: |
318 indentation = edInd - 1 |
323 indentation = edInd - 1 |
319 elif (self.__tryRX.indexIn(txt) == 0 or \ |
324 elif (self.__tryRX.indexIn(txt) == 0 or \ |
320 self.__exceptcRX.indexIn(txt) == 0 or \ |
325 self.__exceptcRX.indexIn(txt) == 0 or \ |
321 self.__exceptRX.indexIn(txt) == 0) and edInd <= indentation: |
326 self.__exceptRX.indexIn(txt) == 0) and \ |
|
327 edInd <= indentation: |
322 self.editor.cancelList() |
328 self.editor.cancelList() |
323 self.editor.setIndentation(line, edInd) |
329 self.editor.setIndentation(line, edInd) |
324 break |
330 break |
325 tryLine -= 1 |
331 tryLine -= 1 |
326 |
332 |
327 def __dedentDefStatement(self): |
333 def __dedentDefStatement(self): |
328 """ |
334 """ |
329 Private method to dedent the line of the def statement to a previous def |
335 Private method to dedent the line of the def statement to a previous |
330 statement or class statement. |
336 def statement or class statement. |
331 """ |
337 """ |
332 line, col = self.editor.getCursorPosition() |
338 line, col = self.editor.getCursorPosition() |
333 indentation = self.editor.indentation(line) |
339 indentation = self.editor.indentation(line) |
334 tryLine = line - 1 |
340 tryLine = line - 1 |
335 while tryLine >= 0: |
341 while tryLine >= 0: |
401 return True |
407 return True |
402 return False |
408 return False |
403 |
409 |
404 def __inComment(self, line, col): |
410 def __inComment(self, line, col): |
405 """ |
411 """ |
406 Private method to check, if the cursor is inside a comment |
412 Private method to check, if the cursor is inside a comment. |
407 |
413 |
408 @param line current line (integer) |
414 @param line current line (integer) |
409 @param col current position within line (integer) |
415 @param col current position within line (integer) |
410 @return flag indicating, if the cursor is inside a comment (boolean) |
416 @return flag indicating, if the cursor is inside a comment (boolean) |
411 """ |
417 """ |
418 col -= 1 |
424 col -= 1 |
419 return False |
425 return False |
420 |
426 |
421 def __inDoubleQuotedString(self): |
427 def __inDoubleQuotedString(self): |
422 """ |
428 """ |
423 Private method to check, if the cursor is within a double quoted string. |
429 Private method to check, if the cursor is within a double quoted |
|
430 string. |
424 |
431 |
425 @return flag indicating, if the cursor is inside a double |
432 @return flag indicating, if the cursor is inside a double |
426 quoted string (boolean) |
433 quoted string (boolean) |
427 """ |
434 """ |
428 return self.editor.currentStyle() == QsciLexerPython.DoubleQuotedString |
435 return self.editor.currentStyle() == QsciLexerPython.DoubleQuotedString |
429 |
436 |
430 def __inTripleDoubleQuotedString(self): |
437 def __inTripleDoubleQuotedString(self): |
431 """ |
438 """ |
432 Private method to check, if the cursor is within a triple double quoted string. |
439 Private method to check, if the cursor is within a triple double |
|
440 quoted string. |
433 |
441 |
434 @return flag indicating, if the cursor is inside a triple double |
442 @return flag indicating, if the cursor is inside a triple double |
435 quoted string (boolean) |
443 quoted string (boolean) |
436 """ |
444 """ |
437 return self.editor.currentStyle() == QsciLexerPython.TripleDoubleQuotedString |
445 return self.editor.currentStyle() == \ |
|
446 QsciLexerPython.TripleDoubleQuotedString |
438 |
447 |
439 def __inSingleQuotedString(self): |
448 def __inSingleQuotedString(self): |
440 """ |
449 """ |
441 Private method to check, if the cursor is within a single quoted string. |
450 Private method to check, if the cursor is within a single quoted |
|
451 string. |
442 |
452 |
443 @return flag indicating, if the cursor is inside a single |
453 @return flag indicating, if the cursor is inside a single |
444 quoted string (boolean) |
454 quoted string (boolean) |
445 """ |
455 """ |
446 return self.editor.currentStyle() == QsciLexerPython.SingleQuotedString |
456 return self.editor.currentStyle() == QsciLexerPython.SingleQuotedString |
447 |
457 |
448 def __inTripleSingleQuotedString(self): |
458 def __inTripleSingleQuotedString(self): |
449 """ |
459 """ |
450 Private method to check, if the cursor is within a triple single quoted string. |
460 Private method to check, if the cursor is within a triple single |
|
461 quoted string. |
451 |
462 |
452 @return flag indicating, if the cursor is inside a triple single |
463 @return flag indicating, if the cursor is inside a triple single |
453 quoted string (boolean) |
464 quoted string (boolean) |
454 """ |
465 """ |
455 return self.editor.currentStyle() == QsciLexerPython.TripleSingleQuotedString |
466 return self.editor.currentStyle() == \ |
|
467 QsciLexerPython.TripleSingleQuotedString |