本文整理汇总了Python中qgis.PyQt.Qsci.QsciScintilla.keyPressEvent方法的典型用法代码示例。如果您正苦于以下问题:Python QsciScintilla.keyPressEvent方法的具体用法?Python QsciScintilla.keyPressEvent怎么用?Python QsciScintilla.keyPressEvent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgis.PyQt.Qsci.QsciScintilla
的用法示例。
在下文中一共展示了QsciScintilla.keyPressEvent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: keyPressEvent
# 需要导入模块: from qgis.PyQt.Qsci import QsciScintilla [as 别名]
# 或者: from qgis.PyQt.Qsci.QsciScintilla import keyPressEvent [as 别名]
def keyPressEvent(self, e):
startLine, startPos, endLine, endPos = self.getSelection()
# handle invalid cursor position and multiline selections
if not self.is_cursor_on_edition_zone() or startLine < endLine:
# allow copying and selecting
if e.modifiers() & (Qt.ControlModifier | Qt.MetaModifier):
if e.key() in (Qt.Key_C, Qt.Key_A):
QsciScintilla.keyPressEvent(self, e)
return
# allow selection
if e.modifiers() & Qt.ShiftModifier:
if e.key() in (Qt.Key_Left, Qt.Key_Right, Qt.Key_Home, Qt.Key_End):
QsciScintilla.keyPressEvent(self, e)
return
# all other keystrokes get sent to the input line
self.move_cursor_to_end()
line, index = self.getCursorPosition()
cmd = self.text(line)
if e.key() in (Qt.Key_Return, Qt.Key_Enter) and not self.isListActive():
self.entered()
elif e.key() in (Qt.Key_Left, Qt.Key_Home):
QsciScintilla.keyPressEvent(self, e)
# check whether the cursor is moved out of the edition zone
newline, newindex = self.getCursorPosition()
if newline < line or newindex < 4:
# fix selection and the cursor position
if self.hasSelectedText():
self.setSelection(line, self.getSelection()[3], line, 4)
else:
self.setCursorPosition(line, 4)
elif e.key() in (Qt.Key_Backspace, Qt.Key_Delete):
QsciScintilla.keyPressEvent(self, e)
# check whether the cursor is moved out of the edition zone
_, newindex = self.getCursorPosition()
if newindex < 4:
# restore the prompt chars (if removed) and
# fix the cursor position
self.insert(cmd[:3 - newindex] + " ")
self.setCursorPosition(line, 4)
self.recolor()
elif (e.modifiers() & (Qt.ControlModifier | Qt.MetaModifier) and e.key() == Qt.Key_V) or \
(e.modifiers() & Qt.ShiftModifier and e.key() == Qt.Key_Insert):
self.paste()
e.accept()
elif e.key() == Qt.Key_Down and not self.isListActive():
self.showPrevious()
elif e.key() == Qt.Key_Up and not self.isListActive():
self.showNext()
## TODO: press event for auto-completion file directory
else:
t = e.text()
self.autoCloseBracket = self.settings.value("pythonConsole/autoCloseBracket", False, type=bool)
self.autoImport = self.settings.value("pythonConsole/autoInsertionImport", True, type=bool)
txt = cmd[:index].replace('>>> ', '').replace('... ', '')
## Close bracket automatically
if t in self.opening and self.autoCloseBracket:
i = self.opening.index(t)
if self.hasSelectedText() and startPos != 0:
selText = self.selectedText()
self.removeSelectedText()
self.insert(self.opening[i] + selText + self.closing[i])
self.setCursorPosition(endLine, endPos + 2)
return
elif t == '(' and (re.match(r'^[ \t]*def \w+$', txt)
or re.match(r'^[ \t]*class \w+$', txt)):
self.insert('):')
else:
self.insert(self.closing[i])
## FIXES #8392 (automatically removes the redundant char
## when autoclosing brackets option is enabled)
elif t in [')', ']', '}'] and self.autoCloseBracket:
txt = self.text(line)
try:
if txt[index - 1] in self.opening and t == txt[index]:
self.setCursorPosition(line, index + 1)
self.SendScintilla(QsciScintilla.SCI_DELETEBACK)
except IndexError:
pass
elif t == ' ' and self.autoImport:
ptrn = r'^[ \t]*from [\w.]+$'
if re.match(ptrn, txt):
self.insert(' import')
self.setCursorPosition(line, index + 7)
QsciScintilla.keyPressEvent(self, e)