##// END OF EJS Templates
prevent remote frontends from closing the kernel
MinRK -
Show More
@@ -31,18 +31,24 b' class MainWindow(QtGui.QMainWindow):'
31 31 # 'object' interface
32 32 #---------------------------------------------------------------------------
33 33
34 def __init__(self, app, frontend, existing=False):
34 def __init__(self, app, frontend, existing=False, may_close=True):
35 35 """ Create a MainWindow for the specified FrontendWidget.
36 36
37 37 The app is passed as an argument to allow for different
38 38 closing behavior depending on whether we are the Kernel's parent.
39 39
40 If existing is True, then this Window does not own the Kernel.
40 If existing is True, then this Console does not own the Kernel.
41
42 If may_close is True, then this Console is permitted to close the kernel
41 43 """
42 44 super(MainWindow, self).__init__()
43 45 self._app = app
44 46 self._frontend = frontend
45 47 self._existing = existing
48 if not existing:
49 self._may_close = may_close
50 else:
51 self._may_close = True
46 52 self._frontend.exit_requested.connect(self.close)
47 53 self.setCentralWidget(frontend)
48 54
@@ -56,22 +62,34 b' class MainWindow(QtGui.QMainWindow):'
56 62 kernel_manager = self._frontend.kernel_manager
57 63 if kernel_manager and kernel_manager.channels_running:
58 64 title = self.window().windowTitle()
59 reply = QtGui.QMessageBox.question(self, title,
60 "You are closing this Console window."+
61 "\nWould you like to quit the Kernel and all attached Consoles as well?",
62 'Cancel', 'No, just this Console', 'Yes, quit everything')
63 if reply == 2: # close All
64 kernel_manager.shutdown_kernel()
65 #kernel_manager.stop_channels()
66 event.accept()
67 elif reply == 1: # close Console
68 if not self._existing:
69 # I have the kernel: don't quit, just close the window
70 self._app.setQuitOnLastWindowClosed(False)
71 self.deleteLater()
72 event.accept()
65 if self._may_close:
66 reply = QtGui.QMessageBox.question(self, title,
67 "You are closing this Console window."+
68 "\nWould you like to quit the Kernel and all attached Consoles as well?",
69 'Cancel', 'No, just this Console', 'Yes, quit everything')
70 if reply == 2: # close All
71 kernel_manager.shutdown_kernel()
72 #kernel_manager.stop_channels()
73 event.accept()
74 elif reply == 1: # close Console
75 if not self._existing:
76 # I have the kernel: don't quit, just close the window
77 self._app.setQuitOnLastWindowClosed(False)
78 self.deleteLater()
79 event.accept()
80 else:
81 event.ignore()
73 82 else:
74 event.ignore()
83 reply = QtGui.QMessageBox.question(self, title,
84 "Are you sure you want to close this Console?\n"+
85 "The Kernel and other Consoles will remain active.",
86 QtGui.QMessageBox.Yes, QtGui.QMessageBox.No
87 )
88 if reply == QtGui.QMessageBox.Yes:
89 event.accept()
90 else:
91 event.ignore()
92
75 93
76 94 #-----------------------------------------------------------------------------
77 95 # Main entry point
@@ -125,7 +143,7 b' def main():'
125 143 sub_address=(args.ip, args.sub),
126 144 rep_address=(args.ip, args.rep),
127 145 hb_address=(args.ip, args.hb))
128 if args.ip == LOCALHOST and not args.existing:
146 if not args.existing:
129 147 if args.pure:
130 148 kernel_manager.start_kernel(ipython=False)
131 149 elif args.pylab:
@@ -134,7 +152,7 b' def main():'
134 152 kernel_manager.start_kernel()
135 153 kernel_manager.start_channels()
136 154
137 local_kernel = (args.ip == LOCALHOST)
155 local_kernel = (not args.existing) or args.ip == LOCALHOST
138 156 # Create the widget.
139 157 app = QtGui.QApplication([])
140 158 if args.pure:
@@ -148,7 +166,7 b' def main():'
148 166 widget.kernel_manager = kernel_manager
149 167
150 168 # Create the main window.
151 window = MainWindow(app, widget, args.existing)
169 window = MainWindow(app, widget, args.existing, may_close=local_kernel)
152 170 window.setWindowTitle('Python' if args.pure else 'IPython')
153 171 window.show()
154 172
General Comments 0
You need to be logged in to leave comments. Login now