def keyPressEvent(self, e): startLine, _, endLine, _ = self.getSelection() # handle invalid cursor position and multiline selections if not self.is_cursor_on_edition_zone() or startLine < endLine: # allow to copy and select 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: 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: QsciScintilla.keyPressEvent(self, e)
def keyPressEvent(self, ev): """ Re-implemented to handle the user input a key at a time. @param ev key event (QKeyEvent) """ txt = ev.text() key = ev.key() ctrl = ev.modifiers() & Qt.ControlModifier shift = ev.modifiers() & Qt.ShiftModifier # See it is text to insert. if (self.keymap.has_key(key) and not shift and not ctrl): self.keymap[key]() elif self.__isCursorOnLastLine() and txt.length(): QsciScintilla.keyPressEvent(self, ev) self.incrementalSearchActive = True if (txt == '.'): self.__showDynCompletion() elif (ctrl or shift): QsciScintilla.keyPressEvent(self, ev) else: ev.ignore()
def keyPressEvent(self, ev): """ Re-implemented to handle the user input a key at a time. @param ev key event (QKeyEvent) """ txt = ev.text() key = ev.key() ctrl = ev.modifiers() & Qt.ControlModifier if(ctrl): QsciScintilla.keyPressEvent(self, ev) elif(self.keymap.has_key(key)): self.keymap[key]() # See it is text to insert. elif self.__isCursorOnLastLine() and txt.length() : QsciScintilla.keyPressEvent(self, ev) self.incrementalSearchActive = True if(txt == '.'): self.__showDynCompletion() else: ev.ignore()
def keyPressEvent(self, ev): """ Re-implemented to handle the user input a key at a time. @param ev key event (QKeyEvent) """ txt = ev.text() key = ev.key() ctrl = ev.modifiers() & Qt.ControlModifier shift = ev.modifiers() & Qt.ShiftModifier # See it is text to insert. if(self.keymap.has_key(key) and not shift and not ctrl): self.keymap[key]() elif ev == QtGui.QKeySequence.Paste: self.paste() elif self.__isCursorOnLastLine() and len(txt) : QsciScintilla.keyPressEvent(self, ev) self.incrementalSearchActive = True if(txt == '.'): self.__showDynCompletion() elif(ctrl or shift): QsciScintilla.keyPressEvent(self, ev) else: ev.ignore()
def keyPressEvent(self, event): """ desc: Intercepts certain keypress events to implement custom copy-pasting and zooming. arguments: event: type: QKeyPressEvent """ key = event.key() ctrl = event.modifiers() & QtCore.Qt.ControlModifier shift = event.modifiers() & QtCore.Qt.ShiftModifier # Zoom in/out if ((key == QtCore.Qt.Key_Plus) and ctrl) \ or ((key == QtCore.Qt.Key_Equal) and shift and ctrl): self.zoomIn() event.accept() elif (key == QtCore.Qt.Key_Minus) and ctrl: self.zoomOut() event.accept() elif (key == QtCore.Qt.Key_V) and ctrl: self.paste() event.accept() else: QsciScintilla.keyPressEvent(self, event)
def keyPressEvent(self, e): startLine, _, endLine, _ = self.getSelection() # handle invalid cursor position and multiline selections if not self.is_cursor_on_edition_zone() or startLine < endLine: # allow to copy and select 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: 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: QsciScintilla.keyPressEvent(self, e)
def keyPressEvent(self, event): """Reimplement Qt method""" key = event.key() ctrl = event.modifiers() & Qt.ControlModifier shift = event.modifiers() & Qt.ShiftModifier # Zoom in/out if key in (Qt.Key_Enter, Qt.Key_Return) and not shift and not ctrl: QsciScintilla.keyPressEvent(self, event) self.fix_indent() elif ((key == Qt.Key_Plus) and ctrl) \ or ((key == Qt.Key_Equal) and shift and ctrl): self.zoomIn() event.accept() elif (key == Qt.Key_Minus) and ctrl: self.zoomOut() event.accept() # Indent/unindent elif key == Qt.Key_Backtab: self.unindent() event.accept() elif (key == Qt.Key_Tab): if self.is_completion_widget_visible(): self.SendScintilla(QsciScintilla.SCI_TAB) else: self.indent() event.accept() elif (key == Qt.Key_V) and ctrl: self.paste() event.accept() elif os.name == 'posix' and key == Qt.Key_Z and shift and ctrl: self.redo() event.accept() #TODO: find other shortcuts... # elif (key == Qt.Key_3) and ctrl: # self.comment() # event.accept() # elif (key == Qt.Key_2) and ctrl: # self.uncomment() # event.accept() # elif (key == Qt.Key_4) and ctrl: # self.blockcomment() # event.accept() # elif (key == Qt.Key_5) and ctrl: # self.unblockcomment() # event.accept() else: QsciScintilla.keyPressEvent(self, event) if CONF.get('main', 'workaround/gnome_qscintilla'): # Workaround for QScintilla's completion with Gnome from PyQt4.QtGui import QListWidget if self.is_completion_widget_visible(): for w in self.children(): if isinstance(w, QListWidget): w.setWindowFlags(Qt.Dialog| Qt.FramelessWindowHint) w.show()
def keyPressEvent(self, event): # This reimplementation add support for auto indentation # for blocks need_indent = (event.key() == Qt.Key_Return and self._need_auto_indent_open()) QsciScintilla.keyPressEvent(self, event) if need_indent: self._insert_indent()
def keyPressEvent(self, ev): k = ev.key() mdf = ev.modifiers() Return = QtCore.Qt.Key_Return Control = QtCore.Qt.ControlModifier Shift = QtCore.Qt.ShiftModifier Slash = QtCore.Qt.Key_Slash Question = QtCore.Qt.Key_Question Minus = QtCore.Qt.Key_Minus V = QtCore.Qt.Key_V Z = QtCore.Qt.Key_Z passthru = True if k == Return: lineno, _linedex = self.getCursorPosition() line = self.text(lineno).strip() indent = self.indentation(lineno) char = line[-1:] colon = ':' if char == colon: # auto indent indent += 4 QsciScintilla.keyPressEvent(self, ev) self.insert(' ' * indent) self.setCursorPosition(lineno + 1, indent) passthru = False elif mdf & Control and k == Slash: self.commentlines() passthru = False elif mdf & Control and k == Question: self.commentlines(un=True) passthru = False elif mdf & Control and k == Minus: self.editor.zoomout() passthru = False elif mdf & Control and k == V: self.paste() passthru = False elif mdf & Control and mdf & Shift and k == Z: self.redo() passthru = False if passthru: QsciScintilla.keyPressEvent(self, ev) self.editor.settitle() self.update_window_modified()
def keyPressEvent(self, e): if e.key() in (Qt.Key_Return, Qt.Key_Enter): self.entered() elif e.key() == Qt.Key_Escape: self.close() elif e.key() in (Qt.Key_Backspace, Qt.Key_Delete): _, newindex = self.getCursorPosition() if newindex > len(self.prompt): QsciScintilla.keyPressEvent(self, e) else: QsciScintilla.keyPressEvent(self, e)
def _key_pressed(self, event): """ Handle KeyPressed event We only care about CTRL-S in order to save changes :param event: key event """ QsciScintilla.keyPressEvent(self._code_editor, event) if event.key() in [Qt.Key_S, Qt.Key_Save]: modifiers = QtGui.QApplication.keyboardModifiers() if modifiers == Qt.ControlModifier and self.is_modified(): self.logger.debug("Saving...") self.on_save_changes() self.key_pressed(event)
def keyPressEvent(self, event): if event.key() == QtCore.Qt.Key_Backtab: self.unindent_() elif event.key() == QtCore.Qt.Key_Tab: self.indent_() else: return QsciScintilla.keyPressEvent(self,event)
def keyPressEvent(self, e): """ Captures keypresses to implement apply (Alt+A Arguments: e -- a keypress even """ # Process the Alt + A shortcut to apply changes if e.key() == QtCore.Qt.Key_A and e.modifiers() == QtCore.Qt.AltModifier: self._parent.apply.clicked.emit(True) return if e.key() == QtCore.Qt.Key_F and e.modifiers() == QtCore.Qt.ControlModifier: self._parent.perform_replace() return QsciScintilla.keyPressEvent(self, e)
def keyPressEvent(self, e): """ Captures keypresses to implement apply (Alt+A Arguments: e -- a keypress even """ # Process the Alt + A shortcut to apply changes if e.key() == QtCore.Qt.Key_A and \ e.modifiers() == QtCore.Qt.AltModifier: self._parent.apply.clicked.emit(True) return if e.key() == QtCore.Qt.Key_F and \ e.modifiers() == QtCore.Qt.ControlModifier: self._parent.perform_replace() return QsciScintilla.keyPressEvent(self, e)
def keyPressEvent(self, event): """Reimplement Qt method""" key = event.key() ctrl = event.modifiers() & Qt.ControlModifier shift = event.modifiers() & Qt.ShiftModifier # Zoom in/out if ((key == Qt.Key_Plus) and ctrl) \ or ((key==Qt.Key_Equal) and shift and ctrl): self.zoomIn() event.accept() elif (key == Qt.Key_Minus) and ctrl: self.zoomOut() event.accept() # Indent/unindent elif key == Qt.Key_Backtab: self.unindent() event.accept() elif (key == Qt.Key_Tab): if self.is_completion_widget_visible(): self.SendScintilla(QsciScintilla.SCI_TAB) else: self.indent() event.accept() elif (key == Qt.Key_V) and ctrl: self.paste() event.accept() #TODO: find other shortcuts... # elif (key == Qt.Key_3) and ctrl: # self.comment() # event.accept() # elif (key == Qt.Key_2) and ctrl: # self.uncomment() # event.accept() # elif (key == Qt.Key_4) and ctrl: # self.blockcomment() # event.accept() # elif (key == Qt.Key_5) and ctrl: # self.unblockcomment() # event.accept() else: QsciScintilla.keyPressEvent(self, event)
def keyPressEvent(self, event): """ Reimplemented to create a console-like interface. """ line, index = self.getCursorPosition() key = event.key() ctrl = event.modifiers() & QtCore.Qt.ControlModifier alt = event.modifiers() & QtCore.Qt.AltModifier shift_down = event.modifiers() & QtCore.Qt.ShiftModifier if ctrl: pass elif alt: pass elif key == QtCore.Qt.Key_Backspace: if self.getCursorPosition() == self.blocking_cursor_pos: pass else: QsciScintilla.keyPressEvent(self, event) elif key == QtCore.Qt.Key_Left: if self.getCursorPosition() == self.blocking_cursor_pos: pass else: QsciScintilla.keyPressEvent(self, event) elif key == QtCore.Qt.Key_Up: self.scrollVertical(-1) elif key == QtCore.Qt.Key_Down: self.scrollVertical(1) elif key == QtCore.Qt.Key_Return: # get input text text = self.getText(self.blocking_cursor_pos, self.position("eof")) self.insertInput(text) else: QsciScintilla.keyPressEvent(self, event)
def keyPressEvent(self, event): """ Reimplemented to create a console-like interface. """ line, index = self.getCursorPosition() key = event.key() ctrl = event.modifiers() & QtCore.Qt.ControlModifier alt = event.modifiers() & QtCore.Qt.AltModifier shift_down = event.modifiers() & QtCore.Qt.ShiftModifier if ctrl: pass elif alt: pass elif key == QtCore.Qt.Key_Backspace: if self.getCursorPosition() == self.blocking_cursor_pos: pass else: QsciScintilla.keyPressEvent(self, event) elif key == QtCore.Qt.Key_Left: if self.getCursorPosition() == self.blocking_cursor_pos: pass else: QsciScintilla.keyPressEvent(self, event) elif key == QtCore.Qt.Key_Up: self.scrollVertical(-1) elif key == QtCore.Qt.Key_Down: self.scrollVertical(1) elif key == QtCore.Qt.Key_Return: # get input text text = self.getText( self.blocking_cursor_pos, self.position("eof")) self.insertInput(text) else: QsciScintilla.keyPressEvent(self, event)
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 to copy and select 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 = unicode(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)
def keyPressEvent(self, e): startLine, startPos, endLine, _ = self.getSelection() # handle invalid cursor position and multiline selections if not self.is_cursor_on_edition_zone() or startLine < endLine: # allow to copy and select 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: if self.settings.value("pythonConsole/autoCloseBracket", True, type=bool): t = unicode(e.text()) ## Close bracket automatically if t in self.opening: 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]) return else: self.insert(self.closing[i]) QsciScintilla.keyPressEvent(self, e)
def keyPressEvent(self, event): """ Reimplement Qt method @param event: @type event: """ key = event.key() startLine, startPos, endLine, endPos = self.getSelection() line, index = self.getCursorPosition() cmd = self.text(line) if (key == Qt.Key_Tab): self.indent() event.accept() elif key == Qt.Key_Backtab: self.unindent() event.accept() else: # new in v13.1 t = event.text() # extract option from settings file autoCloseBracket = QtHelper.str2bool( Settings.instance().readValue(key='Editor/auto-close-bracket')) txt = cmd[:index].replace('>>> ', '').replace('... ', '') # new in v16 afterTxt = cmd[index:] if len(afterTxt): afterTxt = afterTxt.splitlines()[0] # end of new if t in self.opening and autoCloseBracket: i = self.opening.index(t) if self.hasSelectedText(): selText = self.selectedText() self.removeSelectedText() self.insert(self.opening[i] + selText + self.closing[i]) self.setCursorPosition(endLine, endPos + 2) return else: if len(afterTxt): pass 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]) elif t in [')', ']', '}'] and 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 else: pass # end new in v13.1 QsciScintilla.keyPressEvent(self, event)
def keyPressEvent(self, e): linenr, index = self.getCurLine() if not self.is_cursor_on_last_line() or index < 4: if e.modifiers() & Qt.ControlModifier or e.modifiers( ) & Qt.MetaModifier: if e.key() == Qt.Key_C or e.key() == Qt.Key_A: QsciScintilla.keyPressEvent(self, e) else: # all other keystrokes get sent to the input line self.move_cursor_to_end() #pass else: if (e.key() == Qt.Key_Return or e.key() == Qt.Key_Enter) and not self.isListActive(): self.entered() elif e.modifiers() & Qt.ControlModifier: if e.key() == Qt.Key_V: self.paste() elif e.key() == Qt.Key_C: self.copy() elif e.key() == Qt.Key_X: self.cut() elif e.key() == Qt.Key_Left: e.accept() if e.modifiers() & Qt.ShiftModifier: if index > 4: if e.modifiers() & Qt.ControlModifier: self.SendScintilla( QsciScintilla.SCI_WORDLEFTEXTEND) else: self.SendScintilla( QsciScintilla.SCI_CHARLEFTEXTEND) else: if index > 4: if e.modifiers() & Qt.ControlModifier: self.SendScintilla(QsciScintilla.SCI_WORDLEFT) else: self.SendScintilla(QsciScintilla.SCI_CHARLEFT) elif e.key() == Qt.Key_Right: e.accept() if e.modifiers() & Qt.ShiftModifier: if index >= 4: if e.modifiers() & Qt.ControlModifier: self.SendScintilla( QsciScintilla.SCI_WORDRIGHTEXTEND) else: self.SendScintilla( QsciScintilla.SCI_CHARRIGHTEXTEND) else: if index >= 4: if e.modifiers() & Qt.ControlModifier: self.SendScintilla(QsciScintilla.SCI_WORDRIGHT) else: self.SendScintilla(QsciScintilla.SCI_CHARRIGHT) elif e.key() == Qt.Key_Backspace: curPos, pos = self.getCursorPosition() line = self.lines() - 1 if curPos < line - 1 or pos < 5: return #else: #self.move_cursor_to_end() QsciScintilla.keyPressEvent(self, e) elif e.key() == Qt.Key_Delete: if self.hasSelectedText(): self.removeSelectedText() elif self.is_cursor_on_last_line(): self.SendScintilla(QsciScintilla.SCI_CLEAR) e.accept() elif e.key() == Qt.Key_Home: self.setCursorPosition(linenr, 4) self.ensureCursorVisible() 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: QsciScintilla.keyPressEvent(self, e)
def keyPressEvent(self, e): linenr, index = self.getCurLine() if not self.is_cursor_on_last_line() or index < 4: if e.modifiers() & Qt.ControlModifier or e.modifiers() & Qt.MetaModifier: if e.key() == Qt.Key_C or e.key() == Qt.Key_A: QsciScintilla.keyPressEvent(self, e) else: # all other keystrokes get sent to the input line self.move_cursor_to_end() #pass else: if (e.key() == Qt.Key_Return or e.key() == Qt.Key_Enter) and not self.isListActive(): self.entered() elif e.modifiers() & Qt.ControlModifier: if e.key() == Qt.Key_V: self.paste() elif e.key() == Qt.Key_C: self.copy() elif e.key() == Qt.Key_X: self.cut() elif e.key() == Qt.Key_Left: e.accept() if e.modifiers() & Qt.ShiftModifier: if index > 4: if e.modifiers() & Qt.ControlModifier: self.SendScintilla(QsciScintilla.SCI_WORDLEFTEXTEND) else: self.SendScintilla(QsciScintilla.SCI_CHARLEFTEXTEND) else: if index > 4: if e.modifiers() & Qt.ControlModifier: self.SendScintilla(QsciScintilla.SCI_WORDLEFT) else: self.SendScintilla(QsciScintilla.SCI_CHARLEFT) elif e.key() == Qt.Key_Right: e.accept() if e.modifiers() & Qt.ShiftModifier: if index >= 4: if e.modifiers() & Qt.ControlModifier: self.SendScintilla(QsciScintilla.SCI_WORDRIGHTEXTEND) else: self.SendScintilla(QsciScintilla.SCI_CHARRIGHTEXTEND) else: if index >= 4: if e.modifiers() & Qt.ControlModifier: self.SendScintilla(QsciScintilla.SCI_WORDRIGHT) else: self.SendScintilla(QsciScintilla.SCI_CHARRIGHT) elif e.key() == Qt.Key_Backspace: curPos, pos = self.getCursorPosition() line = self.lines() -1 if curPos < line -1 or pos < 5: return #else: #self.move_cursor_to_end() QsciScintilla.keyPressEvent(self, e) elif e.key() == Qt.Key_Delete: if self.hasSelectedText(): self.removeSelectedText() elif self.is_cursor_on_last_line(): self.SendScintilla(QsciScintilla.SCI_CLEAR) e.accept() elif e.key() == Qt.Key_Home: self.setCursorPosition(linenr,4) self.ensureCursorVisible() 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: QsciScintilla.keyPressEvent(self, e)
def keyPressEvent(self, e): startLine, startPos, endLine, _ = self.getSelection() # handle invalid cursor position and multiline selections if not self.is_cursor_on_edition_zone() or startLine < endLine: # allow to copy and select 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: if self.settings.value("pythonConsole/autoCloseBracket", True, type=bool): t = unicode(e.text()) ## Close bracket automatically if t in self.opening: 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]) return else: self.insert(self.closing[i]) QsciScintilla.keyPressEvent(self, e)
def keyPressEvent(self,e): print "Key pressed!" QsciScintilla.keyPressEvent(self,e)