##// END OF EJS Templates
added shutdown notification handling to ipythonqt
MinRK -
Show More
@@ -3,6 +3,7 b' from __future__ import print_function'
3 # Standard library imports
3 # Standard library imports
4 from collections import namedtuple
4 from collections import namedtuple
5 import sys
5 import sys
6 import time
6
7
7 # System library imports
8 # System library imports
8 from pygments.lexers import PythonLexer
9 from pygments.lexers import PythonLexer
@@ -361,6 +362,19 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):'
361 self._append_plain_text(text)
362 self._append_plain_text(text)
362 self._control.moveCursor(QtGui.QTextCursor.End)
363 self._control.moveCursor(QtGui.QTextCursor.End)
363
364
365 def _handle_shutdown_reply(self, msg):
366 """ Handle shutdown signal, only if from other console.
367 """
368 if not self._hidden and not self._is_from_this_session(msg):
369 if not msg['content']['restart']:
370 sys.exit(0)
371 else:
372 # we just got notified of a restart!
373 time.sleep(0.25) # wait 1/4 sec to reest
374 # lest the request for a new prompt
375 # goes to the old kernel
376 self.reset()
377
364 def _started_channels(self):
378 def _started_channels(self):
365 """ Called when the KernelManager channels have started listening or
379 """ Called when the KernelManager channels have started listening or
366 when the frontend is assigned an already listening KernelManager.
380 when the frontend is assigned an already listening KernelManager.
@@ -31,11 +31,12 b' class MainWindow(QtGui.QMainWindow):'
31 # 'object' interface
31 # 'object' interface
32 #---------------------------------------------------------------------------
32 #---------------------------------------------------------------------------
33
33
34 def __init__(self, frontend):
34 def __init__(self, frontend, existing=False):
35 """ Create a MainWindow for the specified FrontendWidget.
35 """ Create a MainWindow for the specified FrontendWidget.
36 """
36 """
37 super(MainWindow, self).__init__()
37 super(MainWindow, self).__init__()
38 self._frontend = frontend
38 self._frontend = frontend
39 self._existing = existing
39 self._frontend.exit_requested.connect(self.close)
40 self._frontend.exit_requested.connect(self.close)
40 self.setCentralWidget(frontend)
41 self.setCentralWidget(frontend)
41
42
@@ -50,15 +51,19 b' class MainWindow(QtGui.QMainWindow):'
50 if kernel_manager and kernel_manager.channels_running:
51 if kernel_manager and kernel_manager.channels_running:
51 title = self.window().windowTitle()
52 title = self.window().windowTitle()
52 reply = QtGui.QMessageBox.question(self, title,
53 reply = QtGui.QMessageBox.question(self, title,
53 'Closing console. Leave Kernel alive?',
54 "Closing console. Shutdown kernel as well?\n"+
55 "'Yes' will close the kernel and all connected consoles.",
54 QtGui.QMessageBox.Yes, QtGui.QMessageBox.No, QtGui.QMessageBox.Cancel)
56 QtGui.QMessageBox.Yes, QtGui.QMessageBox.No, QtGui.QMessageBox.Cancel)
55 if reply == QtGui.QMessageBox.Yes:
57 if reply == QtGui.QMessageBox.Yes:
56 self.destroy()
57 event.ignore()
58 elif reply == QtGui.QMessageBox.No:
59 kernel_manager.shutdown_kernel()
58 kernel_manager.shutdown_kernel()
60 #kernel_manager.stop_channels()
59 #kernel_manager.stop_channels()
61 event.accept()
60 event.accept()
61 elif reply == QtGui.QMessageBox.No:
62 if self._existing:
63 event.accept()
64 else:
65 self.destroy()
66 event.ignore()
62 else:
67 else:
63 event.ignore()
68 event.ignore()
64
69
@@ -136,7 +141,7 b' def main():'
136 widget.kernel_manager = kernel_manager
141 widget.kernel_manager = kernel_manager
137
142
138 # Create the main window.
143 # Create the main window.
139 window = MainWindow(widget)
144 window = MainWindow(widget, args.existing)
140 window.setWindowTitle('Python' if args.pure else 'IPython')
145 window.setWindowTitle('Python' if args.pure else 'IPython')
141 window.show()
146 window.show()
142
147
@@ -105,6 +105,9 b' class QtSubSocketChannel(SocketChannelQObject, SubSocketChannel):'
105 # last-resort sys.excepthook.
105 # last-resort sys.excepthook.
106 crash_received = QtCore.pyqtSignal(object)
106 crash_received = QtCore.pyqtSignal(object)
107
107
108 # Emitted when a shutdown is noticed.
109 shutdown_reply_received = QtCore.pyqtSignal(object)
110
108 #---------------------------------------------------------------------------
111 #---------------------------------------------------------------------------
109 # 'SubSocketChannel' interface
112 # 'SubSocketChannel' interface
110 #---------------------------------------------------------------------------
113 #---------------------------------------------------------------------------
General Comments 0
You need to be logged in to leave comments. Login now