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