本文整理汇总了Python中pyqode.core.api.TextHelper.line_indent方法的典型用法代码示例。如果您正苦于以下问题:Python TextHelper.line_indent方法的具体用法?Python TextHelper.line_indent怎么用?Python TextHelper.line_indent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyqode.core.api.TextHelper
的用法示例。
在下文中一共展示了TextHelper.line_indent方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _on_key_pressed
# 需要导入模块: from pyqode.core.api import TextHelper [as 别名]
# 或者: from pyqode.core.api.TextHelper import line_indent [as 别名]
def _on_key_pressed(self, event):
helper = TextHelper(self.editor)
indent = helper.line_indent() * ' '
if self.editor.textCursor().positionInBlock() == len(indent):
self.QUOTES_FORMATS['"'] = '%s:'
else:
self.QUOTES_FORMATS['"'] = '%s'
self.QUOTES_FORMATS['{'] = '\n' + indent + '%s'
self.QUOTES_FORMATS['['] = '\n' + indent + '%s'
super(AutoCompleteMode, self)._on_key_pressed(event)
示例2: _in_method_call
# 需要导入模块: from pyqode.core.api import TextHelper [as 别名]
# 或者: from pyqode.core.api.TextHelper import line_indent [as 别名]
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
示例3: _on_bt_toggled
# 需要导入模块: from pyqode.core.api import TextHelper [as 别名]
# 或者: from pyqode.core.api.TextHelper import line_indent [as 别名]
def _on_bt_toggled(self, *ar):
if not self._lock:
self._lock = True
for w in self._widgets:
if w == self.sender():
break
if self._toggled:
self._toggled.setChecked(False)
self._toggled = w
th = TextHelper(self.editor)
line = w.scope.blockNumber()
th.goto_line(line, column=th.line_indent(line))
self._lock = False
self.editor.setFocus()
示例4: PyAutoIndentMode
# 需要导入模块: from pyqode.core.api import TextHelper [as 别名]
# 或者: from pyqode.core.api.TextHelper import line_indent [as 别名]
#.........这里部分代码省略.........
cl, cc = self.editor.modes.get(SymbolMatcherMode).symbol_pos(
tc2, CLOSE, mapping[char])
return (ol, oc), (cl, cc)
@staticmethod
def _get_next_char(tc):
tc2 = QTextCursor(tc)
tc2.movePosition(QTextCursor.NextCharacter, QTextCursor.KeepAnchor)
char = tc2.selectedText()
return char
@staticmethod
def _get_prev_char(tc):
tc2 = QTextCursor(tc)
tc2.movePosition(QTextCursor.PreviousCharacter, QTextCursor.KeepAnchor)
char = tc2.selectedText()
while char == ' ':
tc2.movePosition(QTextCursor.PreviousCharacter, QTextCursor.KeepAnchor)
char = tc2.selectedText()
return char.strip()
def _handle_indent_between_paren(self, column, line, parent_impl, tc):
"""
Handle indent between symbols such as parenthesis, braces,...
"""
pre, post = parent_impl
next_char = self._get_next_char(tc)
prev_char = self._get_prev_char(tc)
prev_open = prev_char in ['[', '(', '{']
next_close = next_char in [']', ')', '}']
(open_line, open_symbol_col), (close_line, close_col) = \
self._get_paren_pos(tc, column)
open_line_txt = self._helper.line_text(open_line)
open_line_indent = len(open_line_txt) - len(open_line_txt.lstrip())
if prev_open:
post = (open_line_indent + self.editor.tab_length) * ' '
elif next_close and prev_char != ',':
post = open_line_indent * ' '
elif tc.block().blockNumber() == open_line:
post = open_symbol_col * ' '
# adapt indent if cursor on closing line and next line have same
# indent -> PEP8 compliance
if close_line and close_col:
txt = self._helper.line_text(close_line)
bn = tc.block().blockNumber()
flg = bn == close_line
next_indent = self._helper.line_indent(bn + 1) * ' '
if flg and txt.strip().endswith(':') and next_indent == post:
# | look at how the previous line ( ``':'):`` ) was
# over-indented, this is actually what we are trying to
# achieve here
post += self.editor.tab_length * ' '
# breaking string
if next_char in ['"', "'"]:
tc.movePosition(tc.Left)
is_string = self._helper.is_comment_or_string(tc, formats=['string'])
if next_char in ['"', "'"]:
tc.movePosition(tc.Right)
if is_string:
trav = QTextCursor(tc)
while self._helper.is_comment_or_string(
trav, formats=['string']):
trav.movePosition(trav.Left)
trav.movePosition(trav.Right)