Exemplo n.º 1
0
    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()
Exemplo n.º 2
0
 def keyPressEvent(self, event):
     if event.key() == Qt.Key_Space:
         if QApplication.keyboardModifiers() == Qt.ControlModifier:
             self.autoCompleteFromAll()
             return
     QsciScintilla.keyPressEvent(self, event)
     self.complete.line, self.complete.column = self.getCursorPosition()
     self.complete.text = self.text()
     self.setMarginWidth(0, len(str(len(self.text().split('\n')))) * 20)
     # if event.key() not in [Qt.Key_Up, Qt.Key_Down, Qt.Key_Left, Qt.Key_Right]:
     #    if not self.complete.started:
     #        self.complete.start()
     self.key_pressed.emit()
Exemplo n.º 3
0
    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 [QtCore.Qt.Key_S, QtCore.Qt.Key_Save]:
            modifiers = QApplication.keyboardModifiers()
            if modifiers == QtCore.Qt.ControlModifier and self.is_modified:
                logger.debug("Saving...")
                self.on_save_changes()

        self.key_pressed_event(event)
Exemplo n.º 4
0
    def key_press_event(self, event):

        self.update_dirty()
        if self.editor.__class__.__name__ == "LineTextWidget":
            return self.editor.edit.keyReleaseEvent(event)  # When using PySide without QSciScintilla

        QsciScintilla.keyPressEvent(self.editor, event)

        linenr, pos_in_line = self.editor.getCursorPosition()
        line = str(self.editor.text(linenr)[:pos_in_line])

        if event.key() == Qt.Key_F1:
            try:
                self.parent.show_documentation(getattr(self.scriptRunner, str(self.editor.selectedText())))
            except AttributeError:
                pass

        if event.key() == Qt.Key_Enter or event.key() == Qt.Key_Return:
            for tip in self.autocomplete_lst:
                try:
                    if line.endswith(tip[:tip.index('(') ]):
                        self.editor.insert(tip[tip.index('('):])
                        parent, residual = self.scriptRunner.split_line(line)
                        self.parent.show_documentation(self.scriptRunner.get_function_dict(parent, residual)[residual])
                        return
                except ValueError:
                    pass

        if event.key() < 100 or event.key() in [Qt.Key_Backspace, Qt.Key_Shift]:
            linenr, pos_in_line = self.editor.getCursorPosition()
            line = str(self.editor.text(linenr)[:pos_in_line])

            lst = self.scriptRunner.get_autocomplete_list(line)

            if lst is not None:
                self.api.clear()
                list(map(self.api.add, lst))
                self.api.prepare()
                if len(lst) > 0:
                    self.autocomplete_lst = lst

            self.editor.autoCompleteFromAll()
            shift_event = QKeyEvent(QEvent.KeyPress, Qt.Key_Shift, Qt.NoModifier)
            QsciScintilla.keyPressEvent(self.editor, shift_event)  # show autocomplete list
Exemplo n.º 5
0
 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)