本文整理汇总了Python中pyqode.core.api.TextHelper.word_under_cursor方法的典型用法代码示例。如果您正苦于以下问题:Python TextHelper.word_under_cursor方法的具体用法?Python TextHelper.word_under_cursor怎么用?Python TextHelper.word_under_cursor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyqode.core.api.TextHelper
的用法示例。
在下文中一共展示了TextHelper.word_under_cursor方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_add_decoration
# 需要导入模块: from pyqode.core.api import TextHelper [as 别名]
# 或者: from pyqode.core.api.TextHelper import word_under_cursor [as 别名]
def test_add_decoration(editor):
helper = TextHelper(editor)
helper.goto_line(2, 2)
cursor = helper.word_under_cursor(select_whole_word=True)
deco = TextDecoration(cursor)
deco.set_as_bold()
deco.set_as_underlined(QtGui.QColor("#FF0000"))
editor.decorations.append(deco)
assert not editor.decorations.append(deco)
assert deco.contains_cursor(cursor)
# keep editor clean for next tests
editor.decorations.clear()
示例2: test_clear_decoration
# 需要导入模块: from pyqode.core.api import TextHelper [as 别名]
# 或者: from pyqode.core.api.TextHelper import word_under_cursor [as 别名]
def test_clear_decoration(editor):
# should work even when there are no more decorations
helper = TextHelper(editor)
editor.decorations.clear()
cursor = helper.word_under_cursor(select_whole_word=True)
deco = TextDecoration(cursor)
deco.set_as_bold()
deco.set_as_underlined(QtGui.QColor("#FF0000"))
editor.decorations.append(deco)
assert not editor.decorations.append(deco)
editor.decorations.clear()
assert editor.decorations.append(deco)
assert editor.decorations.remove(deco)
示例3: test_remove_decoration
# 需要导入模块: from pyqode.core.api import TextHelper [as 别名]
# 或者: from pyqode.core.api.TextHelper import word_under_cursor [as 别名]
def test_remove_decoration(editor):
helper = TextHelper(editor)
TextHelper(editor).goto_line(1, 2)
cursor = helper.word_under_cursor(select_whole_word=True)
deco = TextDecoration(cursor)
deco.set_as_bold()
deco.set_as_underlined(QtGui.QColor("#FF0000"))
editor.decorations.append(deco)
assert editor.decorations.remove(deco)
# already removed, return False
assert not editor.decorations.remove(deco)
assert editor.decorations.append(deco)
# keep editor clean for next tests
editor.decorations.clear()
示例4: _auto_import
# 需要导入模块: from pyqode.core.api import TextHelper [as 别名]
# 或者: from pyqode.core.api.TextHelper import word_under_cursor [as 别名]
def _auto_import(self):
helper = TextHelper(self.editor)
name = helper.word_under_cursor(select_whole_word=True).selectedText()
if name:
import_stmt = 'import %s' % name
else:
import_stmt = ''
import_stmt, status = QtWidgets.QInputDialog.getText(
self.editor, _('Add import'), _('Import statement:'),
QtWidgets.QLineEdit.Normal, import_stmt)
if status:
sh = self.editor.syntax_highlighter
line_number = sh.import_statements[0].blockNumber()
for stmt in sh.import_statements:
if stmt.text() == import_stmt:
# same import already exists
return
l, c = helper.cursor_position()
cursor = helper.goto_line(line_number)
cursor.insertText(import_stmt + '\n')
helper.goto_line(l + 1, c)