From 2bea7e95dca02218af87076e62cc07753e323094 2010-10-08 22:13:13 From: MinRK Date: 2010-10-08 22:13:13 Subject: [PATCH] added shutdown notification handling to ipythonqt --- diff --git a/IPython/frontend/qt/console/frontend_widget.py b/IPython/frontend/qt/console/frontend_widget.py index 2afb8e4..fdd9f1d 100644 --- a/IPython/frontend/qt/console/frontend_widget.py +++ b/IPython/frontend/qt/console/frontend_widget.py @@ -3,6 +3,7 @@ from __future__ import print_function # Standard library imports from collections import namedtuple import sys +import time # System library imports from pygments.lexers import PythonLexer @@ -361,6 +362,19 @@ class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin): self._append_plain_text(text) self._control.moveCursor(QtGui.QTextCursor.End) + def _handle_shutdown_reply(self, msg): + """ Handle shutdown signal, only if from other console. + """ + if not self._hidden and not self._is_from_this_session(msg): + if not msg['content']['restart']: + sys.exit(0) + else: + # we just got notified of a restart! + time.sleep(0.25) # wait 1/4 sec to reest + # lest the request for a new prompt + # goes to the old kernel + self.reset() + def _started_channels(self): """ Called when the KernelManager channels have started listening or when the frontend is assigned an already listening KernelManager. diff --git a/IPython/frontend/qt/console/ipythonqt.py b/IPython/frontend/qt/console/ipythonqt.py index 5a7efe2..bccf5a0 100644 --- a/IPython/frontend/qt/console/ipythonqt.py +++ b/IPython/frontend/qt/console/ipythonqt.py @@ -31,11 +31,12 @@ class MainWindow(QtGui.QMainWindow): # 'object' interface #--------------------------------------------------------------------------- - def __init__(self, frontend): + def __init__(self, frontend, existing=False): """ Create a MainWindow for the specified FrontendWidget. """ super(MainWindow, self).__init__() self._frontend = frontend + self._existing = existing self._frontend.exit_requested.connect(self.close) self.setCentralWidget(frontend) @@ -50,15 +51,19 @@ class MainWindow(QtGui.QMainWindow): if kernel_manager and kernel_manager.channels_running: title = self.window().windowTitle() reply = QtGui.QMessageBox.question(self, title, - 'Closing console. Leave Kernel alive?', + "Closing console. Shutdown kernel as well?\n"+ + "'Yes' will close the kernel and all connected consoles.", QtGui.QMessageBox.Yes, QtGui.QMessageBox.No, QtGui.QMessageBox.Cancel) if reply == QtGui.QMessageBox.Yes: - self.destroy() - event.ignore() - elif reply == QtGui.QMessageBox.No: kernel_manager.shutdown_kernel() #kernel_manager.stop_channels() event.accept() + elif reply == QtGui.QMessageBox.No: + if self._existing: + event.accept() + else: + self.destroy() + event.ignore() else: event.ignore() @@ -136,7 +141,7 @@ def main(): widget.kernel_manager = kernel_manager # Create the main window. - window = MainWindow(widget) + window = MainWindow(widget, args.existing) window.setWindowTitle('Python' if args.pure else 'IPython') window.show() diff --git a/IPython/frontend/qt/kernelmanager.py b/IPython/frontend/qt/kernelmanager.py index 09e7fa6..98df284 100644 --- a/IPython/frontend/qt/kernelmanager.py +++ b/IPython/frontend/qt/kernelmanager.py @@ -105,6 +105,9 @@ class QtSubSocketChannel(SocketChannelQObject, SubSocketChannel): # last-resort sys.excepthook. crash_received = QtCore.pyqtSignal(object) + # Emitted when a shutdown is noticed. + shutdown_reply_received = QtCore.pyqtSignal(object) + #--------------------------------------------------------------------------- # 'SubSocketChannel' interface #---------------------------------------------------------------------------