Ctrl+Home and Ctrl+End now work

This commit is contained in:
Kovid Goyal 2010-09-21 22:46:54 -06:00
parent a41f481ee7
commit fdd839af7c
2 changed files with 17 additions and 8 deletions

View File

@ -9,7 +9,7 @@ import sys, textwrap, traceback, StringIO
from functools import partial from functools import partial
from PyQt4.Qt import QTextEdit, Qt, QTextFrameFormat, pyqtSignal, \ from PyQt4.Qt import QTextEdit, Qt, QTextFrameFormat, pyqtSignal, \
QCoreApplication, QColor, QPalette, QMenu, QActionGroup QApplication, QColor, QPalette, QMenu, QActionGroup
from pygments.lexers import PythonLexer, PythonTracebackLexer from pygments.lexers import PythonLexer, PythonTracebackLexer
from pygments.styles import get_all_styles from pygments.styles import get_all_styles
@ -278,7 +278,7 @@ class Console(QTextEdit):
except: except:
prints(tb, end='') prints(tb, end='')
self.ensureCursorVisible() self.ensureCursorVisible()
QCoreApplication.processEvents() QApplication.processEvents()
def show_output(self, raw): def show_output(self, raw):
def do_show(): def do_show():
@ -296,7 +296,7 @@ class Console(QTextEdit):
else: else:
do_show() do_show()
self.ensureCursorVisible() self.ensureCursorVisible()
QCoreApplication.processEvents() QApplication.processEvents()
# }}} # }}}
@ -360,6 +360,11 @@ class Console(QTextEdit):
def home_pressed(self): def home_pressed(self):
if self.prompt_frame is not None: if self.prompt_frame is not None:
mods = QApplication.keyboardModifiers()
ctrl = bool(int(mods & Qt.CTRL))
if ctrl:
self.cursor_pos = (0, self.prompt_len)
else:
c = self.cursor c = self.cursor
c.movePosition(c.StartOfLine) c.movePosition(c.StartOfLine)
c.movePosition(c.NextCharacter, n=self.prompt_len) c.movePosition(c.NextCharacter, n=self.prompt_len)
@ -368,6 +373,10 @@ class Console(QTextEdit):
def end_pressed(self): def end_pressed(self):
if self.prompt_frame is not None: if self.prompt_frame is not None:
mods = QApplication.keyboardModifiers()
ctrl = bool(int(mods & Qt.CTRL))
if ctrl:
self.cursor_pos = (len(list(self.prompt()))-1, self.prompt_len)
c = self.cursor c = self.cursor
c.movePosition(c.EndOfLine) c.movePosition(c.EndOfLine)
self.setTextCursor(c) self.setTextCursor(c)

View File

@ -52,7 +52,7 @@ class MainWindow(QDialog):
self.setWindowTitle(__appname__ + ' console') self.setWindowTitle(__appname__ + ' console')
self.setWindowIcon(QIcon(I('console.png'))) self.setWindowIcon(QIcon(I('console.png')))
self.restart_action = QAction(_('Restart'), self) self.restart_action = QAction(_('Restart console'), self)
self.restart_action.setShortcut(_('Ctrl+R')) self.restart_action.setShortcut(_('Ctrl+R'))
self.addAction(self.restart_action) self.addAction(self.restart_action)
self.restart_action.triggered.connect(self.restart) self.restart_action.triggered.connect(self.restart)