本文整理汇总了Python中pyqode.core.api.utils.TextHelper类的典型用法代码示例。如果您正苦于以下问题:Python TextHelper类的具体用法?Python TextHelper怎么用?Python TextHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TextHelper类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: request_completion
def request_completion(self):
"""
Requests a code completion at the current cursor position.
"""
_logger().debug('request code completion')
self._col = self.editor.textCursor().positionInBlock() - len(
self.completion_prefix)
helper = TextHelper(self.editor)
if not self._request_cnt:
# only check first byte
tc = self.editor.textCursor()
while tc.atBlockEnd() and not tc.atBlockStart() and \
tc.position():
tc.movePosition(tc.Left)
disabled_zone = TextHelper(self.editor).is_comment_or_string(
tc)
if disabled_zone:
_logger().debug(
"cc: cancel request, cursor is in a disabled zone")
return False
self._request_cnt += 1
self._collect_completions(self.editor.toPlainText(),
helper.current_line_nbr(),
helper.current_column_nbr() -
len(self.completion_prefix),
self.editor.file.path,
self.editor.file.encoding,
self.completion_prefix)
return True
return False
开发者ID:AlexLee,项目名称:cadquery-freecad-module,代码行数:30,代码来源:code_completion.py
示例2: test_clear_selection
def test_clear_selection(editor):
editor.file.open(__file__)
helper = TextHelper(editor)
TextHelper(editor).select_lines(0, 2)
assert helper.selected_text() != ''
TextHelper(editor).clear_selection()
assert helper.selected_text() == ''
开发者ID:dtonal,项目名称:pyqode.core,代码行数:7,代码来源:test_text.py
示例3: test_selected_text
def test_selected_text(editor):
helper = TextHelper(editor)
helper.goto_line(2, 1, move=True)
QTest.qWait(100)
assert helper.word_under_cursor().selectedText() == 'T'
assert helper.word_under_cursor(
select_whole_word=True).selectedText() == 'This'
开发者ID:dtonal,项目名称:pyqode.core,代码行数:7,代码来源:test_text.py
示例4: goto_line
def goto_line(self):
"""
Shows the *go to line dialog* and go to the selected line.
"""
helper = TextHelper(self)
line, result = DlgGotoLine.get_line(self, helper.current_line_nbr(), helper.line_count())
if not result:
return
return helper.goto_line(line, move=True)
开发者ID:pyQode,项目名称:pyqode.core,代码行数:9,代码来源:code_edit.py
示例5: test_do_home_key
def test_do_home_key(editor):
QTest.qWait(2000)
helper = TextHelper(editor)
helper.goto_line(336, 29)
assert editor.textCursor().positionInBlock() == 29
assert TextHelper(editor).line_indent() == 4
editor._do_home_key()
assert editor.textCursor().positionInBlock() == 4
editor._do_home_key()
assert editor.textCursor().positionInBlock() == 0
开发者ID:SirmoGames,项目名称:pyqode.core,代码行数:10,代码来源:test_code_edit.py
示例6: _on_key_pressed
def _on_key_pressed(self, event):
"""
Override key press to select the current scope if the user wants
to deleted a folded scope (without selecting it).
"""
delete_request = event.key() in [QtCore.Qt.Key_Backspace,
QtCore.Qt.Key_Delete]
if event.text() or delete_request:
cursor = self.editor.textCursor()
if cursor.hasSelection():
# change selection to encompass the whole scope.
positions_to_check = cursor.selectionStart(), cursor.selectionEnd()
else:
positions_to_check = (cursor.position(), )
for pos in positions_to_check:
block = self.editor.document().findBlock(pos)
th = TextBlockHelper()
if th.is_fold_trigger(block) and th.is_collapsed(block):
self.toggle_fold_trigger(block)
if delete_request and cursor.hasSelection():
scope = FoldScope(self.find_parent_scope(block))
tc = TextHelper(self.editor).select_lines(*scope.get_range())
if tc.selectionStart() > cursor.selectionStart():
start = cursor.selectionStart()
else:
start = tc.selectionStart()
if tc.selectionEnd() < cursor.selectionEnd():
end = cursor.selectionEnd()
else:
end = tc.selectionEnd()
tc.setPosition(start)
tc.setPosition(end, tc.KeepAnchor)
self.editor.setTextCursor(tc)
开发者ID:must40,项目名称:pyqode.core,代码行数:33,代码来源:folding.py
示例7: test_cut_no_selection
def test_cut_no_selection(editor):
assert isinstance(editor, CodeEdit)
editor.setPlainText('''Line 1
Line 2
Line 3''', '', '')
helper = TextHelper(editor)
# eat empty line
helper.goto_line(0)
assert helper.line_count() == 3
editor.cut()
assert helper.line_count() == 2
开发者ID:SirmoGames,项目名称:pyqode.core,代码行数:12,代码来源:test_code_edit.py
示例8: cut
def cut(self):
tc = self.textCursor()
helper = TextHelper(self)
tc.beginEditBlock()
no_selection = False
if not helper.current_line_text().strip():
tc.deleteChar()
else:
if not self.textCursor().hasSelection():
no_selection = True
TextHelper(self).select_whole_line()
super(CodeEdit, self).cut()
if no_selection:
tc.deleteChar()
tc.endEditBlock()
self.setTextCursor(tc)
开发者ID:abdullahtahiriyo,项目名称:cadquery-freecad-module,代码行数:16,代码来源:code_edit.py
示例9: on_install
def on_install(self, editor):
self._completer = QtWidgets.QCompleter([""], editor)
self._completer.setCompletionMode(self._completer.PopupCompletion)
self._completer.activated.connect(self._insert_completion)
self._completer.highlighted.connect(
self._on_selected_completion_changed)
self._completer.setModel(QtGui.QStandardItemModel())
self._helper = TextHelper(editor)
Mode.on_install(self, editor)
开发者ID:AlexLee,项目名称:cadquery-freecad-module,代码行数:9,代码来源:code_completion.py
示例10: cut
def cut(self):
"""
Cuts the selected text or the whole line if no text was selected.
"""
tc = self.textCursor()
helper = TextHelper(self)
tc.beginEditBlock()
no_selection = False
sText = tc.selection().toPlainText()
if not helper.current_line_text() and sText.count("\n") > 1:
tc.deleteChar()
else:
if not self.textCursor().hasSelection():
no_selection = True
TextHelper(self).select_whole_line()
super(CodeEdit, self).cut()
if no_selection:
tc.deleteChar()
tc.endEditBlock()
self.setTextCursor(tc)
开发者ID:pyQode,项目名称:pyqode.core,代码行数:20,代码来源:code_edit.py
示例11: test_copy_no_selection
def test_copy_no_selection(editor):
"""
Tests the select_line_on_copy_empty option that toggles the
"whole line selection on copy with empty selection"-feature
"""
assert isinstance(editor, CodeEdit)
editor.setPlainText('''Line 1
Line 2
Line 3''', '', '')
helper = TextHelper(editor)
helper.goto_line(0)
editor.textCursor().clearSelection()
editor.select_line_on_copy_empty = False
editor.copy()
assert editor.textCursor().hasSelection() is False
editor.textCursor().clearSelection()
editor.select_line_on_copy_empty = True
editor.copy()
assert editor.textCursor().hasSelection()
开发者ID:SirmoGames,项目名称:pyqode.core,代码行数:21,代码来源:test_code_edit.py
示例12: _update
def _update(self, rect, delta_y, force_update_margins=False):
""" Updates panels """
helper = TextHelper(self.editor)
if not self:
return
for zones_id, zone in self._panels.items():
if zones_id == Panel.Position.TOP or \
zones_id == Panel.Position.BOTTOM:
continue
panels = list(zone.values())
for panel in panels:
if panel.scrollable and delta_y:
panel.scroll(0, delta_y)
line, col = helper.cursor_position()
oline, ocol = self._cached_cursor_pos
if line != oline or col != ocol or panel.scrollable:
panel.update(0, rect.y(), panel.width(), rect.height())
self._cached_cursor_pos = helper.cursor_position()
if (rect.contains(self.editor.viewport().rect()) or
force_update_margins):
self._update_viewport_margins()
开发者ID:AlexLee,项目名称:cadquery-freecad-module,代码行数:21,代码来源:panels.py
示例13: __swapLine
def __swapLine(self, up: bool):
helper = TextHelper(self)
text = helper.current_line_text()
line_nbr = helper.current_line_nbr()
if up:
swap_line_nbr = line_nbr - 1
else:
swap_line_nbr = line_nbr + 1
swap_text = helper.line_text(swap_line_nbr)
if (swap_line_nbr < helper.line_count()
and line_nbr < helper.line_count()):
helper.set_line_text(line_nbr, swap_text)
helper.set_line_text(swap_line_nbr, text)
开发者ID:pyQode,项目名称:pyqode.core,代码行数:14,代码来源:code_edit.py
示例14: _draw_fold_region_background
def _draw_fold_region_background(self, block, painter):
"""
Draw the fold region when the mouse is over and non collapsed
indicator.
:param top: Top position
:param block: Current block.
:param painter: QPainter
"""
r = folding.FoldScope(block)
th = TextHelper(self.editor)
start, end = r.get_range(ignore_blank_lines=True)
if start > 0:
top = th.line_pos_from_number(start)
else:
top = 0
bottom = th.line_pos_from_number(end + 1)
h = bottom - top
if h == 0:
h = self.sizeHint().height()
w = self.sizeHint().width()
self._draw_rect(QtCore.QRectF(0, top, w, h), painter)
开发者ID:sopak,项目名称:cadquery-freecad-module,代码行数:22,代码来源:folding.py
示例15: mouseMoveEvent
def mouseMoveEvent(self, event):
"""
Detect mouser over indicator and highlight the current scope in the
editor (up and down decoration arround the foldable text when the mouse
is over an indicator).
:param event: event
"""
super(FoldingPanel, self).mouseMoveEvent(event)
th = TextHelper(self.editor)
line = th.line_nbr_from_position(event.pos().y())
if line >= 0:
block = FoldScope.find_parent_scope(
self.editor.document().findBlockByNumber(line))
if TextBlockHelper.is_fold_trigger(block):
if self._mouse_over_line is None:
# mouse enter fold scope
QtWidgets.QApplication.setOverrideCursor(
QtGui.QCursor(QtCore.Qt.PointingHandCursor))
if self._mouse_over_line != block.blockNumber() and \
self._mouse_over_line is not None:
# fold scope changed, a previous block was highlighter so
# we quickly update our highlighting
self._mouse_over_line = block.blockNumber()
self._highlight_surrounding_scopes(block)
else:
# same fold scope, request highlight
self._mouse_over_line = block.blockNumber()
self._highlight_runner.request_job(
self._highlight_surrounding_scopes, block)
self._highight_block = block
else:
# no fold scope to highlight, cancel any pending requests
self._highlight_runner.cancel_requests()
self._mouse_over_line = None
QtWidgets.QApplication.restoreOverrideCursor()
self.repaint()
开发者ID:sopak,项目名称:cadquery-freecad-module,代码行数:37,代码来源:folding.py
示例16: test_matched_selection
def test_matched_selection(editor):
line, column, text = 297, 14, '''__file__'''
cursor = editor.textCursor()
assert not cursor.hasSelection()
helper = TextHelper(editor)
helper.goto_line(line, column)
assert helper.cursor_position()[0] == line
assert helper.cursor_position()[1] == column
cursor = editor.textCursor()
helper.match_select()
cursor = editor.textCursor()
assert cursor.hasSelection()
assert text in cursor.selectedText()
开发者ID:SirmoGames,项目名称:pyqode.core,代码行数:13,代码来源:test_text.py
示例17: test_goto_line
def test_goto_line(editor):
assert editor.textCursor().blockNumber() == 0
assert editor.textCursor().columnNumber() == 0
cursor = TextHelper(editor).goto_line(2, 0, move=False)
QTest.qWait(100)
assert editor.textCursor().blockNumber() != cursor.blockNumber()
assert editor.textCursor().columnNumber() == cursor.columnNumber()
cursor = TextHelper(editor).goto_line(9, move=True)
QTest.qWait(100)
assert editor.textCursor().blockNumber() == cursor.blockNumber() == 9
assert editor.textCursor().columnNumber() == cursor.columnNumber() == 0
assert TextHelper(editor).current_line_nbr() == 9
assert TextHelper(editor).current_column_nbr() == 0
开发者ID:dtonal,项目名称:pyqode.core,代码行数:13,代码来源:test_text.py
示例18: test_matched_selection
def test_matched_selection(editor):
line, column, text = 233, 14, ''' editor.textCursor(), 'import', QtGui.QTextDocument.FindCaseSensitively'''
cursor = editor.textCursor()
assert not cursor.hasSelection()
helper = TextHelper(editor)
helper.goto_line(line, column)
assert helper.cursor_position()[0] == line
assert helper.cursor_position()[1] == column
cursor = editor.textCursor()
helper.match_select()
cursor = editor.textCursor()
assert cursor.hasSelection()
assert text in cursor.selectedText()
开发者ID:dtonal,项目名称:pyqode.core,代码行数:13,代码来源:test_text.py
示例19: test_extended_selection
def test_extended_selection(editor):
for line, column, text in [(8, 15, 'pyqode.core.api.utils'),
(8, 1, 'from')]:
editor.file.open(__file__)
QTest.qWait(1000)
cursor = editor.textCursor()
assert not cursor.hasSelection()
helper = TextHelper(editor)
helper.goto_line(line, column)
assert helper.cursor_position()[0] == line
assert helper.cursor_position()[1] == column
cursor = editor.textCursor()
assert text in cursor.block().text()
helper.select_extended_word()
cursor = editor.textCursor()
assert cursor.hasSelection()
assert cursor.selectedText() == text
开发者ID:dtonal,项目名称:pyqode.core,代码行数:17,代码来源:test_text.py
示例20: on_install
def on_install(self, editor):
super(SearchAndReplacePanel, self).on_install(editor)
self.hide()
self.text_helper = TextHelper(editor)
开发者ID:must40,项目名称:pyqode.core,代码行数:4,代码来源:search_and_replace.py
注:本文中的pyqode.core.api.utils.TextHelper类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论