def _in_method_call(self): helper = TextHelper(self.editor) line_nbr = helper.current_line_nbr() - 1 expected_indent = helper.line_indent() - 4 while line_nbr >= 0: text = helper.line_text(line_nbr) indent = len(text) - len(text.lstrip()) if indent == expected_indent and 'class' in text: return True line_nbr -= 1 return False
def _in_method_call(self): helper = TextHelper(self.editor) line_nbr = helper.current_line_nbr() - 1 expected_indent = helper.line_indent() - 4 while line_nbr >= 0: text = helper.line_text(line_nbr) indent = len(text) - len(text.lstrip()) if indent == expected_indent and 'class' in text: return True line_nbr -= 1 return False
def _on_item_clicked(self, item): """ Go to the item position in the editor. """ if item: name = item.data(0, QtCore.Qt.UserRole) if name: go = name.block.blockNumber() helper = TextHelper(self._editor) if helper.current_line_nbr() != go: helper.goto_line(go, column=name.column) self._editor.setFocus()
def _on_item_clicked(self, item): """ Go to the item position in the editor. """ if item: name = item.data(0, QtCore.Qt.UserRole) if name: go = name.block.blockNumber() helper = TextHelper(self._editor) if helper.current_line_nbr() != go: helper.goto_line(go, column=name.column) self._editor.setFocus()
def _handle_fct_def(self): if self._in_method_call(): th = TextHelper(self.editor) if '@classmethod' in th.line_text(th.current_line_nbr() - 1): txt = "cls):" else: txt = "self):" else: txt = "):" cursor = self.editor.textCursor() cursor.insertText(txt) cursor.movePosition(cursor.Left, cursor.MoveAnchor, 2) self.editor.setTextCursor(cursor)
def _on_post_key_pressed(self, event): # if we are in disabled cc, use the parent implementation helper = TextHelper(self.editor) column = helper.current_column_nbr() usd = self.editor.textCursor().block().userData() if usd: for start, end in usd.cc_disabled_zones: if (start <= column < end - 1 and not helper.current_line_text( ).lstrip().startswith('"""')): return prev_line = helper.line_text(helper.current_line_nbr() - 1) is_below_fct_or_class = "def" in prev_line or "class" in prev_line if (event.text() == '"' and '""' == helper.current_line_text().strip() and (is_below_fct_or_class or column == 2)): self._insert_docstring(prev_line, is_below_fct_or_class) elif (event.text() == "(" and helper.current_line_text().lstrip().startswith("def ")): self._handle_fct_def() else: super(PyAutoCompleteMode, self)._on_post_key_pressed(event)