mirror of
https://github.com/qgis/QGIS.git
synced 2025-11-28 00:06:23 -05:00
automatically switch focus to the input area in console
- any keystroke switch focus when in the output area - moved closeEvent method to DockWidget (since 0330202 it has not worked anymore)
This commit is contained in:
parent
6abe8611f4
commit
2425f92ce0
@ -79,6 +79,10 @@ class PythonConsole(QDockWidget):
|
|||||||
self.raise_()
|
self.raise_()
|
||||||
QDockWidget.setFocus(self)
|
QDockWidget.setFocus(self)
|
||||||
|
|
||||||
|
def closeEvent(self, event):
|
||||||
|
self.console.edit.writeHistoryFile()
|
||||||
|
QWidget.closeEvent(self, event)
|
||||||
|
|
||||||
class PythonConsoleWidget(QWidget):
|
class PythonConsoleWidget(QWidget):
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
QWidget.__init__(self, parent)
|
QWidget.__init__(self, parent)
|
||||||
@ -256,8 +260,8 @@ class PythonConsoleWidget(QWidget):
|
|||||||
sM.setPopupMode(QToolButton.InstantPopup)
|
sM.setPopupMode(QToolButton.InstantPopup)
|
||||||
|
|
||||||
self.b.addWidget(self.toolBar)
|
self.b.addWidget(self.toolBar)
|
||||||
self.edit = PythonEdit()
|
self.edit = PythonEdit(self)
|
||||||
self.textEditOut = EditorOutput()
|
self.textEditOut = EditorOutput(self)
|
||||||
|
|
||||||
self.setFocusProxy(self.edit)
|
self.setFocusProxy(self.edit)
|
||||||
|
|
||||||
@ -362,10 +366,6 @@ class PythonConsoleWidget(QWidget):
|
|||||||
self.edit.refreshLexerProperties()
|
self.edit.refreshLexerProperties()
|
||||||
self.textEditOut.refreshLexerProperties()
|
self.textEditOut.refreshLexerProperties()
|
||||||
|
|
||||||
def closeEvent(self, event):
|
|
||||||
self.edit.writeHistoryFile()
|
|
||||||
QWidget.closeEvent(self, event)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
a = QApplication(sys.argv)
|
a = QApplication(sys.argv)
|
||||||
console = PythonConsoleWidget()
|
console = PythonConsoleWidget()
|
||||||
|
|||||||
@ -24,7 +24,7 @@ from PyQt4.QtGui import *
|
|||||||
from PyQt4.Qsci import (QsciScintilla,
|
from PyQt4.Qsci import (QsciScintilla,
|
||||||
QsciScintillaBase,
|
QsciScintillaBase,
|
||||||
QsciLexerPython)
|
QsciLexerPython)
|
||||||
from console_sci import PythonEdit
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
class writeOut:
|
class writeOut:
|
||||||
@ -32,17 +32,17 @@ class writeOut:
|
|||||||
"""
|
"""
|
||||||
This class allow to write stdout and stderr
|
This class allow to write stdout and stderr
|
||||||
"""
|
"""
|
||||||
self.editor = edit
|
self.outputArea = edit
|
||||||
self.out = None
|
self.out = None
|
||||||
self.style = style
|
self.style = style
|
||||||
|
|
||||||
def write(self, m):
|
def write(self, m):
|
||||||
if self.style == "traceback":
|
if self.style == "traceback":
|
||||||
self.editor.SendScintilla(QsciScintilla.SCI_SETSTYLING, len(m), 1)
|
self.outputArea.SendScintilla(QsciScintilla.SCI_SETSTYLING, len(m), 1)
|
||||||
self.editor.append(m)
|
self.outputArea.append(m)
|
||||||
self.editor.SendScintilla(QsciScintilla.SCI_SETSTYLING, len(m), 1)
|
self.outputArea.SendScintilla(QsciScintilla.SCI_SETSTYLING, len(m), 1)
|
||||||
else:
|
else:
|
||||||
self.editor.append(m)
|
self.outputArea.append(m)
|
||||||
self.move_cursor_to_end()
|
self.move_cursor_to_end()
|
||||||
|
|
||||||
if self.out:
|
if self.out:
|
||||||
@ -51,14 +51,14 @@ class writeOut:
|
|||||||
def move_cursor_to_end(self):
|
def move_cursor_to_end(self):
|
||||||
"""Move cursor to end of text"""
|
"""Move cursor to end of text"""
|
||||||
line, index = self.get_end_pos()
|
line, index = self.get_end_pos()
|
||||||
self.editor.setCursorPosition(line, index)
|
self.outputArea.setCursorPosition(line, index)
|
||||||
self.editor.ensureCursorVisible()
|
self.outputArea.ensureCursorVisible()
|
||||||
self.editor.ensureLineVisible(line)
|
self.outputArea.ensureLineVisible(line)
|
||||||
|
|
||||||
def get_end_pos(self):
|
def get_end_pos(self):
|
||||||
"""Return (line, index) position of the last character"""
|
"""Return (line, index) position of the last character"""
|
||||||
line = self.editor.lines() - 1
|
line = self.outputArea.lines() - 1
|
||||||
return (line, self.editor.text(line).length())
|
return (line, self.outputArea.text(line).length())
|
||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
pass
|
pass
|
||||||
@ -67,13 +67,15 @@ class EditorOutput(QsciScintilla):
|
|||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
#QsciScintilla.__init__(self, parent)
|
#QsciScintilla.__init__(self, parent)
|
||||||
super(EditorOutput,self).__init__(parent)
|
super(EditorOutput,self).__init__(parent)
|
||||||
|
self.parent = parent
|
||||||
|
self.edit = self.parent.edit
|
||||||
|
|
||||||
# Enable non-ascii chars for editor
|
# Enable non-ascii chars for editor
|
||||||
self.setUtf8(True)
|
self.setUtf8(True)
|
||||||
|
|
||||||
sys.stdout = writeOut(self, sys.stdout)
|
sys.stdout = writeOut(self, sys.stdout)
|
||||||
sys.stderr = writeOut(self, sys.stderr, "traceback")
|
sys.stderr = writeOut(self, sys.stderr, "traceback")
|
||||||
|
|
||||||
self.edit = PythonEdit()
|
|
||||||
self.setLexers()
|
self.setLexers()
|
||||||
self.setReadOnly(True)
|
self.setReadOnly(True)
|
||||||
|
|
||||||
@ -101,7 +103,7 @@ class EditorOutput(QsciScintilla):
|
|||||||
#self.setFoldMarginColors(QColor("#99CC66"),QColor("#333300"))
|
#self.setFoldMarginColors(QColor("#99CC66"),QColor("#333300"))
|
||||||
#self.setWrapMode(QsciScintilla.WrapCharacter)
|
#self.setWrapMode(QsciScintilla.WrapCharacter)
|
||||||
|
|
||||||
## Edge Mode : does not seems to work
|
## Edge Mode
|
||||||
#self.setEdgeMode(QsciScintilla.EdgeLine)
|
#self.setEdgeMode(QsciScintilla.EdgeLine)
|
||||||
#self.setEdgeColumn(80)
|
#self.setEdgeColumn(80)
|
||||||
#self.setEdgeColor(QColor("#FF0000"))
|
#self.setEdgeColor(QColor("#FF0000"))
|
||||||
@ -175,3 +177,14 @@ class EditorOutput(QsciScintilla):
|
|||||||
self.edit.insertFromDropPaste(cmd)
|
self.edit.insertFromDropPaste(cmd)
|
||||||
self.edit.entered()
|
self.edit.entered()
|
||||||
|
|
||||||
|
def keyPressEvent(self, e):
|
||||||
|
# empty text indicates possible shortcut key sequence so stay in output
|
||||||
|
txt = e.text()
|
||||||
|
if txt.length() and txt >= " ":
|
||||||
|
self.edit.append(txt)
|
||||||
|
self.edit.move_cursor_to_end()
|
||||||
|
self.edit.setFocus()
|
||||||
|
e.ignore()
|
||||||
|
else:
|
||||||
|
# possible shortcut key sequence, accept it
|
||||||
|
e.accept()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user