33 self.__defSelfRX = QRegExp(r"""^[ \t]*def \w+\([ \t]*self[ \t]*[,)]""") |
33 self.__defSelfRX = QRegExp(r"""^[ \t]*def \w+\([ \t]*self[ \t]*[,)]""") |
34 self.__defClsRX = QRegExp(r"""^[ \t]*def \w+\([ \t]*cls[ \t]*[,)]""") |
34 self.__defClsRX = QRegExp(r"""^[ \t]*def \w+\([ \t]*cls[ \t]*[,)]""") |
35 self.__classRX = QRegExp(r"""^[ \t]*class \w+\(""") |
35 self.__classRX = QRegExp(r"""^[ \t]*class \w+\(""") |
36 self.__importRX = QRegExp(r"""^[ \t]*from [\w.]+ """) |
36 self.__importRX = QRegExp(r"""^[ \t]*from [\w.]+ """) |
37 self.__classmethodRX = QRegExp(r"""^[ \t]*@classmethod""") |
37 self.__classmethodRX = QRegExp(r"""^[ \t]*@classmethod""") |
|
38 self.__staticmethodRX = QRegExp(r"""^[ \t]*@staticmethod""") |
38 |
39 |
39 self.__defOnlyRX = QRegExp(r"""^[ \t]*def """) |
40 self.__defOnlyRX = QRegExp(r"""^[ \t]*def """) |
40 |
41 |
41 self.__ifRX = QRegExp(r"""^[ \t]*if """) |
42 self.__ifRX = QRegExp(r"""^[ \t]*if """) |
42 self.__elifRX = QRegExp(r"""^[ \t]*elif """) |
43 self.__elifRX = QRegExp(r"""^[ \t]*elif """) |
105 # insert closing parenthesis and self |
106 # insert closing parenthesis and self |
106 if char == '(': |
107 if char == '(': |
107 txt = self.editor.text(line)[:col] |
108 txt = self.editor.text(line)[:col] |
108 if self.__insertSelf and \ |
109 if self.__insertSelf and \ |
109 self.__defRX.exactMatch(txt): |
110 self.__defRX.exactMatch(txt): |
110 if self.__isClassmethodDef(): |
111 if self.__isClassMethodDef(): |
111 self.editor.insert('cls') |
112 self.editor.insert('cls') |
112 self.editor.setCursorPosition(line, col + 3) |
113 self.editor.setCursorPosition(line, col + 3) |
|
114 elif self.__isStaticMethodDef(): |
|
115 # nothing to insert |
|
116 pass |
113 elif self.__isClassMethod(): |
117 elif self.__isClassMethod(): |
114 self.editor.insert('self') |
118 self.editor.insert('self') |
115 self.editor.setCursorPosition(line, col + 4) |
119 self.editor.setCursorPosition(line, col + 4) |
116 if self.__insertClosingBrace: |
120 if self.__insertClosingBrace: |
117 if self.__defRX.exactMatch(txt) or \ |
121 if self.__defRX.exactMatch(txt) or \ |
362 self.editor.indentation(curLine) <= indentation: |
366 self.editor.indentation(curLine) <= indentation: |
363 return False |
367 return False |
364 curLine -= 1 |
368 curLine -= 1 |
365 return False |
369 return False |
366 |
370 |
367 def __isClassmethodDef(self): |
371 def __isClassMethodDef(self): |
368 """ |
372 """ |
369 Private method to check, if the user is defing a classmethod |
373 Private method to check, if the user is defing a class method |
370 (@classmethod) method. |
374 (@classmethod). |
371 |
375 |
372 @return flag indicating the definition of a classmethod method (boolean) |
376 @return flag indicating the definition of a class method (boolean) |
373 """ |
377 """ |
374 line, col = self.editor.getCursorPosition() |
378 line, col = self.editor.getCursorPosition() |
375 indentation = self.editor.indentation(line) |
379 indentation = self.editor.indentation(line) |
376 curLine = line - 1 |
380 curLine = line - 1 |
377 if self.__classmethodRX.indexIn(self.editor.text(curLine)) == 0 and \ |
381 if self.__classmethodRX.indexIn(self.editor.text(curLine)) == 0 and \ |
|
382 self.editor.indentation(curLine) == indentation: |
|
383 return True |
|
384 return False |
|
385 |
|
386 def __isStaticMethodDef(self): |
|
387 """ |
|
388 Private method to check, if the user is defing a static method |
|
389 (@staticmethod) method. |
|
390 |
|
391 @return flag indicating the definition of a static method (boolean) |
|
392 """ |
|
393 line, col = self.editor.getCursorPosition() |
|
394 indentation = self.editor.indentation(line) |
|
395 curLine = line - 1 |
|
396 if self.__staticmethodRX.indexIn(self.editor.text(curLine)) == 0 and \ |
378 self.editor.indentation(curLine) == indentation: |
397 self.editor.indentation(curLine) == indentation: |
379 return True |
398 return True |
380 return False |
399 return False |
381 |
400 |
382 def __inComment(self, line, col): |
401 def __inComment(self, line, col): |