本文整理匯總了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)