Show More
@@ -111,6 +111,7 b' class IPythonWidget(FrontendWidget):' | |||||
111 | self._payload_source_page : self._handle_payload_page, |
|
111 | self._payload_source_page : self._handle_payload_page, | |
112 | self._payload_source_loadpy : self._handle_payload_loadpy } |
|
112 | self._payload_source_loadpy : self._handle_payload_loadpy } | |
113 | self._previous_prompt_obj = None |
|
113 | self._previous_prompt_obj = None | |
|
114 | self._keep_kernel_on_exit = None | |||
114 |
|
115 | |||
115 | # Initialize widget styling. |
|
116 | # Initialize widget styling. | |
116 | if self.style_sheet: |
|
117 | if self.style_sheet: | |
@@ -424,6 +425,7 b' class IPythonWidget(FrontendWidget):' | |||||
424 | self._edit(item['filename'], item['line_number']) |
|
425 | self._edit(item['filename'], item['line_number']) | |
425 |
|
426 | |||
426 | def _handle_payload_exit(self, item): |
|
427 | def _handle_payload_exit(self, item): | |
|
428 | self._keep_kernel_on_exit = item['keepkernel'] | |||
427 | self.exit_requested.emit() |
|
429 | self.exit_requested.emit() | |
428 |
|
430 | |||
429 | def _handle_payload_loadpy(self, item): |
|
431 | def _handle_payload_loadpy(self, item): |
@@ -60,50 +60,62 b' class MainWindow(QtGui.QMainWindow):' | |||||
60 | def closeEvent(self, event): |
|
60 | def closeEvent(self, event): | |
61 | """ Reimplemented to prompt the user and close the kernel cleanly. |
|
61 | """ Reimplemented to prompt the user and close the kernel cleanly. | |
62 | """ |
|
62 | """ | |
|
63 | keepkernel = self._frontend._keep_kernel_on_exit | |||
63 | kernel_manager = self._frontend.kernel_manager |
|
64 | kernel_manager = self._frontend.kernel_manager | |
64 | if kernel_manager and kernel_manager.channels_running: |
|
65 | ||
65 | title = self.window().windowTitle() |
|
66 | if keepkernel is None: | |
66 | cancel = QtGui.QMessageBox.Cancel |
|
67 | if kernel_manager and kernel_manager.channels_running: | |
67 | okay = QtGui.QMessageBox.Ok |
|
68 | title = self.window().windowTitle() | |
68 | if self._may_close: |
|
69 | cancel = QtGui.QMessageBox.Cancel | |
69 | msg = "You are closing this Console window." |
|
70 | okay = QtGui.QMessageBox.Ok | |
70 | info = "Would you like to quit the Kernel and all attached Consoles as well?" |
|
71 | if self._may_close: | |
71 | justthis = QtGui.QPushButton("&No, just this Console", self) |
|
72 | msg = "You are closing this Console window." | |
72 | justthis.setShortcut('N') |
|
73 | info = "Would you like to quit the Kernel and all attached Consoles as well?" | |
73 |
|
|
74 | justthis = QtGui.QPushButton("&No, just this Console", self) | |
74 |
|
|
75 | justthis.setShortcut('N') | |
75 | box = QtGui.QMessageBox(QtGui.QMessageBox.Question, title, msg) |
|
76 | closeall = QtGui.QPushButton("&Yes, quit everything", self) | |
76 |
|
|
77 | closeall.setShortcut('Y') | |
77 | box.addButton(cancel) |
|
78 | box = QtGui.QMessageBox(QtGui.QMessageBox.Question, title, msg) | |
78 | box.addButton(justthis, QtGui.QMessageBox.NoRole) |
|
79 | box.setInformativeText(info) | |
79 |
box.addButton(c |
|
80 | box.addButton(cancel) | |
80 | box.setDefaultButton(closeall) |
|
81 | box.addButton(justthis, QtGui.QMessageBox.NoRole) | |
81 | box.setEscapeButton(cancel) |
|
82 | box.addButton(closeall, QtGui.QMessageBox.YesRole) | |
82 |
|
|
83 | box.setDefaultButton(closeall) | |
83 | if reply == 1: # close All |
|
84 | box.setEscapeButton(cancel) | |
84 | kernel_manager.shutdown_kernel() |
|
85 | reply = box.exec_() | |
85 | #kernel_manager.stop_channels() |
|
86 | if reply == 1: # close All | |
86 |
|
|
87 | kernel_manager.shutdown_kernel() | |
87 | elif reply == 0: # close Console |
|
88 | #kernel_manager.stop_channels() | |
88 |
|
|
89 | event.accept() | |
89 | # I have the kernel: don't quit, just close the window |
|
90 | elif reply == 0: # close Console | |
90 |
self._ |
|
91 | if not self._existing: | |
91 | self.deleteLater() |
|
92 | # Have kernel: don't quit, just close the window | |
92 | event.accept() |
|
93 | self._app.setQuitOnLastWindowClosed(False) | |
93 | else: |
|
94 | self.deleteLater() | |
94 |
event. |
|
95 | event.accept() | |
95 | else: |
|
96 | else: | |
96 | reply = QtGui.QMessageBox.question(self, title, |
|
97 | event.ignore() | |
97 | "Are you sure you want to close this Console?"+ |
|
|||
98 | "\nThe Kernel and other Consoles will remain active.", |
|
|||
99 | okay|cancel, |
|
|||
100 | defaultButton=okay |
|
|||
101 | ) |
|
|||
102 | if reply == okay: |
|
|||
103 | event.accept() |
|
|||
104 | else: |
|
98 | else: | |
105 | event.ignore() |
|
99 | reply = QtGui.QMessageBox.question(self, title, | |
106 |
|
100 | "Are you sure you want to close this Console?"+ | ||
|
101 | "\nThe Kernel and other Consoles will remain active.", | |||
|
102 | okay|cancel, | |||
|
103 | defaultButton=okay | |||
|
104 | ) | |||
|
105 | if reply == okay: | |||
|
106 | event.accept() | |||
|
107 | else: | |||
|
108 | event.ignore() | |||
|
109 | elif keepkernel: #close console but leave kernel running | |||
|
110 | if kernel_manager and kernel_manager.channels_running: | |||
|
111 | if not self._existing: | |||
|
112 | # I have the kernel: don't quit, just close the window | |||
|
113 | self._app.setQuitOnLastWindowClosed(False) | |||
|
114 | event.accept() | |||
|
115 | else: #close console and kernel | |||
|
116 | if kernel_manager and kernel_manager.channels_running: | |||
|
117 | kernel_manager.shutdown_kernel() | |||
|
118 | event.accept() | |||
107 |
|
119 | |||
108 | #----------------------------------------------------------------------------- |
|
120 | #----------------------------------------------------------------------------- | |
109 | # Main entry point |
|
121 | # Main entry point |
@@ -78,6 +78,7 b' class ZMQInteractiveShell(InteractiveShell):' | |||||
78 | """A subclass of InteractiveShell for ZMQ.""" |
|
78 | """A subclass of InteractiveShell for ZMQ.""" | |
79 |
|
79 | |||
80 | displayhook_class = Type(ZMQDisplayHook) |
|
80 | displayhook_class = Type(ZMQDisplayHook) | |
|
81 | keepkernel = None | |||
81 |
|
82 | |||
82 | def init_environment(self): |
|
83 | def init_environment(self): | |
83 | """Configure the user's environment. |
|
84 | """Configure the user's environment. | |
@@ -111,6 +112,7 b' class ZMQInteractiveShell(InteractiveShell):' | |||||
111 | payload = dict( |
|
112 | payload = dict( | |
112 | source='IPython.zmq.zmqshell.ZMQInteractiveShell.ask_exit', |
|
113 | source='IPython.zmq.zmqshell.ZMQInteractiveShell.ask_exit', | |
113 | exit=True, |
|
114 | exit=True, | |
|
115 | keepkernel=self.keepkernel, | |||
114 | ) |
|
116 | ) | |
115 | self.payload_manager.write_payload(payload) |
|
117 | self.payload_manager.write_payload(payload) | |
116 |
|
118 | |||
@@ -563,5 +565,16 b' class ZMQInteractiveShell(InteractiveShell):' | |||||
563 | text=content |
|
565 | text=content | |
564 | ) |
|
566 | ) | |
565 | self.payload_manager.write_payload(payload) |
|
567 | self.payload_manager.write_payload(payload) | |
|
568 | ||||
|
569 | def magic_Exit(self, parameter_s=''): | |||
|
570 | """Exit IPython. If the -k option is provided, the kernel will be left | |||
|
571 | running. Otherwise, it will shutdown without prompting. | |||
|
572 | """ | |||
|
573 | opts,args = self.parse_options(parameter_s,'k') | |||
|
574 | self.shell.keepkernel = opts.has_key('k') | |||
|
575 | self.shell.ask_exit() | |||
|
576 | ||||
|
577 | # Add aliases as magics so all common forms work: exit, quit, Exit, Quit. | |||
|
578 | magic_exit = magic_quit = magic_Quit = magic_Exit | |||
566 |
|
579 | |||
567 | InteractiveShellABC.register(ZMQInteractiveShell) |
|
580 | InteractiveShellABC.register(ZMQInteractiveShell) |
General Comments 0
You need to be logged in to leave comments.
Login now