Skip to content

Commit

Permalink
Merge pull request #242 from slarosa/master
Browse files Browse the repository at this point in the history
improved python console paste action and minor bug fixes
  • Loading branch information
timlinux committed Sep 22, 2012
2 parents 73fcb66 + c5ff5ee commit 1b95cdc
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions python/console_sci.py
Expand Up @@ -124,6 +124,8 @@ def clearConsole(self):
self.setFocus() self.setFocus()


def commandConsole(self, command): def commandConsole(self, command):
if not self.is_cursor_on_last_line():
self.move_cursor_to_end()
line, pos = self.getCurLine() line, pos = self.getCurLine()
selCmd= self.text(line).length() selCmd= self.text(line).length()
self.setSelection(line, 4, line, selCmd) self.setSelection(line, 4, line, selCmd)
Expand Down Expand Up @@ -324,7 +326,6 @@ def showPrevious(self):
self.move_cursor_to_end() self.move_cursor_to_end()
#self.SendScintilla(QsciScintilla.SCI_DELETEBACK) #self.SendScintilla(QsciScintilla.SCI_DELETEBACK)



def showNext(self): def showNext(self):
if self.historyIndex > 0 and not self.history.isEmpty(): if self.historyIndex > 0 and not self.history.isEmpty():
line, pos = self.getCurLine() line, pos = self.getCurLine()
Expand Down Expand Up @@ -365,7 +366,6 @@ def keyPressEvent(self, e):
QsciScintilla.keyPressEvent(self, e) QsciScintilla.keyPressEvent(self, e)
elif e.key() == Qt.Key_Delete: elif e.key() == Qt.Key_Delete:
if self.hasSelectedText(): if self.hasSelectedText():
self.check_selection()
self.removeSelectedText() self.removeSelectedText()
elif self.is_cursor_on_last_line(): elif self.is_cursor_on_last_line():
self.SendScintilla(QsciScintilla.SCI_CLEAR) self.SendScintilla(QsciScintilla.SCI_CLEAR)
Expand Down Expand Up @@ -405,13 +405,6 @@ def keyPressEvent(self, e):
self.SendScintilla(QsciScintilla.SCI_WORDRIGHT) self.SendScintilla(QsciScintilla.SCI_WORDRIGHT)
else: else:
self.SendScintilla(QsciScintilla.SCI_CHARRIGHT) self.SendScintilla(QsciScintilla.SCI_CHARRIGHT)
elif e.key() == Qt.Key_Delete:
if self.hasSelectedText():
self.check_selection()
self.removeSelectedText()
elif self.is_cursor_on_last_line():
self.SendScintilla(QsciScintilla.SCI_CLEAR)
event.accept()
## TODO: press event for auto-completion file directory ## TODO: press event for auto-completion file directory
#elif e.key() == Qt.Key_Tab: #elif e.key() == Qt.Key_Tab:
#self.show_file_completion() #self.show_file_completion()
Expand All @@ -423,28 +416,29 @@ def keyPressEvent(self, e):
def paste(self): def paste(self):
"""Reimplement QScintilla method""" """Reimplement QScintilla method"""
stringPaste = unicode(QApplication.clipboard().text()) stringPaste = unicode(QApplication.clipboard().text())
if self.hasSelectedText():
self.removeSelectedText()
self.insertFromDropPaste(stringPaste) self.insertFromDropPaste(stringPaste)


## Drag and drop ## Drag and drop
def dragEnterEvent(self, e): def dropEvent(self, e):
if e.mimeData().hasFormat('text/plain'): if e.mimeData().hasText():
stringDrag = e.mimeData().text()
self.insertFromDropPaste(stringDrag)
e.setDropAction(Qt.MoveAction)
e.accept() e.accept()
else: else:
e.ignore() QsciScintillaCompat.dropEvent(self, e)


def dropEvent(self, e):
stringDrag = e.mimeData().text()
self.insertFromDropPaste(stringDrag)

def insertFromDropPaste(self, textDP): def insertFromDropPaste(self, textDP):
pasteList = QStringList() pasteList = QStringList()
pasteList = textDP.split("\n") pasteList = textDP.split("\n")
for line in pasteList[:-1]: for line in pasteList[:-1]:
self.append(line) self.insert(line)
self.move_cursor_to_end() self.move_cursor_to_end()
#self.SendScintilla(QsciScintilla.SCI_DELETEBACK) #self.SendScintilla(QsciScintilla.SCI_DELETEBACK)
self.runCommand(unicode(self.currentCommand())) self.runCommand(unicode(self.currentCommand()))
self.append(unicode(pasteList[-1])) self.insert(unicode(pasteList[-1]))
self.move_cursor_to_end() self.move_cursor_to_end()


def getTextFromEditor(self): def getTextFromEditor(self):
Expand Down

0 comments on commit 1b95cdc

Please sign in to comment.