本文整理汇总了Python中pyqode.core.api.TextHelper.line_text方法的典型用法代码示例。如果您正苦于以下问题:Python TextHelper.line_text方法的具体用法?Python TextHelper.line_text怎么用?Python TextHelper.line_text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyqode.core.api.TextHelper
的用法示例。
在下文中一共展示了TextHelper.line_text方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _in_method_call
# 需要导入模块: from pyqode.core.api import TextHelper [as 别名]
# 或者: from pyqode.core.api.TextHelper import line_text [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
示例2: _on_post_key_pressed
# 需要导入模块: from pyqode.core.api import TextHelper [as 别名]
# 或者: from pyqode.core.api.TextHelper import line_text [as 别名]
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)
示例3: PyAutoIndentMode
# 需要导入模块: from pyqode.core.api import TextHelper [as 别名]
# 或者: from pyqode.core.api.TextHelper import line_text [as 别名]
#.........这里部分代码省略.........
col = len(block.text())
return nb_open > nb_closed
@staticmethod
def _get_last_word(tc):
tc2 = QTextCursor(tc)
tc2.movePosition(QTextCursor.Left, tc.KeepAnchor, 1)
tc2.movePosition(QTextCursor.WordLeft, tc.KeepAnchor)
return tc2.selectedText().strip()
@staticmethod
def _get_last_word_unstripped(tc):
tc2 = QTextCursor(tc)
tc2.movePosition(QTextCursor.Left, tc.KeepAnchor, 1)
tc2.movePosition(QTextCursor.WordLeft, tc.KeepAnchor)
return tc2.selectedText()
def _get_indent_of_opening_paren(self, tc):
tc.movePosition(tc.Left, tc.KeepAnchor)
char = tc.selectedText()
tc.movePosition(tc.Right, tc.MoveAnchor)
mapping = {
')': (OPEN, PAREN),
']': (OPEN, SQUARE),
'}': (OPEN, BRACE)
}
try:
character, char_type = mapping[char]
except KeyError:
return None
else:
ol, oc = self.editor.modes.get(SymbolMatcherMode).symbol_pos(
tc, character, char_type)
line = self._helper.line_text(ol)
return len(line) - len(line.lstrip())
def _get_first_open_paren(self, tc, column):
pos = None
char = None
ln = tc.blockNumber()
tc_trav = QTextCursor(tc)
mapping = {
'(': (CLOSE, PAREN),
'[': (CLOSE, SQUARE),
'{': (CLOSE, BRACE)
}
while ln >= 0 and tc.block().text().strip():
tc_trav.movePosition(tc_trav.StartOfLine, tc_trav.MoveAnchor)
lists = get_block_symbol_data(self.editor, tc_trav.block())
all_symbols = []
for symbols in lists:
all_symbols += [s for s in symbols]
symbols = sorted(all_symbols, key=lambda x: x.position)
for paren in reversed(symbols):
if paren.position < column:
if self._is_paren_open(paren):
if paren.position > column:
continue
else:
pos = tc_trav.position() + paren.position
char = paren.character
# ensure it does not have a closing paren on
# the same line
tc3 = QTextCursor(tc)
tc3.setPosition(pos)
try:
示例4: PyAutoIndentMode
# 需要导入模块: from pyqode.core.api import TextHelper [as 别名]
# 或者: from pyqode.core.api.TextHelper import line_text [as 别名]
class PyAutoIndentMode(AutoIndentMode):
"""
Customised :class:`pyqode.core.modes.AutoIndentMode` for python
that tries its best to follow the pep8 indentation guidelines.
"""
def __init__(self):
super(PyAutoIndentMode, self).__init__()
def on_install(self, editor):
super().on_install(editor)
self._helper = TextHelper(editor)
def has_two_empty_line_before(self, tc):
ln = tc.blockNumber()
limit = ln - 1
while ln > limit:
if self._helper.line_text(ln).strip() != "":
return False
ln -= 1
return True
def has_unclosed_paren(self, tc):
ln = tc.blockNumber()
while ln >= 0:
line = self._helper.line_text(ln)
if line.count("(") > line.count(")"):
return True
ln -= 1
return False
def is_in_string_def(self, full_line, column):
count = 0
char = "'"
for i in range(len(full_line)):
if full_line[i] == "'" or full_line[i] == '"':
count += 1
if full_line[i] == '"' and i < column:
char = '"'
count_after_col = 0
for i in range(column, len(full_line)):
if full_line[i] == "'" or full_line[i] == '"':
count_after_col += 1
return count % 2 == 0 and count_after_col % 2 == 1, char
def is_paren_open(self, paren):
return (paren.character == "(" or paren.character == "["
or paren.character == '{')
def is_paren_closed(self, paren):
return (paren.character == ")" or paren.character == "]"
or paren.character == '}')
def get_full_line(self, tc):
tc2 = QTextCursor(tc)
tc2.select(QTextCursor.LineUnderCursor)
full_line = tc2.selectedText()
return full_line
def parens_count_for_block(self, col, block):
data = block.userData()
nb_open = 0
nb_closed = 0
lists = [data.parentheses, data.braces, data.square_brackets]
for symbols in lists:
for paren in symbols:
if self.is_paren_open(paren):
if not col:
return -1, -1
nb_open += 1
if paren.position >= col and self.is_paren_closed(paren):
nb_closed += 1
return nb_closed, nb_open
def between_paren(self, tc, col):
nb_closed, nb_open = self.parens_count_for_block(col, tc.block())
block = tc.block().next()
while nb_open == nb_closed == 0 and block.isValid():
nb_closed, nb_open = self.parens_count_for_block(nb_open, block)
block = block.next()
# if not, is there an non closed paren on the next lines.
parens = {'(': 0, '{': 0, '[': 0}
matching = {')': '(', '}': '{', ']': '['}
rparens = {')': 0, '}': 0, ']': 0}
rmatching = {'(': ')', '{': '}', '[': ']'}
if nb_open != nb_closed:
# look down
if nb_open > nb_closed:
operation = self._next_block
down = True
else:
operation = self._prev_block
down = False
block = tc.block()
# block = operation(tc.block())
offset = col
while block.isValid():
data = block.userData()
lists = [data.parentheses, data.braces, data.square_brackets]
for symbols in lists:
for paren in symbols:
#.........这里部分代码省略.........