예제 #1
0
 def focusInEvent(self, event):
     """ Test whether the file has been changed 'behind our back'
     """
     # Act normally to the focus event        
     BaseTextCtrl.focusInEvent(self, event)
     # Test file change
     self.testWhetherFileWasChanged()
예제 #2
0
파일: editor.py 프로젝트: guanzd88/iep
 def focusInEvent(self, event):
     """ Test whether the file has been changed 'behind our back'
     """
     # Act normally to the focus event
     BaseTextCtrl.focusInEvent(self, event)
     # Test file change
     self.testWhetherFileWasChanged()
예제 #3
0
 def showEvent(self, event=None):
     """ Capture show event to change title. """
     # Act normally
     if event:
         BaseTextCtrl.showEvent(self, event)
     
     # Make parser update
     iep.parser.parseThis(self)
예제 #4
0
 def dropEvent(self, event):
     """ Drop files in the list. """   
     if event.mimeData().hasUrls():
         # file: let the editorstack do the work.
         iep.editors.dropEvent(event)
     else:
         # text: act normal
         BaseTextCtrl.dropEvent(self, event)
예제 #5
0
파일: editor.py 프로젝트: guanzd88/iep
    def showEvent(self, event=None):
        """ Capture show event to change title. """
        # Act normally
        if event:
            BaseTextCtrl.showEvent(self, event)

        # Make parser update
        iep.parser.parseThis(self)
예제 #6
0
파일: editor.py 프로젝트: guanzd88/iep
 def dropEvent(self, event):
     """ Drop files in the list. """
     if event.mimeData().hasUrls():
         # file: let the editorstack do the work.
         iep.editors.dropEvent(event)
     else:
         # text: act normal
         BaseTextCtrl.dropEvent(self, event)
예제 #7
0
 def dragMoveEvent(self, event):
     """ Otherwise cursor can get stuck.
     https://bitbucket.org/iep-project/iep/issue/252
     https://qt-project.org/forums/viewthread/3180
     """
     if event.mimeData().hasUrls():
         event.acceptProposedAction()
     else:
         BaseTextCtrl.dropEvent(self, event)
예제 #8
0
    def cut(self):
        """ Reimplement cut to only copy if part of the selected text
        is not at the prompt. """

        if self.isReadOnly():
            return self.copy()
        else:
            return BaseTextCtrl.cut(self)
예제 #9
0
파일: shell.py 프로젝트: guanzd88/iep
 def cut(self):
     """ Reimplement cut to only copy if part of the selected text
     is not at the prompt. """
     
     if self.isReadOnly():
         return self.copy()
     else:
         return BaseTextCtrl.cut(self)
예제 #10
0
 def paste(self):
     """ Reimplement paste to paste at the end of the edit line when
     the position is at the prompt. """
     self.ensureCursorAtEditLine()
     # Paste normally
     return BaseTextCtrl.paste(self)
예제 #11
0
    def keyPressEvent(self, event):

        if event.key() in [Qt.Key_Return, Qt.Key_Enter]:

            # First check if autocompletion triggered
            if self.potentiallyAutoComplete(event):
                return
            else:
                # Enter: execute line
                # Remove calltip and autocomp if shown
                self.autocompleteCancel()
                self.calltipCancel()

                # reset history needle
                self._historyNeedle = None

                # process
                self.processLine()
                return

        if event.key() == Qt.Key_Escape:
            # Escape clears command
            if not (self.autocompleteActive() or self.calltipActive()):
                self.clearCommand()

        if event.key() == Qt.Key_Home:
            # Home goes to the prompt.
            cursor = self.textCursor()
            if event.modifiers() & Qt.ShiftModifier:
                cursor.setPosition(self._cursor2.position(), A_KEEP)
            else:
                cursor.setPosition(self._cursor2.position(), A_MOVE)
            #
            self.setTextCursor(cursor)
            self.autocompleteCancel()
            return

        if event.key() == Qt.Key_Insert:
            # Don't toggle between insert mode and overwrite mode.
            return True

        #Ensure to not backspace / go left beyond the prompt
        if event.key() in [Qt.Key_Backspace, Qt.Key_Left]:
            self._historyNeedle = None
            if self.textCursor().position() == self._cursor2.position():
                if event.key() == Qt.Key_Backspace:
                    self.textCursor().removeSelectedText()
                return  #Ignore the key, don't go beyond the prompt


        if event.key() in [Qt.Key_Up, Qt.Key_Down] and not \
                self.autocompleteActive():

            # needle
            if self._historyNeedle is None:
                # get partly-written-command
                #
                # Select text
                cursor = self.textCursor()
                cursor.setPosition(self._cursor2.position(), A_MOVE)
                cursor.movePosition(cursor.End, A_KEEP)
                # Update needle text
                self._historyNeedle = cursor.selectedText()
                self._historyStep = 0

            #Browse through history
            if event.key() == Qt.Key_Up:
                self._historyStep += 1
            else:  # Key_Down
                self._historyStep -= 1
                if self._historyStep < 1:
                    self._historyStep = 1

            # find the command
            count = 0
            for c in self._history:
                if c.startswith(self._historyNeedle):
                    count += 1
                    if count >= self._historyStep:
                        break
            else:
                # found nothing-> reset
                self._historyStep = 0
                c = self._historyNeedle

            # Replace text
            cursor = self.textCursor()
            cursor.setPosition(self._cursor2.position(), A_MOVE)
            cursor.movePosition(cursor.End, A_KEEP)
            cursor.insertText(c)

            self.ensureCursorAtEditLine()
            return

        else:
            # Reset needle
            self._historyNeedle = None

        #if a 'normal' key is pressed, ensure the cursor is at the edit line
        if event.text():
            self.ensureCursorAtEditLine()

        #Default behaviour: BaseTextCtrl
        BaseTextCtrl.keyPressEvent(self, event)
예제 #12
0
 def mousePressEvent(self, event):
     """ Disable right MB and middle MB (which pastes by default). """
     if event.button() != QtCore.Qt.MidButton:
         BaseTextCtrl.mousePressEvent(self, event)
예제 #13
0
파일: shell.py 프로젝트: guanzd88/iep
 def paste(self):
     """ Reimplement paste to paste at the end of the edit line when
     the position is at the prompt. """
     self.ensureCursorAtEditLine()
     # Paste normally
     return BaseTextCtrl.paste(self)
예제 #14
0
파일: shell.py 프로젝트: guanzd88/iep
    def keyPressEvent(self,event):
        
        if event.key() in [Qt.Key_Return, Qt.Key_Enter]:
            
            # First check if autocompletion triggered
            if self.potentiallyAutoComplete(event):
                return
            else:
                # Enter: execute line
                # Remove calltip and autocomp if shown
                self.autocompleteCancel()
                self.calltipCancel()
                
                # reset history needle
                self._historyNeedle = None
                
                # process
                self.processLine()
                return
        
        if event.key() == Qt.Key_Escape:
            # Escape clears command
            if not ( self.autocompleteActive() or self.calltipActive() ): 
                self.clearCommand()
            
        if event.key() == Qt.Key_Home:
            # Home goes to the prompt.
            cursor = self.textCursor()
            if event.modifiers() & Qt.ShiftModifier:
                cursor.setPosition(self._cursor2.position(), A_KEEP)
            else:
                cursor.setPosition(self._cursor2.position(), A_MOVE)
            #
            self.setTextCursor(cursor)
            self.autocompleteCancel()
            return

        if event.key() == Qt.Key_Insert:
            # Don't toggle between insert mode and overwrite mode.
            return True
        
        #Ensure to not backspace / go left beyond the prompt
        if event.key() in [Qt.Key_Backspace, Qt.Key_Left]:
            self._historyNeedle = None
            if self.textCursor().position() == self._cursor2.position():
                if event.key() == Qt.Key_Backspace:
                    self.textCursor().removeSelectedText()
                return  #Ignore the key, don't go beyond the prompt


        if event.key() in [Qt.Key_Up, Qt.Key_Down] and not \
                self.autocompleteActive():
            
            # needle
            if self._historyNeedle is None:
                # get partly-written-command
                #
                # Select text                
                cursor = self.textCursor()
                cursor.setPosition(self._cursor2.position(), A_MOVE)
                cursor.movePosition(cursor.End, A_KEEP)
                # Update needle text
                self._historyNeedle = cursor.selectedText()
                self._historyStep = 0
            
            #Browse through history
            if event.key() == Qt.Key_Up:
                self._historyStep +=1
            else: # Key_Down
                self._historyStep -=1
                if self._historyStep < 1:
                    self._historyStep = 1
            
            # find the command
            count = 0
            for c in self._history:
                if c.startswith(self._historyNeedle):
                    count+=1
                    if count >= self._historyStep:
                        break
            else:
                # found nothing-> reset
                self._historyStep = 0
                c = self._historyNeedle  
            
            # Replace text
            cursor = self.textCursor()
            cursor.setPosition(self._cursor2.position(), A_MOVE)
            cursor.movePosition(cursor.End, A_KEEP)
            cursor.insertText(c)
            
            self.ensureCursorAtEditLine()
            return
        
        else:
            # Reset needle
            self._historyNeedle = None
        
        #if a 'normal' key is pressed, ensure the cursor is at the edit line
        if event.text():
            self.ensureCursorAtEditLine()
        
        #Default behaviour: BaseTextCtrl
        BaseTextCtrl.keyPressEvent(self,event)
예제 #15
0
파일: shell.py 프로젝트: guanzd88/iep
 def mousePressEvent(self, event):
     """ Disable right MB and middle MB (which pastes by default). """
     if event.button() != QtCore.Qt.MidButton:
         BaseTextCtrl.mousePressEvent(self, event)