From 15de954d6a916081cd45e7c0d7a1282ec6e2b4b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Verret?= Date: Mon, 12 Oct 2020 13:28:44 -0400 Subject: [PATCH] Handle KeyboardInterrupt in Python Console (#6643) Use Ctrl+C to raise a KeyboardInterrupt. This is especially useful to escape constructs. Example: >>> for i in range(0, 3): ... KeyboardInterrupt >>> --- electrum/gui/qt/console.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/electrum/gui/qt/console.py b/electrum/gui/qt/console.py index 1eaaffb7a..248fec9b7 100644 --- a/electrum/gui/qt/console.py +++ b/electrum/gui/qt/console.py @@ -95,6 +95,11 @@ class Console(QtWidgets.QPlainTextEdit): self.setPlainText('') self.newPrompt(curr_line) + def keyboard_interrupt(self): + self.construct = [] + self.appendPlainText('KeyboardInterrupt') + self.newPrompt('') + def newPrompt(self, curr_line): if self.construct: prompt = '... ' + curr_line @@ -286,6 +291,8 @@ class Console(QtWidgets.QPlainTextEdit): return elif event.key() == QtCore.Qt.Key_L and event.modifiers() == QtCore.Qt.ControlModifier: self.clear() + elif event.key() == QtCore.Qt.Key_C and event.modifiers() == QtCore.Qt.ControlModifier: + self.keyboard_interrupt() super(Console, self).keyPressEvent(event)