本文整理汇总了Python中cola.widgets.spellcheck.SpellCheckTextEdit.keyPressEvent方法的典型用法代码示例。如果您正苦于以下问题:Python SpellCheckTextEdit.keyPressEvent方法的具体用法?Python SpellCheckTextEdit.keyPressEvent怎么用?Python SpellCheckTextEdit.keyPressEvent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cola.widgets.spellcheck.SpellCheckTextEdit
的用法示例。
在下文中一共展示了SpellCheckTextEdit.keyPressEvent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: keyPressEvent
# 需要导入模块: from cola.widgets.spellcheck import SpellCheckTextEdit [as 别名]
# 或者: from cola.widgets.spellcheck.SpellCheckTextEdit import keyPressEvent [as 别名]
def keyPressEvent(self, event):
if event.key() == Qt.Key_Up:
cursor = self.textCursor()
position = cursor.position()
if position == 0:
# The cursor is at the beginning of the line.
# If we have selection then simply reset the cursor.
# Otherwise, emit a signal so that the parent can
# change focus.
if cursor.hasSelection():
cursor.setPosition(0)
self.setTextCursor(cursor)
else:
self.emit_leave()
event.accept()
return
text_before = unicode(self.toPlainText())[:position]
lines_before = text_before.count('\n')
if lines_before == 0:
# If we're on the first line, but not at the
# beginning, then move the cursor to the beginning
# of the line.
if event.modifiers() & Qt.ShiftModifier:
mode = QtGui.QTextCursor.KeepAnchor
else:
mode = QtGui.QTextCursor.MoveAnchor
cursor.setPosition(0, mode)
self.setTextCursor(cursor)
event.accept()
return
elif event.key() == Qt.Key_Down:
cursor = self.textCursor()
position = cursor.position()
all_text = unicode(self.toPlainText())
text_after = all_text[position:]
lines_after = text_after.count('\n')
if lines_after == 0:
if event.modifiers() & Qt.ShiftModifier:
mode = QtGui.QTextCursor.KeepAnchor
else:
mode = QtGui.QTextCursor.MoveAnchor
cursor.setPosition(len(all_text), mode)
self.setTextCursor(cursor)
event.accept()
return
SpellCheckTextEdit.keyPressEvent(self, event)